3 * $Id: pres_curses.c,v 1.6 1999/07/27 14:04:19 mdw Exp $
5 * Curses-based output presentation
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of sw-tools.
14 * sw-tools is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * sw-tools is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with sw-tools; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 /*----- Revision history --------------------------------------------------*
31 * $Log: pres_curses.c,v $
32 * Revision 1.6 1999/07/27 14:04:19 mdw
33 * (Bug fix) Include the SIGWINCH handler even if `wresize' isn't known.
35 * Revision 1.5 1999/07/27 12:49:16 mdw
36 * Slight tidying of resizing terminal handling.
38 * Revision 1.4 1999/07/16 16:52:28 mdw
39 * `wbkdset' doesn't work so well. Use `wbkgd' instead.
41 * Revision 1.3 1999/07/16 12:49:58 mdw
42 * Improve exit status display. New interface from `doto' project.
44 * Revision 1.2 1999/06/24 15:51:16 mdw
45 * Fix signal handlers so they don't corrupt `errno'.
47 * Revision 1.1.1.1 1999/06/02 16:53:35 mdw
52 /*----- Header files ------------------------------------------------------*/
63 #include <sys/types.h>
66 #if defined(HAVE_NCURSES_H)
68 #elif defined(HAVE_NCURSES_NCURSES_H)
69 # include <ncurses/ncurses.h>
70 #elif defined(HAVE_CURSES_H)
73 # error "Where's your <curses.h> header?"
77 #include <mLib/alloc.h>
78 #include <mLib/report.h>
82 #include "pres_curses.h"
88 /*----- Data structures ---------------------------------------------------*/
99 /*----- Static variables --------------------------------------------------*/
101 static cwin
*cwins
= 0;
102 static int nwins
= 0;
104 /*----- Main code ---------------------------------------------------------*/
112 * Use: Calculates window sizes for all the windows. The heights are
113 * determined in a way which doesn't allow rounding errors to be
114 * an issue (although there will be up to a line's height
115 * difference between two windows). No actual changing of
116 * curses structures is done.
119 static void sizes(void)
122 int t
= 0, h
= LINES
, w
= nwins
;
124 for (c
= cwins
; c
; c
= c
->next
) {
134 /* --- @sig_tstp@ --- */
137 static void sig_tstp(int s
)
146 /* --- @sig_cont@ --- */
149 static void sig_cont(int s
)
157 /* --- @sig_winch@ --- */
161 static void sig_winch(int s
)
171 for (c
= cwins
; c
; c
= c
->next
) {
172 mvwin(c
->w
, c
->top
, 0);
173 wresize(c
->w
, c
->height
, COLS
);
174 mvwin(c
->s
, c
->top
+ c
->height
, 0);
188 /* --- @curses_ok@ --- */
192 if (!isatty(STDOUT_FILENO
)) {
193 moan("can't use curses: stdout isn't a terminal");
196 if (setupterm(0, STDOUT_FILENO
, 0) == ERR
) {
197 moan("can't use curses: couldn't read terminfo");
200 if (!tigetstr("cup")) {
201 moan("can't use curses: terminal insufficiently winning");
207 /* --- @curses_init@ --- */
209 int curses_init(archcons
*a
)
211 cwin
**cc
= &cwins
, *c
;
213 /* --- Allocate my window structures --- */
216 for (; a
; a
= a
->cdr
) {
220 c
= xmalloc(sizeof(cwin
));
230 /* --- Haul curses up by its naughty bits --- */
233 keypad(stdscr
, TRUE
);
239 /* --- Grind through everything setting up windows --- */
242 for (c
= cwins
; c
; c
= c
->next
) {
243 if ((c
->w
= newwin(c
->height
, COLS
, c
->top
, 0)) == 0 ||
244 (c
->s
= newwin(1, COLS
, c
->top
+ c
->height
, 0)) == 0)
246 scrollok(c
->w
, TRUE
);
249 wbkgd(c
->s
, A_STANDOUT
);
250 mvwprintw(c
->s
, 0, 0, " %s [running]\n", c
->e
->arch
);
257 signal(SIGWINCH
, sig_winch
);
260 signal(SIGTSTP
, sig_tstp
);
261 signal(SIGCONT
, sig_cont
);
280 /* --- @curses_output@ --- */
282 void curses_output(archent
*e
, const char *p
, size_t sz
)
293 /* --- @curses_close@ --- */
295 void curses_close(archent
*e
, int ok
, const char *summ
)
298 mvwprintw(c
->s
, 0, 0, " %s [%s]\n", e
->arch
, summ
);
302 /* --- @curses_done@ --- */
304 void curses_done(archcons
*a
)
306 if (opt_flags
& optFlag_beep
) {
312 for (; a
; a
= a
->cdr
) {
322 /* --- @curses_abort@ --- */
324 void curses_abort(archcons
*a
)
327 signal(SIGWINCH
, SIG_DFL
);
330 signal(SIGTSTP
, SIG_DFL
);
331 signal(SIGCONT
, SIG_DFL
);
336 /*----- That's all, folks -------------------------------------------------*/
339 int pres_curses__built
= 1;