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
27 static SCREEN *myscreen = NULL;
28 static WINDOW *mainwindow = NULL;
29 static WINDOW *statuswindow = NULL;
34 extern int screenheight;
35 extern int screenwidth;
36 extern void check_screen_dims(void);
41 * status_line() is a convenience function for writing a "typical"
42 * status line to the window.
44 void status_line(const char *humannode, const char *bbs_city,
45 const char *room_name, int secure, int newmailcount)
50 sln_printf("Secure ");
52 sln_printf("Not secure ");
53 waddch(statuswindow, ACS_VLINE);
54 waddch(statuswindow, ' ');
55 if (humannode && bbs_city)
56 sln_printf("%s at %s ", humannode, bbs_city);
58 sln_printf("in %s ", room_name);
59 if (newmailcount > -1) {
60 waddch(statuswindow, ACS_VLINE);
61 sln_printf(" %d unread mail", newmailcount);
63 mvwinch(statuswindow, 0, 0);
65 #endif /* HAVE_CURSES_H */
70 * Initialize the screen. If newterm() fails, myscreen will be NULL and
71 * further handlers will assume we should be in line mode.
76 if (arg_screen != RC_NO && rc_screen != RC_NO)
77 myscreen = newterm(NULL, stdout, stdin);
82 intrflush(stdscr, FALSE);
85 #endif /* HAVE_CURSES_H */
94 /* Setup all our colors */
96 init_pair(1+DIM_BLACK, COLOR_BLACK, COLOR_BLACK);
97 init_pair(1+DIM_RED, COLOR_RED, COLOR_BLACK);
98 init_pair(1+DIM_GREEN, COLOR_GREEN, COLOR_BLACK);
99 init_pair(1+DIM_YELLOW, COLOR_YELLOW, COLOR_BLACK);
100 init_pair(1+DIM_BLUE, COLOR_BLUE, COLOR_BLACK);
101 init_pair(1+DIM_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
102 init_pair(1+DIM_CYAN, COLOR_CYAN, COLOR_BLACK);
103 init_pair(1+DIM_WHITE, COLOR_WHITE, COLOR_BLACK);
104 init_pair(17, COLOR_WHITE, COLOR_BLUE);
106 #endif /* HAVE_CURSES_H */
113 * Kill the screen completely (used at exit). It is safe to call this
114 * function more than once.
116 void screen_delete(void)
129 * Set screen/IO parameters, e.g. at start of program or return from external
140 #endif /* HAVE_CURSES_H */
146 * Reset screen/IO parameters, e.g. at exit or fork of external program.
148 int screen_reset(void)
155 #endif /* HAVE_CURSES_H */
161 * scr_printf() outputs to the main window (or screen if not in curses)
163 int scr_printf(char *fmt, ...)
171 retval = _vwprintw(mainwindow, fmt, ap);
173 if (fmt[strlen(fmt) - 1] == '\n')
174 wrefresh(mainwindow);
178 retval = vprintf(fmt, ap);
185 * err_printf() outputs to error status window (or stderr if not in curses)
187 int err_printf(char *fmt, ...)
194 if (mainwindow) { /* FIXME: direct to error window */
195 retval = _vwprintw(mainwindow, fmt, ap);
196 if (fmt[strlen(fmt) - 1] == '\n')
197 wrefresh(mainwindow);
200 retval = vfprintf(stderr, fmt, ap);
207 * sln_printf() outputs to error status window (or stderr if not in curses)
209 int sln_printf(char *fmt, ...)
217 retval = _vwprintw(statuswindow, fmt, ap);
218 if (fmt[strlen(fmt) - 1] == '\n')
219 wrefresh(mainwindow);
222 retval = vprintf(fmt, ap);
229 * sln_printf_if() outputs to status window, no output if not in curses
231 int sln_printf_if(char *fmt, ...)
233 register int retval = 1;
239 retval = _vwprintw(statuswindow, fmt, ap);
240 if (fmt[strlen(fmt) - 1] == '\r' ||
241 fmt[strlen(fmt) - 1] == '\n') {
242 mvwinch(statuswindow, 0, 0);
243 wrefresh(mainwindow);
256 return wgetch(mainwindow);
263 * scr_putc() outputs a single character
269 return ((waddch(mainwindow, c) == OK) ? c : EOF);
271 return putc(c, stdout);
276 * scr_color() sets the window color for mainwindow
278 int scr_color(int colornum)
282 wcolor_set(mainwindow, 1 + (colornum & 7), NULL);
284 wattron(mainwindow, A_BOLD);
286 wattroff(mainwindow, A_BOLD);
299 wrefresh(mainwindow);
309 if (mainwindow) /* FIXME: error status window needed */
310 wrefresh(mainwindow);
321 wrefresh(statuswindow);
328 int scr_set_windowsize(void)
334 getmaxyx(mainwindow, y, x);
339 #endif /* HAVE_CURSES_H */
345 * scr_winch() handles window size changes from SIGWINCH
346 * resizes all our windows for us
348 RETSIGTYPE scr_winch(void)
351 /* FIXME: not implemented */
358 * Initialize the window(s) we will be using.
360 void windows_new(void)
366 getmaxyx(stdscr, y, x);
367 mainwindow = newwin(y - 1, x, 0, 0);
369 screenheight = y - 1;
370 immedok(mainwindow, FALSE);
371 leaveok(mainwindow, FALSE);
372 scrollok(mainwindow, TRUE);
373 statuswindow = newwin(1, x, y - 1, 0);
374 wbkgdset(statuswindow, COLOR_PAIR(17));
375 werase(statuswindow);
376 immedok(statuswindow, TRUE);
377 leaveok(statuswindow, FALSE);
378 scrollok(statuswindow, FALSE);
379 wrefresh(statuswindow);
381 #else /* HAVE_CURSES_H */
383 #endif /* HAVE_CURSES_H */
388 * Deinitialize the window(s) we were using (at exit).
390 void windows_delete(void)
397 delwin(statuswindow);
399 #else /* HAVE_CURSES_H */
401 #endif /* HAVE_CURSES_H */