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 int rc_ansi_color;
37 extern void check_screen_dims(void);
42 * status_line() is a convenience function for writing a "typical"
43 * status line to the window.
45 void status_line(const char *humannode, const char *bbs_city,
46 const char *room_name, int secure, int newmailcount)
51 sln_printf("Secure ");
53 sln_printf("Not secure ");
54 waddch(statuswindow, ACS_VLINE);
55 waddch(statuswindow, ' ');
56 if (humannode && bbs_city)
57 sln_printf("%s at %s ", humannode, bbs_city);
59 sln_printf("in %s ", room_name);
60 if (newmailcount > -1) {
61 waddch(statuswindow, ACS_VLINE);
62 sln_printf(" %d unread mail", newmailcount);
64 mvwinch(statuswindow, 0, 0);
66 #endif /* HAVE_CURSES_H */
71 * Initialize the screen. If newterm() fails, myscreen will be NULL and
72 * further handlers will assume we should be in line mode.
77 if (arg_screen != RC_NO && rc_screen != RC_NO)
78 myscreen = newterm(NULL, stdout, stdin);
83 intrflush(stdscr, FALSE);
85 /* Setup all our colors */
89 init_pair(1+DIM_BLACK, COLOR_BLACK, COLOR_BLACK);
90 init_pair(1+DIM_RED, COLOR_RED, COLOR_BLACK);
91 init_pair(1+DIM_GREEN, COLOR_GREEN, COLOR_BLACK);
92 init_pair(1+DIM_YELLOW, COLOR_YELLOW, COLOR_BLACK);
93 init_pair(1+DIM_BLUE, COLOR_BLUE, COLOR_BLACK);
94 init_pair(1+DIM_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
95 init_pair(1+DIM_CYAN, COLOR_CYAN, COLOR_BLACK);
96 init_pair(1+DIM_WHITE, COLOR_WHITE, COLOR_BLACK);
97 init_pair(17, COLOR_WHITE, COLOR_BLUE);
99 #endif /* HAVE_CURSES_H */
112 * Kill the screen completely (used at exit). It is safe to call this
113 * function more than once.
115 void screen_delete(void)
128 * Set screen/IO parameters, e.g. at start of program or return from external
139 #endif /* HAVE_CURSES_H */
145 * Reset screen/IO parameters, e.g. at exit or fork of external program.
147 int screen_reset(void)
154 #endif /* HAVE_CURSES_H */
160 * scr_printf() outputs to the main window (or screen if not in curses)
162 int scr_printf(char *fmt, ...)
170 retval = _vwprintw(mainwindow, fmt, ap);
172 if (fmt[strlen(fmt) - 1] == '\n')
173 wrefresh(mainwindow);
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, ...)
216 retval = _vwprintw(statuswindow, fmt, ap);
217 if (fmt[strlen(fmt) - 1] == '\n')
218 wrefresh(mainwindow);
221 retval = vprintf(fmt, ap);
228 * sln_printf_if() outputs to status window, no output if not in curses
230 int sln_printf_if(char *fmt, ...)
232 register int retval = 1;
238 retval = _vwprintw(statuswindow, fmt, ap);
239 if (fmt[strlen(fmt) - 1] == '\r' ||
240 fmt[strlen(fmt) - 1] == '\n') {
241 mvwinch(statuswindow, 0, 0);
242 wrefresh(mainwindow);
255 return wgetch(mainwindow);
262 * scr_putc() outputs a single character
268 return ((waddch(mainwindow, c) == OK) ? c : EOF);
270 return putc(c, stdout);
275 * scr_color() sets the window color for mainwindow
277 int scr_color(int colornum)
281 wcolor_set(mainwindow, 1 + (colornum & 7), NULL);
283 wattron(mainwindow, A_BOLD);
285 wattroff(mainwindow, A_BOLD);
298 wrefresh(mainwindow);
308 if (mainwindow) /* FIXME: error status window needed */
309 wrefresh(mainwindow);
320 wrefresh(statuswindow);
327 int scr_set_windowsize(void)
333 getmaxyx(mainwindow, y, x);
338 #endif /* HAVE_CURSES_H */
344 * scr_winch() handles window size changes from SIGWINCH
345 * resizes all our windows for us
347 RETSIGTYPE scr_winch(void)
350 /* FIXME: not implemented */
357 * Initialize the window(s) we will be using.
359 void windows_new(void)
365 getmaxyx(stdscr, y, x);
366 mainwindow = newwin(y - 1, x, 0, 0);
368 screenheight = y - 1;
369 immedok(mainwindow, FALSE);
370 leaveok(mainwindow, FALSE);
371 scrollok(mainwindow, TRUE);
372 statuswindow = newwin(1, x, y - 1, 0);
373 wbkgdset(statuswindow, COLOR_PAIR(17));
374 werase(statuswindow);
375 immedok(statuswindow, TRUE);
376 leaveok(statuswindow, FALSE);
377 scrollok(statuswindow, FALSE);
378 wrefresh(statuswindow);
380 #else /* HAVE_CURSES_H */
382 #endif /* HAVE_CURSES_H */
387 * Deinitialize the window(s) we were using (at exit).
389 void windows_delete(void)
396 delwin(statuswindow);
398 #else /* HAVE_CURSES_H */
400 #endif /* HAVE_CURSES_H */