4 * Handle full-screen curses stuff
15 #include <sys/types.h>
17 #define _vwprintw vw_printw
19 /* Ancient curses implementations, this needs testing. Anybody got XENIX? */
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);
101 init_pair(17, COLOR_WHITE, COLOR_BLUE);
103 #endif /* HAVE_CURSES_H */
116 * Kill the screen completely (used at exit). It is safe to call this
117 * function more than once.
119 void screen_delete(void)
132 * Set screen/IO parameters, e.g. at start of program or return from external
143 #endif /* HAVE_CURSES_H */
149 * Reset screen/IO parameters, e.g. at exit or fork of external program.
151 int screen_reset(void)
158 #endif /* HAVE_CURSES_H */
164 * scr_printf() outputs to the main window (or screen if not in curses)
166 int scr_printf(char *fmt, ...)
174 retval = _vwprintw(mainwindow, fmt, ap);
177 retval = vprintf(fmt, ap);
184 * err_printf() outputs to error status window (or stderr if not in curses)
186 int err_printf(char *fmt, ...)
193 if (mainwindow) { /* FIXME: direct to error window */
194 retval = _vwprintw(mainwindow, fmt, ap);
195 if (fmt[strlen(fmt) - 1] == '\n')
196 wrefresh(mainwindow);
199 retval = vfprintf(stderr, fmt, ap);
206 * sln_printf() outputs to error status window (or stderr if not in curses)
208 int sln_printf(char *fmt, ...)
213 static char buf[4096];
221 retval = vsnprintf(buf, 4096, fmt, ap);
222 for (i = buf; *i; i++) {
223 if (*i == '\r' || *i == '\n')
224 wclrtoeol(statuswindow);
226 if (*i == '\r' || *i == '\n') {
227 wrefresh(statuswindow);
228 mvwinch(statuswindow, 0, 0);
233 retval = vprintf(fmt, ap);
240 * sln_printf_if() outputs to status window, no output if not in curses
242 int sln_printf_if(char *fmt, ...)
244 register int retval = 1;
246 static char buf[4096];
253 retval = vsnprintf(buf, 4096, fmt, ap);
254 for (i = buf; *i; i++) {
255 if (*i == '\r' || *i == '\n')
256 wclrtoeol(statuswindow);
258 if (*i == '\r' || *i == '\n') {
259 wrefresh(statuswindow);
260 mvwinch(statuswindow, 0, 0);
275 return wgetch(mainwindow);
282 int scr_blockread(void)
286 wtimeout(mainwindow, S_KEEPALIVE);
290 a = wgetch(mainwindow); /* will block for food */
293 /* a = scr_getc(); */
300 * scr_putc() outputs a single character
306 return ((waddch(mainwindow, c) == OK) ? c : EOF);
308 return putc(c, stdout);
316 return ((waddch(statuswindow, c) == OK) ? c : EOF);
318 return putc(c, stdout);
322 int sln_putc_if(int c)
326 return ((waddch(statuswindow, c) == OK) ? c : EOF);
333 * scr_color() sets the window color for mainwindow
335 int scr_color(int colornum)
339 #ifdef HAVE_WCOLOR_SET
340 wcolor_set(mainwindow, 1 + (colornum & 7), NULL);
343 wattron(mainwindow, A_BOLD);
345 wattroff(mainwindow, A_BOLD);
358 wrefresh(mainwindow);
368 if (mainwindow) /* FIXME: error status window needed */
369 wrefresh(mainwindow);
380 wrefresh(statuswindow);
387 int scr_set_windowsize(void)
393 getmaxyx(mainwindow, y, x);
398 #endif /* HAVE_CURSES_H */
404 * scr_winch() handles window size changes from SIGWINCH
405 * resizes all our windows for us
407 RETSIGTYPE scr_winch(void)
410 /* FIXME: not implemented */
417 * Initialize the window(s) we will be using.
419 void windows_new(void)
425 getmaxyx(stdscr, y, x);
426 mainwindow = newwin(y - 1, x, 0, 0);
428 screenheight = y - 1;
429 immedok(mainwindow, FALSE);
430 leaveok(mainwindow, FALSE);
431 scrollok(mainwindow, TRUE);
432 statuswindow = newwin(1, x, y - 1, 0);
433 wbkgdset(statuswindow, COLOR_PAIR(17));
434 werase(statuswindow);
435 immedok(statuswindow, FALSE);
436 leaveok(statuswindow, FALSE);
437 scrollok(statuswindow, FALSE);
438 wrefresh(statuswindow);
440 #else /* HAVE_CURSES_H */
442 #endif /* HAVE_CURSES_H */
447 * Deinitialize the window(s) we were using (at exit).
449 void windows_delete(void)
456 delwin(statuswindow);
458 #else /* HAVE_CURSES_H */
460 #endif /* HAVE_CURSES_H */