4 * Handle full-screen curses stuff
14 #include <sys/types.h>
16 #define _vwprintw vw_printw
18 /* SYSV style curses (Solaris, etc.) */
19 #define _vwprintw vwprintw
25 #include "citadel_ipc.h"
26 #include "citadel_decls.h"
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);
46 int is_curses_enabled(void) {
48 return mainwindow != NULL;
55 * status_line() is a convenience function for writing a "typical"
56 * status line to the window.
58 void status_line(const char *humannode, const char *bbs_city,
59 const char *room_name, int secure, int newmailcount)
64 sln_printf("Encrypted ");
65 waddch(statuswindow, ACS_VLINE);
66 waddch(statuswindow, ' ');
69 sln_printf("%s on ", room_name);
71 sln_printf("%s ", humannode);
72 if (newmailcount > -1) {
73 waddch(statuswindow, ACS_VLINE);
74 sln_printf(" Mail: %d new ", newmailcount);
78 #endif /* HAVE_CURSES_H */
83 * Initialize the screen. If newterm() fails, myscreen will be NULL and
84 * further handlers will assume we should be in line mode.
89 if (arg_screen != RC_NO && rc_screen != RC_NO)
90 myscreen = newterm(NULL, stdout, stdin);
95 intrflush(stdscr, FALSE);
97 /* Setup all our colors */
101 /*init_pair(DIM_BLACK, COLOR_BLACK, COLOR_BLACK);*/
102 init_pair(DIM_RED, COLOR_RED, COLOR_BLACK);
103 init_pair(DIM_GREEN, COLOR_GREEN, COLOR_BLACK);
104 init_pair(DIM_YELLOW, COLOR_YELLOW, COLOR_BLACK);
105 init_pair(DIM_BLUE, COLOR_BLUE, COLOR_BLACK);
106 init_pair(DIM_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
107 init_pair(DIM_CYAN, COLOR_CYAN, COLOR_BLACK);
108 init_pair(DIM_WHITE, COLOR_WHITE, COLOR_BLACK);
111 init_pair(8, COLOR_WHITE, COLOR_BLUE);
113 #endif /* HAVE_CURSES_H */
126 * Kill the screen completely (used at exit). It is safe to call this
127 * function more than once.
129 void screen_delete(void)
142 * Set screen/IO parameters, e.g. at start of program or return from external
153 #endif /* HAVE_CURSES_H */
159 * Reset screen/IO parameters, e.g. at exit or fork of external program.
161 int screen_reset(void)
168 #endif /* HAVE_CURSES_H */
174 * scr_printf() outputs to the main window (or screen if not in curses)
176 int scr_printf(char *fmt, ...)
184 retval = _vwprintw(mainwindow, fmt, ap);
187 retval = vprintf(fmt, ap);
194 * err_printf() outputs to error status window (or stderr if not in curses)
196 int err_printf(char *fmt, ...)
203 if (mainwindow) { /* FIXME: direct to error window */
204 retval = _vwprintw(mainwindow, fmt, ap);
205 if (fmt[strlen(fmt) - 1] == '\n')
206 wrefresh(mainwindow);
209 retval = vfprintf(stderr, fmt, ap);
216 * sln_printf() outputs to error status window (or stderr if not in curses)
218 int sln_printf(char *fmt, ...)
223 static char buf[4096];
231 retval = vsnprintf(buf, 4096, fmt, ap);
232 for (i = buf; *i; i++) {
233 if (*i == '\r' || *i == '\n')
234 wclrtoeol(statuswindow);
236 if (*i == '\r' || *i == '\n') {
237 wrefresh(statuswindow);
238 mvwinch(statuswindow, 0, 0);
243 retval = vprintf(fmt, ap);
250 * sln_printf_if() outputs to status window, no output if not in curses
252 int sln_printf_if(char *fmt, ...)
254 register int retval = 1;
256 static char buf[4096];
263 retval = vsnprintf(buf, 4096, fmt, ap);
264 for (i = buf; *i; i++) {
265 if (*i == '\r' || *i == '\n')
266 wclrtoeol(statuswindow);
268 if (*i == '\r' || *i == '\n') {
269 wrefresh(statuswindow);
270 mvwinch(statuswindow, 0, 0);
280 int scr_getc(int delay)
286 wtimeout(mainwindow, delay);
287 return wgetch(mainwindow);
296 /* the following is unused and looks broken, but there may
297 be some input problems still lurking in curses mode, so
298 i'll leave it blocked out for now for informational
301 int scr_blockread(void)
305 wtimeout(mainwindow, S_KEEPALIVE);
309 a = wgetch(mainwindow); /* will block for food */
312 /* a = scr_getc(); */
320 * scr_putc() outputs a single character
327 return ((waddch(mainwindow, c) == OK) ? c : EOF);
330 return putc(c, stdout);
338 return ((waddch(statuswindow, c) == OK) ? c : EOF);
340 return putc(c, stdout);
344 int sln_putc_if(int c)
348 return ((waddch(statuswindow, c) == OK) ? c : EOF);
355 * scr_color() sets the window color for mainwindow
357 int scr_color(int colornum)
361 #ifdef HAVE_WCOLOR_SET
362 wcolor_set(mainwindow, (colornum & 7), NULL);
364 wattron(mainwindow, COLOR_PAIR((colornum & 7)));
367 wattron(mainwindow, A_BOLD);
369 wattroff(mainwindow, A_BOLD);
382 wrefresh(mainwindow);
392 if (mainwindow) /* FIXME: error status window needed */
393 wrefresh(mainwindow);
404 wrefresh(statuswindow);
410 static volatile int caught_sigwinch = 0;
413 * this is not supposed to be called from a signal handler.
415 int scr_set_windowsize()
418 if (mainwindow && caught_sigwinch) {
420 #ifdef HAVE_RESIZETERM
421 resizeterm(screenheight + 1, screenwidth);
424 wresize(mainwindow, screenheight, screenwidth);
425 wresize(statuswindow, 1, screenwidth);
427 mvwin(statuswindow, screenheight, 0);
428 status_line(serv_info.serv_humannode, serv_info.serv_bbs_city,
429 room_name, secure, -1);
430 wnoutrefresh(mainwindow);
431 wnoutrefresh(statuswindow);
435 #endif /* HAVE_CURSES_H */
440 * scr_winch() handles window size changes from SIGWINCH
441 * resizes all our windows for us
443 RETSIGTYPE scr_winch(int signum)
445 /* if we receive this signal, we must be running
446 in a terminal that supports resizing. */
450 signal(SIGWINCH, scr_winch);
455 * Initialize the window(s) we will be using.
457 void windows_new(void)
463 getmaxyx(stdscr, y, x);
464 mainwindow = newwin(y - 1, x, 0, 0);
466 screenheight = y - 1;
467 immedok(mainwindow, FALSE);
468 leaveok(mainwindow, FALSE);
469 scrollok(mainwindow, TRUE);
470 statuswindow = newwin(1, x, y - 1, 0);
473 wbkgdset(statuswindow, ' ' | COLOR_PAIR(8));
475 wbkgdset(statuswindow, ' ' | COLOR_PAIR(DIM_WHITE));
477 werase(statuswindow);
478 immedok(statuswindow, FALSE);
479 leaveok(statuswindow, FALSE);
480 scrollok(statuswindow, FALSE);
481 wrefresh(statuswindow);
483 #else /* HAVE_CURSES_H */
485 #endif /* HAVE_CURSES_H */
490 * Deinitialize the window(s) we were using (at exit).
492 void windows_delete(void)
499 delwin(statuswindow);
501 #else /* HAVE_CURSES_H */
503 #endif /* HAVE_CURSES_H */