4 * Handle full-screen curses stuff
10 #elif defined(HAVE_CURSES_H)
17 #include <sys/types.h>
19 #define _vwprintw vw_printw
21 /* SYSV style curses (Solaris, etc.) */
22 #define _vwprintw vwprintw
32 static SCREEN *myscreen = NULL;
33 static WINDOW *mainwindow = NULL;
34 static WINDOW *statuswindow = NULL;
39 extern int screenheight;
40 extern int screenwidth;
41 extern int rc_ansi_color;
42 extern void check_screen_dims(void);
45 void do_keepalive(void);
49 * status_line() is a convenience function for writing a "typical"
50 * status line to the window.
52 void status_line(const char *humannode, const char *bbs_city,
53 const char *room_name, int secure, int newmailcount)
58 sln_printf("Encrypted ");
59 waddch(statuswindow, ACS_VLINE);
60 waddch(statuswindow, ' ');
63 sln_printf("%s on ", room_name);
65 sln_printf("%s ", humannode);
66 if (newmailcount > -1) {
67 waddch(statuswindow, ACS_VLINE);
68 sln_printf(" Mail: %d new ", newmailcount);
72 #endif /* HAVE_CURSES_H */
77 * Initialize the screen. If newterm() fails, myscreen will be NULL and
78 * further handlers will assume we should be in line mode.
83 if (arg_screen != RC_NO && rc_screen != RC_NO)
84 myscreen = newterm(NULL, stdout, stdin);
89 intrflush(stdscr, FALSE);
91 /* Setup all our colors */
95 init_pair(DIM_BLACK, COLOR_BLACK, COLOR_BLACK);
96 init_pair(DIM_RED, COLOR_RED, COLOR_BLACK);
97 init_pair(DIM_GREEN, COLOR_GREEN, COLOR_BLACK);
98 init_pair(DIM_YELLOW, COLOR_YELLOW, COLOR_BLACK);
99 init_pair(DIM_BLUE, COLOR_BLUE, COLOR_BLACK);
100 init_pair(DIM_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
101 init_pair(DIM_CYAN, COLOR_CYAN, COLOR_BLACK);
102 init_pair(DIM_WHITE, COLOR_WHITE, COLOR_BLACK);
105 init_pair(8, COLOR_WHITE, COLOR_BLUE);
107 #endif /* HAVE_CURSES_H */
120 * Kill the screen completely (used at exit). It is safe to call this
121 * function more than once.
123 void screen_delete(void)
136 * Set screen/IO parameters, e.g. at start of program or return from external
147 #endif /* HAVE_CURSES_H */
153 * Reset screen/IO parameters, e.g. at exit or fork of external program.
155 int screen_reset(void)
162 #endif /* HAVE_CURSES_H */
168 * scr_printf() outputs to the main window (or screen if not in curses)
170 int scr_printf(char *fmt, ...)
178 retval = _vwprintw(mainwindow, fmt, ap);
181 retval = vprintf(fmt, ap);
188 * err_printf() outputs to error status window (or stderr if not in curses)
190 int err_printf(char *fmt, ...)
197 if (mainwindow) { /* FIXME: direct to error window */
198 retval = _vwprintw(mainwindow, fmt, ap);
199 if (fmt[strlen(fmt) - 1] == '\n')
200 wrefresh(mainwindow);
203 retval = vfprintf(stderr, fmt, ap);
210 * sln_printf() outputs to error status window (or stderr if not in curses)
212 int sln_printf(char *fmt, ...)
217 static char buf[4096];
225 retval = vsnprintf(buf, 4096, fmt, ap);
226 for (i = buf; *i; i++) {
227 if (*i == '\r' || *i == '\n')
228 wclrtoeol(statuswindow);
230 if (*i == '\r' || *i == '\n') {
231 wrefresh(statuswindow);
232 mvwinch(statuswindow, 0, 0);
237 retval = vprintf(fmt, ap);
244 * sln_printf_if() outputs to status window, no output if not in curses
246 int sln_printf_if(char *fmt, ...)
248 register int retval = 1;
250 static char buf[4096];
257 retval = vsnprintf(buf, 4096, fmt, ap);
258 for (i = buf; *i; i++) {
259 if (*i == '\r' || *i == '\n')
260 wclrtoeol(statuswindow);
262 if (*i == '\r' || *i == '\n') {
263 wrefresh(statuswindow);
264 mvwinch(statuswindow, 0, 0);
279 return wgetch(mainwindow);
286 int scr_blockread(void)
290 wtimeout(mainwindow, S_KEEPALIVE);
294 a = wgetch(mainwindow); /* will block for food */
297 /* a = scr_getc(); */
304 * scr_putc() outputs a single character
310 return ((waddch(mainwindow, c) == OK) ? c : EOF);
312 return putc(c, stdout);
320 return ((waddch(statuswindow, c) == OK) ? c : EOF);
322 return putc(c, stdout);
326 int sln_putc_if(int c)
330 return ((waddch(statuswindow, c) == OK) ? c : EOF);
337 * scr_color() sets the window color for mainwindow
339 int scr_color(int colornum)
343 #ifdef HAVE_WCOLOR_SET
344 wcolor_set(mainwindow, (colornum & 7), NULL);
346 wattron(mainwindow, COLOR_PAIR((colornum & 7)));
349 wattron(mainwindow, A_BOLD);
351 wattroff(mainwindow, A_BOLD);
364 wrefresh(mainwindow);
374 if (mainwindow) /* FIXME: error status window needed */
375 wrefresh(mainwindow);
386 wrefresh(statuswindow);
393 int scr_set_windowsize(void)
399 getmaxyx(mainwindow, y, x);
404 #endif /* HAVE_CURSES_H */
410 * scr_winch() handles window size changes from SIGWINCH
411 * resizes all our windows for us
413 RETSIGTYPE scr_winch(void)
416 /* FIXME: not implemented */
423 * Initialize the window(s) we will be using.
425 void windows_new(void)
431 getmaxyx(stdscr, y, x);
432 mainwindow = newwin(y - 1, x, 0, 0);
434 screenheight = y - 1;
435 immedok(mainwindow, FALSE);
436 leaveok(mainwindow, FALSE);
437 scrollok(mainwindow, TRUE);
438 statuswindow = newwin(1, x, y - 1, 0);
441 wbkgdset(statuswindow, ' ' | COLOR_PAIR(8));
443 wbkgdset(statuswindow, ' ' | COLOR_PAIR(DIM_WHITE));
445 werase(statuswindow);
446 immedok(statuswindow, FALSE);
447 leaveok(statuswindow, FALSE);
448 scrollok(statuswindow, FALSE);
449 wrefresh(statuswindow);
451 #else /* HAVE_CURSES_H */
453 #endif /* HAVE_CURSES_H */
458 * Deinitialize the window(s) we were using (at exit).
460 void windows_delete(void)
467 delwin(statuswindow);
469 #else /* HAVE_CURSES_H */
471 #endif /* HAVE_CURSES_H */