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("Secure ");
56 sln_printf("Not secure ");
57 waddch(statuswindow, ACS_VLINE);
58 waddch(statuswindow, ' ');
59 if (humannode && bbs_city)
60 sln_printf("%s at %s ", humannode, bbs_city);
62 sln_printf("in %s ", room_name);
63 if (newmailcount > -1) {
64 waddch(statuswindow, ACS_VLINE);
65 sln_printf(" %d unread mail", newmailcount);
69 #endif /* HAVE_CURSES_H */
74 * Initialize the screen. If newterm() fails, myscreen will be NULL and
75 * further handlers will assume we should be in line mode.
80 if (arg_screen != RC_NO && rc_screen != RC_NO)
81 myscreen = newterm(NULL, stdout, stdin);
86 intrflush(stdscr, FALSE);
88 /* Setup all our colors */
92 init_pair(1+DIM_BLACK, COLOR_BLACK, COLOR_BLACK);
93 init_pair(1+DIM_RED, COLOR_RED, COLOR_BLACK);
94 init_pair(1+DIM_GREEN, COLOR_GREEN, COLOR_BLACK);
95 init_pair(1+DIM_YELLOW, COLOR_YELLOW, COLOR_BLACK);
96 init_pair(1+DIM_BLUE, COLOR_BLUE, COLOR_BLACK);
97 init_pair(1+DIM_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
98 init_pair(1+DIM_CYAN, COLOR_CYAN, COLOR_BLACK);
99 init_pair(1+DIM_WHITE, COLOR_WHITE, COLOR_BLACK);
100 init_pair(17, COLOR_WHITE, COLOR_BLUE);
102 #endif /* HAVE_CURSES_H */
115 * Kill the screen completely (used at exit). It is safe to call this
116 * function more than once.
118 void screen_delete(void)
131 * Set screen/IO parameters, e.g. at start of program or return from external
142 #endif /* HAVE_CURSES_H */
148 * Reset screen/IO parameters, e.g. at exit or fork of external program.
150 int screen_reset(void)
157 #endif /* HAVE_CURSES_H */
163 * scr_printf() outputs to the main window (or screen if not in curses)
165 int scr_printf(char *fmt, ...)
173 retval = _vwprintw(mainwindow, fmt, ap);
176 retval = vprintf(fmt, ap);
183 * err_printf() outputs to error status window (or stderr if not in curses)
185 int err_printf(char *fmt, ...)
192 if (mainwindow) { /* FIXME: direct to error window */
193 retval = _vwprintw(mainwindow, fmt, ap);
194 if (fmt[strlen(fmt) - 1] == '\n')
195 wrefresh(mainwindow);
198 retval = vfprintf(stderr, fmt, ap);
205 * sln_printf() outputs to error status window (or stderr if not in curses)
207 int sln_printf(char *fmt, ...)
212 static char buf[4096];
220 retval = vsnprintf(buf, 4096, fmt, ap);
221 for (i = buf; *i; i++) {
222 if (*i == '\r' || *i == '\n')
223 wclrtoeol(statuswindow);
225 if (*i == '\r' || *i == '\n') {
226 wrefresh(statuswindow);
227 mvwinch(statuswindow, 0, 0);
232 retval = vprintf(fmt, ap);
239 * sln_printf_if() outputs to status window, no output if not in curses
241 int sln_printf_if(char *fmt, ...)
243 register int retval = 1;
245 static char buf[4096];
252 retval = vsnprintf(buf, 4096, fmt, ap);
253 for (i = buf; *i; i++) {
254 if (*i == '\r' || *i == '\n')
255 wclrtoeol(statuswindow);
257 if (*i == '\r' || *i == '\n') {
258 wrefresh(statuswindow);
259 mvwinch(statuswindow, 0, 0);
273 return wgetch(mainwindow);
280 * scr_putc() outputs a single character
286 return ((waddch(mainwindow, c) == OK) ? c : EOF);
288 return putc(c, stdout);
296 return ((waddch(statuswindow, c) == OK) ? c : EOF);
298 return putc(c, stdout);
302 int sln_putc_if(int c)
306 return ((waddch(statuswindow, c) == OK) ? c : EOF);
313 * scr_color() sets the window color for mainwindow
315 int scr_color(int colornum)
319 wcolor_set(mainwindow, 1 + (colornum & 7), NULL);
321 wattron(mainwindow, A_BOLD);
323 wattroff(mainwindow, A_BOLD);
336 wrefresh(mainwindow);
346 if (mainwindow) /* FIXME: error status window needed */
347 wrefresh(mainwindow);
358 wrefresh(statuswindow);
365 int scr_set_windowsize(void)
371 getmaxyx(mainwindow, y, x);
376 #endif /* HAVE_CURSES_H */
382 * scr_winch() handles window size changes from SIGWINCH
383 * resizes all our windows for us
385 RETSIGTYPE scr_winch(void)
388 /* FIXME: not implemented */
395 * Initialize the window(s) we will be using.
397 void windows_new(void)
403 getmaxyx(stdscr, y, x);
404 mainwindow = newwin(y - 1, x, 0, 0);
406 screenheight = y - 1;
407 immedok(mainwindow, FALSE);
408 leaveok(mainwindow, FALSE);
409 scrollok(mainwindow, TRUE);
410 statuswindow = newwin(1, x, y - 1, 0);
411 wbkgdset(statuswindow, COLOR_PAIR(17));
412 werase(statuswindow);
413 immedok(statuswindow, FALSE);
414 leaveok(statuswindow, FALSE);
415 scrollok(statuswindow, FALSE);
416 wrefresh(statuswindow);
418 #else /* HAVE_CURSES_H */
420 #endif /* HAVE_CURSES_H */
425 * Deinitialize the window(s) we were using (at exit).
427 void windows_delete(void)
434 delwin(statuswindow);
436 #else /* HAVE_CURSES_H */
438 #endif /* HAVE_CURSES_H */