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
325 return ((waddch(mainwindow, c) == OK) ? c : EOF);
327 return putc(c, stdout);
335 return ((waddch(statuswindow, c) == OK) ? c : EOF);
337 return putc(c, stdout);
341 int sln_putc_if(int c)
345 return ((waddch(statuswindow, c) == OK) ? c : EOF);
352 * scr_color() sets the window color for mainwindow
354 int scr_color(int colornum)
358 #ifdef HAVE_WCOLOR_SET
359 wcolor_set(mainwindow, (colornum & 7), NULL);
361 wattron(mainwindow, COLOR_PAIR((colornum & 7)));
364 wattron(mainwindow, A_BOLD);
366 wattroff(mainwindow, A_BOLD);
379 wrefresh(mainwindow);
389 if (mainwindow) /* FIXME: error status window needed */
390 wrefresh(mainwindow);
401 wrefresh(statuswindow);
407 static volatile int caught_sigwinch = 0;
410 * this is not supposed to be called from a signal handler.
412 int scr_set_windowsize()
415 if (mainwindow && caught_sigwinch) {
417 resizeterm(screenheight + 1, screenwidth);
418 wresize(mainwindow, screenheight, screenwidth);
419 wresize(statuswindow, 1, screenwidth);
420 mvwin(statuswindow, screenheight, 0);
421 status_line(serv_info.serv_humannode, serv_info.serv_bbs_city,
422 room_name, secure, -1);
423 wnoutrefresh(mainwindow);
424 wnoutrefresh(statuswindow);
428 #endif /* HAVE_CURSES_H */
433 * scr_winch() handles window size changes from SIGWINCH
434 * resizes all our windows for us
436 RETSIGTYPE scr_winch(int signum)
438 /* if we receive this signal, we must be running
439 in a terminal that supports resizing. */
443 signal(SIGWINCH, scr_winch);
448 * Initialize the window(s) we will be using.
450 void windows_new(void)
456 getmaxyx(stdscr, y, x);
457 mainwindow = newwin(y - 1, x, 0, 0);
459 screenheight = y - 1;
460 immedok(mainwindow, FALSE);
461 leaveok(mainwindow, FALSE);
462 scrollok(mainwindow, TRUE);
463 statuswindow = newwin(1, x, y - 1, 0);
466 wbkgdset(statuswindow, ' ' | COLOR_PAIR(8));
468 wbkgdset(statuswindow, ' ' | COLOR_PAIR(DIM_WHITE));
470 werase(statuswindow);
471 immedok(statuswindow, FALSE);
472 leaveok(statuswindow, FALSE);
473 scrollok(statuswindow, FALSE);
474 wrefresh(statuswindow);
476 #else /* HAVE_CURSES_H */
478 #endif /* HAVE_CURSES_H */
483 * Deinitialize the window(s) we were using (at exit).
485 void windows_delete(void)
492 delwin(statuswindow);
494 #else /* HAVE_CURSES_H */
496 #endif /* HAVE_CURSES_H */