4 * Handle full-screen curses stuff
15 #include <sys/types.h>
16 #ifdef VW_PRINTW_IN_CURSES
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);
45 * status_line() is a convenience function for writing a "typical"
46 * status line to the window.
48 void status_line(const char *humannode, const char *bbs_city,
49 const char *room_name, int secure, int newmailcount)
54 sln_printf("Encrypted ");
55 waddch(statuswindow, ACS_VLINE);
56 waddch(statuswindow, ' ');
59 sln_printf("%s on ", room_name);
61 sln_printf("%s ", humannode);
62 if (newmailcount > -1) {
63 waddch(statuswindow, ACS_VLINE);
64 sln_printf(" Mail: %d new ", newmailcount);
68 #endif /* HAVE_CURSES_H */
73 * Initialize the screen. If newterm() fails, myscreen will be NULL and
74 * further handlers will assume we should be in line mode.
79 if (arg_screen != RC_NO && rc_screen != RC_NO)
80 myscreen = newterm(NULL, stdout, stdin);
85 intrflush(stdscr, FALSE);
87 /* Setup all our colors */
91 init_pair(1+DIM_BLACK, COLOR_BLACK, COLOR_BLACK);
92 init_pair(1+DIM_RED, COLOR_RED, COLOR_BLACK);
93 init_pair(1+DIM_GREEN, COLOR_GREEN, COLOR_BLACK);
94 init_pair(1+DIM_YELLOW, COLOR_YELLOW, COLOR_BLACK);
95 init_pair(1+DIM_BLUE, COLOR_BLUE, COLOR_BLACK);
96 init_pair(1+DIM_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
97 init_pair(1+DIM_CYAN, COLOR_CYAN, COLOR_BLACK);
98 init_pair(1+DIM_WHITE, COLOR_WHITE, COLOR_BLACK);
99 init_pair(17, COLOR_WHITE, COLOR_BLUE);
101 #endif /* HAVE_CURSES_H */
114 * Kill the screen completely (used at exit). It is safe to call this
115 * function more than once.
117 void screen_delete(void)
130 * Set screen/IO parameters, e.g. at start of program or return from external
141 #endif /* HAVE_CURSES_H */
147 * Reset screen/IO parameters, e.g. at exit or fork of external program.
149 int screen_reset(void)
156 #endif /* HAVE_CURSES_H */
162 * scr_printf() outputs to the main window (or screen if not in curses)
164 int scr_printf(char *fmt, ...)
172 retval = _vwprintw(mainwindow, fmt, ap);
175 retval = vprintf(fmt, ap);
182 * err_printf() outputs to error status window (or stderr if not in curses)
184 int err_printf(char *fmt, ...)
191 if (mainwindow) { /* FIXME: direct to error window */
192 retval = _vwprintw(mainwindow, fmt, ap);
193 if (fmt[strlen(fmt) - 1] == '\n')
194 wrefresh(mainwindow);
197 retval = vfprintf(stderr, fmt, ap);
204 * sln_printf() outputs to error status window (or stderr if not in curses)
206 int sln_printf(char *fmt, ...)
211 static char buf[4096];
219 retval = vsnprintf(buf, 4096, fmt, ap);
220 for (i = buf; *i; i++) {
221 if (*i == '\r' || *i == '\n')
222 wclrtoeol(statuswindow);
224 if (*i == '\r' || *i == '\n') {
225 wrefresh(statuswindow);
226 mvwinch(statuswindow, 0, 0);
231 retval = vprintf(fmt, ap);
238 * sln_printf_if() outputs to status window, no output if not in curses
240 int sln_printf_if(char *fmt, ...)
242 register int retval = 1;
244 static char buf[4096];
251 retval = vsnprintf(buf, 4096, fmt, ap);
252 for (i = buf; *i; i++) {
253 if (*i == '\r' || *i == '\n')
254 wclrtoeol(statuswindow);
256 if (*i == '\r' || *i == '\n') {
257 wrefresh(statuswindow);
258 mvwinch(statuswindow, 0, 0);
272 return wgetch(mainwindow);
279 * scr_putc() outputs a single character
285 return ((waddch(mainwindow, c) == OK) ? c : EOF);
287 return putc(c, stdout);
295 return ((waddch(statuswindow, c) == OK) ? c : EOF);
297 return putc(c, stdout);
301 int sln_putc_if(int c)
305 return ((waddch(statuswindow, c) == OK) ? c : EOF);
312 * scr_color() sets the window color for mainwindow
314 int scr_color(int colornum)
318 wcolor_set(mainwindow, 1 + (colornum & 7), NULL);
320 wattron(mainwindow, A_BOLD);
322 wattroff(mainwindow, A_BOLD);
335 wrefresh(mainwindow);
345 if (mainwindow) /* FIXME: error status window needed */
346 wrefresh(mainwindow);
357 wrefresh(statuswindow);
364 int scr_set_windowsize(void)
370 getmaxyx(mainwindow, y, x);
375 #endif /* HAVE_CURSES_H */
381 * scr_winch() handles window size changes from SIGWINCH
382 * resizes all our windows for us
384 RETSIGTYPE scr_winch(void)
387 /* FIXME: not implemented */
394 * Initialize the window(s) we will be using.
396 void windows_new(void)
402 getmaxyx(stdscr, y, x);
403 mainwindow = newwin(y - 1, x, 0, 0);
405 screenheight = y - 1;
406 immedok(mainwindow, FALSE);
407 leaveok(mainwindow, FALSE);
408 scrollok(mainwindow, TRUE);
409 statuswindow = newwin(1, x, y - 1, 0);
410 wbkgdset(statuswindow, COLOR_PAIR(17));
411 werase(statuswindow);
412 immedok(statuswindow, FALSE);
413 leaveok(statuswindow, FALSE);
414 scrollok(statuswindow, FALSE);
415 wrefresh(statuswindow);
417 #else /* HAVE_CURSES_H */
419 #endif /* HAVE_CURSES_H */
424 * Deinitialize the window(s) we were using (at exit).
426 void windows_delete(void)
433 delwin(statuswindow);
435 #else /* HAVE_CURSES_H */
437 #endif /* HAVE_CURSES_H */