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 * Initialize the screen. If newterm() fails, myscreen will be NULL and
42 * further handlers will assume we should be in line mode.
47 if (arg_screen != RC_NO && rc_screen != RC_NO)
48 myscreen = newterm(NULL, stdout, stdin);
53 intrflush(stdscr, FALSE);
56 #endif /* HAVE_CURSES_H */
65 /* Setup all our colors */
67 init_pair(1+DIM_BLACK, COLOR_BLACK, COLOR_BLACK);
68 init_pair(1+DIM_RED, COLOR_RED, COLOR_BLACK);
69 init_pair(1+DIM_GREEN, COLOR_GREEN, COLOR_BLACK);
70 init_pair(1+DIM_YELLOW, COLOR_YELLOW, COLOR_BLACK);
71 init_pair(1+DIM_BLUE, COLOR_BLUE, COLOR_BLACK);
72 init_pair(1+DIM_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
73 init_pair(1+DIM_CYAN, COLOR_CYAN, COLOR_BLACK);
74 init_pair(1+DIM_WHITE, COLOR_WHITE, COLOR_BLACK);
75 init_pair(17, COLOR_WHITE, COLOR_BLUE);
77 #endif /* HAVE_CURSES_H */
84 * Kill the screen completely (used at exit). It is safe to call this
85 * function more than once.
87 void screen_delete(void)
100 * Set screen/IO parameters, e.g. at start of program or return from external
111 #endif /* HAVE_CURSES_H */
117 * Reset screen/IO parameters, e.g. at exit or fork of external program.
119 int screen_reset(void)
126 #endif /* HAVE_CURSES_H */
132 * scr_printf() outputs to the main window (or screen if not in curses)
134 int scr_printf(char *fmt, ...)
142 retval = _vwprintw(mainwindow, fmt, ap);
144 if (fmt[strlen(fmt) - 1] == '\n')
145 wrefresh(mainwindow);
149 retval = vprintf(fmt, ap);
156 * err_printf() outputs to error status window (or stderr if not in curses)
158 int err_printf(char *fmt, ...)
165 if (mainwindow) { /* FIXME: direct to error window */
166 retval = _vwprintw(mainwindow, fmt, ap);
167 if (fmt[strlen(fmt) - 1] == '\n')
168 wrefresh(mainwindow);
171 retval = vfprintf(stderr, fmt, ap);
178 * sln_printf() outputs to error status window (or stderr if not in curses)
180 int sln_printf(char *fmt, ...)
188 retval = _vwprintw(statuswindow, fmt, ap);
189 if (fmt[strlen(fmt) - 1] == '\n')
190 wrefresh(mainwindow);
193 retval = vprintf(fmt, ap);
203 return wgetch(mainwindow);
210 * scr_putc() outputs a single character
216 return ((waddch(mainwindow, c) == OK) ? c : EOF);
218 return putc(c, stdout);
223 * scr_color() sets the window color for mainwindow
225 int scr_color(int colornum)
229 wcolor_set(mainwindow, 1 + (colornum & 7), NULL);
231 wattron(mainwindow, A_BOLD);
233 wattroff(mainwindow, A_BOLD);
246 wrefresh(mainwindow);
256 if (mainwindow) /* FIXME: error status window needed */
257 wrefresh(mainwindow);
268 wrefresh(statuswindow);
275 int scr_set_windowsize(void)
281 getmaxyx(mainwindow, y, x);
286 #endif /* HAVE_CURSES_H */
292 * scr_winch() handles window size changes from SIGWINCH
293 * resizes all our windows for us
295 RETSIGTYPE scr_winch(void)
298 /* FIXME: not implemented */
305 * Initialize the window(s) we will be using.
307 void windows_new(void)
313 getmaxyx(stdscr, y, x);
314 mainwindow = newwin(y - 1, x, 0, 0);
316 screenheight = y - 1;
317 immedok(mainwindow, FALSE);
318 leaveok(mainwindow, FALSE);
319 scrollok(mainwindow, TRUE);
320 statuswindow = newwin(1, x, y - 1, 0);
321 wbkgdset(statuswindow, COLOR_PAIR(17));
322 werase(statuswindow);
323 immedok(statuswindow, TRUE);
324 leaveok(statuswindow, FALSE);
325 scrollok(statuswindow, FALSE);
326 wrefresh(statuswindow);
328 #else /* HAVE_CURSES_H */
330 #endif /* HAVE_CURSES_H */
335 * Deinitialize the window(s) we were using (at exit).
337 void windows_delete(void)
344 delwin(statuswindow);
346 #else /* HAVE_CURSES_H */
348 #endif /* HAVE_CURSES_H */