4 * Handle full-screen curses stuff
13 #include <sys/types.h>
15 #define _vwprintw vw_printw
17 /* SYSV style curses (Solaris, etc.) */
18 #define _vwprintw vwprintw
26 #include "citadel_decls.h"
29 static SCREEN *myscreen = NULL;
30 static WINDOW *mainwindow = NULL;
31 static WINDOW *statuswindow = NULL;
36 extern int screenheight;
37 extern int screenwidth;
38 extern int rc_ansi_color;
39 extern void check_screen_dims(void);
42 void do_keepalive(void);
45 int is_curses_enabled(void) {
47 return mainwindow != NULL;
54 * status_line() is a convenience function for writing a "typical"
55 * status line to the window.
57 void status_line(const char *humannode, const char *bbs_city,
58 const char *room_name, int secure, int newmailcount)
63 sln_printf("Encrypted ");
64 waddch(statuswindow, ACS_VLINE);
65 waddch(statuswindow, ' ');
68 sln_printf("%s on ", room_name);
70 sln_printf("%s ", humannode);
71 if (newmailcount > -1) {
72 waddch(statuswindow, ACS_VLINE);
73 sln_printf(" Mail: %d new ", newmailcount);
77 #endif /* HAVE_CURSES_H */
82 * Initialize the screen. If newterm() fails, myscreen will be NULL and
83 * further handlers will assume we should be in line mode.
88 if (arg_screen != RC_NO && rc_screen != RC_NO)
89 myscreen = newterm(NULL, stdout, stdin);
94 intrflush(stdscr, FALSE);
96 /* Setup all our colors */
100 /*init_pair(DIM_BLACK, COLOR_BLACK, COLOR_BLACK);*/
101 init_pair(DIM_RED, COLOR_RED, COLOR_BLACK);
102 init_pair(DIM_GREEN, COLOR_GREEN, COLOR_BLACK);
103 init_pair(DIM_YELLOW, COLOR_YELLOW, COLOR_BLACK);
104 init_pair(DIM_BLUE, COLOR_BLUE, COLOR_BLACK);
105 init_pair(DIM_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
106 init_pair(DIM_CYAN, COLOR_CYAN, COLOR_BLACK);
107 init_pair(DIM_WHITE, COLOR_WHITE, COLOR_BLACK);
110 init_pair(8, COLOR_WHITE, COLOR_BLUE);
112 #endif /* HAVE_CURSES_H */
125 * Kill the screen completely (used at exit). It is safe to call this
126 * function more than once.
128 void screen_delete(void)
141 * Set screen/IO parameters, e.g. at start of program or return from external
152 #endif /* HAVE_CURSES_H */
158 * Reset screen/IO parameters, e.g. at exit or fork of external program.
160 int screen_reset(void)
167 #endif /* HAVE_CURSES_H */
173 * scr_printf() outputs to the main window (or screen if not in curses)
175 int scr_printf(char *fmt, ...)
183 retval = _vwprintw(mainwindow, fmt, ap);
186 retval = vprintf(fmt, ap);
193 * err_printf() outputs to error status window (or stderr if not in curses)
195 int err_printf(char *fmt, ...)
202 if (mainwindow) { /* FIXME: direct to error window */
203 retval = _vwprintw(mainwindow, fmt, ap);
204 if (fmt[strlen(fmt) - 1] == '\n')
205 wrefresh(mainwindow);
208 retval = vfprintf(stderr, fmt, ap);
215 * sln_printf() outputs to error status window (or stderr if not in curses)
217 int sln_printf(char *fmt, ...)
222 static char buf[4096];
230 retval = vsnprintf(buf, 4096, fmt, ap);
231 for (i = buf; *i; i++) {
232 if (*i == '\r' || *i == '\n')
233 wclrtoeol(statuswindow);
235 if (*i == '\r' || *i == '\n') {
236 wrefresh(statuswindow);
237 mvwinch(statuswindow, 0, 0);
242 retval = vprintf(fmt, ap);
249 * sln_printf_if() outputs to status window, no output if not in curses
251 int sln_printf_if(char *fmt, ...)
253 register int retval = 1;
255 static char buf[4096];
262 retval = vsnprintf(buf, 4096, fmt, ap);
263 for (i = buf; *i; i++) {
264 if (*i == '\r' || *i == '\n')
265 wclrtoeol(statuswindow);
267 if (*i == '\r' || *i == '\n') {
268 wrefresh(statuswindow);
269 mvwinch(statuswindow, 0, 0);
279 int scr_getc(int delay)
285 wtimeout(mainwindow, delay);
286 return wgetch(mainwindow);
295 /* the following is unused and looks broken, but there may
296 be some input problems still lurking in curses mode, so
297 i'll leave it blocked out for now for informational
300 int scr_blockread(void)
304 wtimeout(mainwindow, S_KEEPALIVE);
308 a = wgetch(mainwindow); /* will block for food */
311 /* a = scr_getc(); */
319 * scr_putc() outputs a single character
326 return ((waddch(mainwindow, c) == OK) ? c : EOF);
329 return putc(c, stdout);
337 return ((waddch(statuswindow, c) == OK) ? c : EOF);
339 return putc(c, stdout);
343 int sln_putc_if(int c)
347 return ((waddch(statuswindow, c) == OK) ? c : EOF);
354 * scr_color() sets the window color for mainwindow
356 int scr_color(int colornum)
360 #ifdef HAVE_WCOLOR_SET
361 wcolor_set(mainwindow, (colornum & 7), NULL);
363 wattron(mainwindow, COLOR_PAIR((colornum & 7)));
366 wattron(mainwindow, A_BOLD);
368 wattroff(mainwindow, A_BOLD);
381 wrefresh(mainwindow);
391 if (mainwindow) /* FIXME: error status window needed */
392 wrefresh(mainwindow);
403 wrefresh(statuswindow);
409 static volatile int caught_sigwinch = 0;
412 * this is not supposed to be called from a signal handler.
414 int scr_set_windowsize()
417 if (mainwindow && caught_sigwinch) {
419 resizeterm(screenheight + 1, screenwidth);
420 wresize(mainwindow, screenheight, screenwidth);
421 wresize(statuswindow, 1, screenwidth);
422 mvwin(statuswindow, screenheight, 0);
423 status_line(serv_info.serv_humannode, serv_info.serv_bbs_city,
424 room_name, secure, -1);
425 wnoutrefresh(mainwindow);
426 wnoutrefresh(statuswindow);
430 #endif /* HAVE_CURSES_H */
435 * scr_winch() handles window size changes from SIGWINCH
436 * resizes all our windows for us
438 RETSIGTYPE scr_winch(int signum)
440 /* if we receive this signal, we must be running
441 in a terminal that supports resizing. */
445 signal(SIGWINCH, scr_winch);
450 * Initialize the window(s) we will be using.
452 void windows_new(void)
458 getmaxyx(stdscr, y, x);
459 mainwindow = newwin(y - 1, x, 0, 0);
461 screenheight = y - 1;
462 immedok(mainwindow, FALSE);
463 leaveok(mainwindow, FALSE);
464 scrollok(mainwindow, TRUE);
465 statuswindow = newwin(1, x, y - 1, 0);
468 wbkgdset(statuswindow, ' ' | COLOR_PAIR(8));
470 wbkgdset(statuswindow, ' ' | COLOR_PAIR(DIM_WHITE));
472 werase(statuswindow);
473 immedok(statuswindow, FALSE);
474 leaveok(statuswindow, FALSE);
475 scrollok(statuswindow, FALSE);
476 wrefresh(statuswindow);
478 #else /* HAVE_CURSES_H */
480 #endif /* HAVE_CURSES_H */
485 * Deinitialize the window(s) we were using (at exit).
487 void windows_delete(void)
494 delwin(statuswindow);
496 #else /* HAVE_CURSES_H */
498 #endif /* HAVE_CURSES_H */