4 * Handle full-screen curses stuff
15 #include <sys/types.h>
16 #ifdef VW_PRINTW_IN_CURSES
17 #define _vwprintw vw_printw
19 /* Ancient curses implementations, this needs testing. Anybody got XENIX? */
20 #define _vwprintw vwprintw
30 static SCREEN *myscreen = NULL;
31 static WINDOW *mainwindow = NULL;
32 static WINDOW *statuswindow = NULL;
37 extern int screenheight;
38 extern int screenwidth;
39 extern int rc_ansi_color;
40 extern void check_screen_dims(void);
43 void do_keepalive(void);
47 * status_line() is a convenience function for writing a "typical"
48 * status line to the window.
50 void status_line(const char *humannode, const char *bbs_city,
51 const char *room_name, int secure, int newmailcount)
56 sln_printf("Encrypted ");
57 waddch(statuswindow, ACS_VLINE);
58 waddch(statuswindow, ' ');
61 sln_printf("%s on ", room_name);
63 sln_printf("%s ", humannode);
64 if (newmailcount > -1) {
65 waddch(statuswindow, ACS_VLINE);
66 sln_printf(" Mail: %d new ", newmailcount);
70 #endif /* HAVE_CURSES_H */
75 * Initialize the screen. If newterm() fails, myscreen will be NULL and
76 * further handlers will assume we should be in line mode.
81 if (arg_screen != RC_NO && rc_screen != RC_NO)
82 myscreen = newterm(NULL, stdout, stdin);
87 intrflush(stdscr, FALSE);
89 /* Setup all our colors */
93 init_pair(1+DIM_BLACK, COLOR_BLACK, COLOR_BLACK);
94 init_pair(1+DIM_RED, COLOR_RED, COLOR_BLACK);
95 init_pair(1+DIM_GREEN, COLOR_GREEN, COLOR_BLACK);
96 init_pair(1+DIM_YELLOW, COLOR_YELLOW, COLOR_BLACK);
97 init_pair(1+DIM_BLUE, COLOR_BLUE, COLOR_BLACK);
98 init_pair(1+DIM_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
99 init_pair(1+DIM_CYAN, COLOR_CYAN, COLOR_BLACK);
100 init_pair(1+DIM_WHITE, COLOR_WHITE, COLOR_BLACK);
101 init_pair(17, COLOR_WHITE, COLOR_BLUE);
103 #endif /* HAVE_CURSES_H */
116 * Kill the screen completely (used at exit). It is safe to call this
117 * function more than once.
119 void screen_delete(void)
132 * Set screen/IO parameters, e.g. at start of program or return from external
143 #endif /* HAVE_CURSES_H */
149 * Reset screen/IO parameters, e.g. at exit or fork of external program.
151 int screen_reset(void)
158 #endif /* HAVE_CURSES_H */
164 * scr_printf() outputs to the main window (or screen if not in curses)
166 int scr_printf(char *fmt, ...)
174 retval = _vwprintw(mainwindow, fmt, ap);
177 retval = vprintf(fmt, ap);
184 * err_printf() outputs to error status window (or stderr if not in curses)
186 int err_printf(char *fmt, ...)
193 if (mainwindow) { /* FIXME: direct to error window */
194 retval = _vwprintw(mainwindow, fmt, ap);
195 if (fmt[strlen(fmt) - 1] == '\n')
196 wrefresh(mainwindow);
199 retval = vfprintf(stderr, fmt, ap);
206 * sln_printf() outputs to error status window (or stderr if not in curses)
208 int sln_printf(char *fmt, ...)
213 static char buf[4096];
221 retval = vsnprintf(buf, 4096, fmt, ap);
222 for (i = buf; *i; i++) {
223 if (*i == '\r' || *i == '\n')
224 wclrtoeol(statuswindow);
226 if (*i == '\r' || *i == '\n') {
227 wrefresh(statuswindow);
228 mvwinch(statuswindow, 0, 0);
233 retval = vprintf(fmt, ap);
240 * sln_printf_if() outputs to status window, no output if not in curses
242 int sln_printf_if(char *fmt, ...)
244 register int retval = 1;
246 static char buf[4096];
253 retval = vsnprintf(buf, 4096, fmt, ap);
254 for (i = buf; *i; i++) {
255 if (*i == '\r' || *i == '\n')
256 wclrtoeol(statuswindow);
258 if (*i == '\r' || *i == '\n') {
259 wrefresh(statuswindow);
260 mvwinch(statuswindow, 0, 0);
273 /* This looks scary, the program will hang if mainwindow is null */
275 return wgetch(mainwindow);
279 int scr_blockread(void)
282 wtimeout(mainwindow, S_KEEPALIVE);
286 a = wgetch(mainwindow); /* will block for food */
289 /* a = scr_getc(); */
295 * scr_putc() outputs a single character
301 return ((waddch(mainwindow, c) == OK) ? c : EOF);
303 return putc(c, stdout);
311 return ((waddch(statuswindow, c) == OK) ? c : EOF);
313 return putc(c, stdout);
317 int sln_putc_if(int c)
321 return ((waddch(statuswindow, c) == OK) ? c : EOF);
328 * scr_color() sets the window color for mainwindow
330 int scr_color(int colornum)
334 wcolor_set(mainwindow, 1 + (colornum & 7), NULL);
336 wattron(mainwindow, A_BOLD);
338 wattroff(mainwindow, A_BOLD);
351 wrefresh(mainwindow);
361 if (mainwindow) /* FIXME: error status window needed */
362 wrefresh(mainwindow);
373 wrefresh(statuswindow);
380 int scr_set_windowsize(void)
386 getmaxyx(mainwindow, y, x);
391 #endif /* HAVE_CURSES_H */
397 * scr_winch() handles window size changes from SIGWINCH
398 * resizes all our windows for us
400 RETSIGTYPE scr_winch(void)
403 /* FIXME: not implemented */
410 * Initialize the window(s) we will be using.
412 void windows_new(void)
418 getmaxyx(stdscr, y, x);
419 mainwindow = newwin(y - 1, x, 0, 0);
421 screenheight = y - 1;
422 immedok(mainwindow, FALSE);
423 leaveok(mainwindow, FALSE);
424 scrollok(mainwindow, TRUE);
425 statuswindow = newwin(1, x, y - 1, 0);
426 wbkgdset(statuswindow, COLOR_PAIR(17));
427 werase(statuswindow);
428 immedok(statuswindow, FALSE);
429 leaveok(statuswindow, FALSE);
430 scrollok(statuswindow, FALSE);
431 wrefresh(statuswindow);
433 #else /* HAVE_CURSES_H */
435 #endif /* HAVE_CURSES_H */
440 * Deinitialize the window(s) we were using (at exit).
442 void windows_delete(void)
449 delwin(statuswindow);
451 #else /* HAVE_CURSES_H */
453 #endif /* HAVE_CURSES_H */