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);
48 int is_curses_enabled(void) {
50 return mainwindow != NULL;
57 * status_line() is a convenience function for writing a "typical"
58 * status line to the window.
60 void status_line(const char *humannode, const char *bbs_city,
61 const char *room_name, int secure, int newmailcount)
66 sln_printf("Encrypted ");
67 waddch(statuswindow, ACS_VLINE);
68 waddch(statuswindow, ' ');
71 sln_printf("%s on ", room_name);
73 sln_printf("%s ", humannode);
74 if (newmailcount > -1) {
75 waddch(statuswindow, ACS_VLINE);
76 sln_printf(" Mail: %d new ", newmailcount);
80 #endif /* HAVE_CURSES_H */
85 * Initialize the screen. If newterm() fails, myscreen will be NULL and
86 * further handlers will assume we should be in line mode.
91 if (arg_screen != RC_NO && rc_screen != RC_NO)
92 myscreen = newterm(NULL, stdout, stdin);
97 intrflush(stdscr, FALSE);
99 /* Setup all our colors */
103 /*init_pair(DIM_BLACK, COLOR_BLACK, COLOR_BLACK);*/
104 init_pair(DIM_RED, COLOR_RED, COLOR_BLACK);
105 init_pair(DIM_GREEN, COLOR_GREEN, COLOR_BLACK);
106 init_pair(DIM_YELLOW, COLOR_YELLOW, COLOR_BLACK);
107 init_pair(DIM_BLUE, COLOR_BLUE, COLOR_BLACK);
108 init_pair(DIM_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
109 init_pair(DIM_CYAN, COLOR_CYAN, COLOR_BLACK);
110 init_pair(DIM_WHITE, COLOR_WHITE, COLOR_BLACK);
113 init_pair(8, COLOR_WHITE, COLOR_BLUE);
115 #endif /* HAVE_CURSES_H */
128 * Kill the screen completely (used at exit). It is safe to call this
129 * function more than once.
131 void screen_delete(void)
144 * Set screen/IO parameters, e.g. at start of program or return from external
155 #endif /* HAVE_CURSES_H */
161 * Reset screen/IO parameters, e.g. at exit or fork of external program.
163 int screen_reset(void)
170 #endif /* HAVE_CURSES_H */
176 * scr_printf() outputs to the main window (or screen if not in curses)
178 int scr_printf(char *fmt, ...)
186 retval = _vwprintw(mainwindow, fmt, ap);
189 retval = vprintf(fmt, ap);
196 * err_printf() outputs to error status window (or stderr if not in curses)
198 int err_printf(char *fmt, ...)
205 if (mainwindow) { /* FIXME: direct to error window */
206 retval = _vwprintw(mainwindow, fmt, ap);
207 if (fmt[strlen(fmt) - 1] == '\n')
208 wrefresh(mainwindow);
211 retval = vfprintf(stderr, fmt, ap);
218 * sln_printf() outputs to error status window (or stderr if not in curses)
220 int sln_printf(char *fmt, ...)
225 static char buf[4096];
233 retval = vsnprintf(buf, 4096, fmt, ap);
234 for (i = buf; *i; i++) {
235 if (*i == '\r' || *i == '\n')
236 wclrtoeol(statuswindow);
238 if (*i == '\r' || *i == '\n') {
239 wrefresh(statuswindow);
240 mvwinch(statuswindow, 0, 0);
245 retval = vprintf(fmt, ap);
252 * sln_printf_if() outputs to status window, no output if not in curses
254 int sln_printf_if(char *fmt, ...)
256 register int retval = 1;
258 static char buf[4096];
265 retval = vsnprintf(buf, 4096, fmt, ap);
266 for (i = buf; *i; i++) {
267 if (*i == '\r' || *i == '\n')
268 wclrtoeol(statuswindow);
270 if (*i == '\r' || *i == '\n') {
271 wrefresh(statuswindow);
272 mvwinch(statuswindow, 0, 0);
287 return wgetch(mainwindow);
294 int scr_blockread(void)
298 wtimeout(mainwindow, S_KEEPALIVE);
302 a = wgetch(mainwindow); /* will block for food */
305 /* a = scr_getc(); */
312 * scr_putc() outputs a single character
318 return ((waddch(mainwindow, c) == OK) ? c : EOF);
320 return putc(c, stdout);
328 return ((waddch(statuswindow, c) == OK) ? c : EOF);
330 return putc(c, stdout);
334 int sln_putc_if(int c)
338 return ((waddch(statuswindow, c) == OK) ? c : EOF);
345 * scr_color() sets the window color for mainwindow
347 int scr_color(int colornum)
351 #ifdef HAVE_WCOLOR_SET
352 wcolor_set(mainwindow, (colornum & 7), NULL);
354 wattron(mainwindow, COLOR_PAIR((colornum & 7)));
357 wattron(mainwindow, A_BOLD);
359 wattroff(mainwindow, A_BOLD);
372 wrefresh(mainwindow);
382 if (mainwindow) /* FIXME: error status window needed */
383 wrefresh(mainwindow);
394 wrefresh(statuswindow);
401 int scr_set_windowsize(void)
407 getmaxyx(mainwindow, y, x);
412 #endif /* HAVE_CURSES_H */
418 * scr_winch() handles window size changes from SIGWINCH
419 * resizes all our windows for us
421 RETSIGTYPE scr_winch(void)
424 /* FIXME: not implemented */
431 * Initialize the window(s) we will be using.
433 void windows_new(void)
439 getmaxyx(stdscr, y, x);
440 mainwindow = newwin(y - 1, x, 0, 0);
442 screenheight = y - 1;
443 immedok(mainwindow, FALSE);
444 leaveok(mainwindow, FALSE);
445 scrollok(mainwindow, TRUE);
446 statuswindow = newwin(1, x, y - 1, 0);
449 wbkgdset(statuswindow, ' ' | COLOR_PAIR(8));
451 wbkgdset(statuswindow, ' ' | COLOR_PAIR(DIM_WHITE));
453 werase(statuswindow);
454 immedok(statuswindow, FALSE);
455 leaveok(statuswindow, FALSE);
456 scrollok(statuswindow, FALSE);
457 wrefresh(statuswindow);
459 #else /* HAVE_CURSES_H */
461 #endif /* HAVE_CURSES_H */
466 * Deinitialize the window(s) we were using (at exit).
468 void windows_delete(void)
475 delwin(statuswindow);
477 #else /* HAVE_CURSES_H */
479 #endif /* HAVE_CURSES_H */