4 * Handle full-screen curses stuff
15 #include <sys/types.h>
17 #define _vwprintw vw_printw
19 /* SYSV style curses (Solaris, etc.) */
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);
103 init_pair(9, COLOR_WHITE, COLOR_BLUE);
105 #endif /* HAVE_CURSES_H */
118 * Kill the screen completely (used at exit). It is safe to call this
119 * function more than once.
121 void screen_delete(void)
134 * Set screen/IO parameters, e.g. at start of program or return from external
145 #endif /* HAVE_CURSES_H */
151 * Reset screen/IO parameters, e.g. at exit or fork of external program.
153 int screen_reset(void)
160 #endif /* HAVE_CURSES_H */
166 * scr_printf() outputs to the main window (or screen if not in curses)
168 int scr_printf(char *fmt, ...)
176 retval = _vwprintw(mainwindow, fmt, ap);
179 retval = vprintf(fmt, ap);
186 * err_printf() outputs to error status window (or stderr if not in curses)
188 int err_printf(char *fmt, ...)
195 if (mainwindow) { /* FIXME: direct to error window */
196 retval = _vwprintw(mainwindow, fmt, ap);
197 if (fmt[strlen(fmt) - 1] == '\n')
198 wrefresh(mainwindow);
201 retval = vfprintf(stderr, fmt, ap);
208 * sln_printf() outputs to error status window (or stderr if not in curses)
210 int sln_printf(char *fmt, ...)
215 static char buf[4096];
223 retval = vsnprintf(buf, 4096, fmt, ap);
224 for (i = buf; *i; i++) {
225 if (*i == '\r' || *i == '\n')
226 wclrtoeol(statuswindow);
228 if (*i == '\r' || *i == '\n') {
229 wrefresh(statuswindow);
230 mvwinch(statuswindow, 0, 0);
235 retval = vprintf(fmt, ap);
242 * sln_printf_if() outputs to status window, no output if not in curses
244 int sln_printf_if(char *fmt, ...)
246 register int retval = 1;
248 static char buf[4096];
255 retval = vsnprintf(buf, 4096, fmt, ap);
256 for (i = buf; *i; i++) {
257 if (*i == '\r' || *i == '\n')
258 wclrtoeol(statuswindow);
260 if (*i == '\r' || *i == '\n') {
261 wrefresh(statuswindow);
262 mvwinch(statuswindow, 0, 0);
277 return wgetch(mainwindow);
284 int scr_blockread(void)
288 wtimeout(mainwindow, S_KEEPALIVE);
292 a = wgetch(mainwindow); /* will block for food */
295 /* a = scr_getc(); */
302 * scr_putc() outputs a single character
308 return ((waddch(mainwindow, c) == OK) ? c : EOF);
310 return putc(c, stdout);
318 return ((waddch(statuswindow, c) == OK) ? c : EOF);
320 return putc(c, stdout);
324 int sln_putc_if(int c)
328 return ((waddch(statuswindow, c) == OK) ? c : EOF);
335 * scr_color() sets the window color for mainwindow
337 int scr_color(int colornum)
341 #ifdef HAVE_WCOLOR_SET
342 wcolor_set(mainwindow, 1 + (colornum & 7), NULL);
344 wattron(mainwindow, COLOR_PAIR(1 + (colornum & 7)));
347 wattron(mainwindow, A_BOLD);
349 wattroff(mainwindow, A_BOLD);
362 wrefresh(mainwindow);
372 if (mainwindow) /* FIXME: error status window needed */
373 wrefresh(mainwindow);
384 wrefresh(statuswindow);
391 int scr_set_windowsize(void)
397 getmaxyx(mainwindow, y, x);
402 #endif /* HAVE_CURSES_H */
408 * scr_winch() handles window size changes from SIGWINCH
409 * resizes all our windows for us
411 RETSIGTYPE scr_winch(void)
414 /* FIXME: not implemented */
421 * Initialize the window(s) we will be using.
423 void windows_new(void)
429 getmaxyx(stdscr, y, x);
430 mainwindow = newwin(y - 1, x, 0, 0);
432 screenheight = y - 1;
433 immedok(mainwindow, FALSE);
434 leaveok(mainwindow, FALSE);
435 scrollok(mainwindow, TRUE);
436 statuswindow = newwin(1, x, y - 1, 0);
439 wbkgdset(statuswindow, COLOR_PAIR(9));
441 werase(statuswindow);
442 immedok(statuswindow, FALSE);
443 leaveok(statuswindow, FALSE);
444 scrollok(statuswindow, FALSE);
445 wrefresh(statuswindow);
447 #else /* HAVE_CURSES_H */
449 #endif /* HAVE_CURSES_H */
454 * Deinitialize the window(s) we were using (at exit).
456 void windows_delete(void)
463 delwin(statuswindow);
465 #else /* HAVE_CURSES_H */
467 #endif /* HAVE_CURSES_H */