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);
280 int scr_blockread(void)
284 wtimeout(mainwindow, S_KEEPALIVE);
288 a = wgetch(mainwindow); /* will block for food */
291 /* a = scr_getc(); */
298 * scr_putc() outputs a single character
304 return ((waddch(mainwindow, c) == OK) ? c : EOF);
306 return putc(c, stdout);
314 return ((waddch(statuswindow, c) == OK) ? c : EOF);
316 return putc(c, stdout);
320 int sln_putc_if(int c)
324 return ((waddch(statuswindow, c) == OK) ? c : EOF);
331 * scr_color() sets the window color for mainwindow
333 int scr_color(int colornum)
337 wcolor_set(mainwindow, 1 + (colornum & 7), NULL);
339 wattron(mainwindow, A_BOLD);
341 wattroff(mainwindow, A_BOLD);
354 wrefresh(mainwindow);
364 if (mainwindow) /* FIXME: error status window needed */
365 wrefresh(mainwindow);
376 wrefresh(statuswindow);
383 int scr_set_windowsize(void)
389 getmaxyx(mainwindow, y, x);
394 #endif /* HAVE_CURSES_H */
400 * scr_winch() handles window size changes from SIGWINCH
401 * resizes all our windows for us
403 RETSIGTYPE scr_winch(void)
406 /* FIXME: not implemented */
413 * Initialize the window(s) we will be using.
415 void windows_new(void)
421 getmaxyx(stdscr, y, x);
422 mainwindow = newwin(y - 1, x, 0, 0);
424 screenheight = y - 1;
425 immedok(mainwindow, FALSE);
426 leaveok(mainwindow, FALSE);
427 scrollok(mainwindow, TRUE);
428 statuswindow = newwin(1, x, y - 1, 0);
429 wbkgdset(statuswindow, COLOR_PAIR(17));
430 werase(statuswindow);
431 immedok(statuswindow, FALSE);
432 leaveok(statuswindow, FALSE);
433 scrollok(statuswindow, FALSE);
434 wrefresh(statuswindow);
436 #else /* HAVE_CURSES_H */
438 #endif /* HAVE_CURSES_H */
443 * Deinitialize the window(s) we were using (at exit).
445 void windows_delete(void)
452 delwin(statuswindow);
454 #else /* HAVE_CURSES_H */
456 #endif /* HAVE_CURSES_H */