81f21e5a7c8b8dff365d18a229b27cb513b00e7b
3 * $Id: pres_curses.c,v 1.4 1999/07/16 16:52:28 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.4 1999/07/16 16:52:28 mdw
33 * `wbkdset' doesn't work so well. Use `wbkgd' instead.
35 * Revision 1.3 1999/07/16 12:49:58 mdw
36 * Improve exit status display. New interface from `doto' project.
38 * Revision 1.2 1999/06/24 15:51:16 mdw
39 * Fix signal handlers so they don't corrupt `errno'.
41 * Revision 1.1.1.1 1999/06/02 16:53:35 mdw
46 /*----- Header files ------------------------------------------------------*/
57 #include <sys/types.h>
60 #if defined(HAVE_NCURSES_H)
62 #elif defined(HAVE_NCURSES_NCURSES_H)
63 # include <ncurses/ncurses.h>
64 #elif defined(HAVE_CURSES_H)
67 # error "Where's your <curses.h> header?"
71 #include <mLib/alloc.h>
72 #include <mLib/report.h>
76 #include "pres_curses.h"
82 /*----- Data structures ---------------------------------------------------*/
93 /*----- Static variables --------------------------------------------------*/
95 static cwin
*cwins
= 0;
98 /*----- Main code ---------------------------------------------------------*/
106 * Use: Calculates window sizes for all the windows. The heights are
107 * determined in a way which doesn't allow rounding errors to be
108 * an issue (although there will be up to a line's height
109 * difference between two windows). No actual changing of
110 * curses structures is done.
113 static void sizes(void)
116 int t
= 0, h
= LINES
, w
= nwins
;
118 for (c
= cwins
; c
; c
= c
->next
) {
128 /* --- @sig_tstp@ --- */
131 static void sig_tstp(int s
)
140 /* --- @sig_cont@ --- */
143 static void sig_cont(int s
)
151 /* --- @sig_winch@ --- */
155 static void sig_winch(int s
)
163 for (c
= cwins
; c
; c
= c
->next
) {
164 mvwin(c
->w
, c
->top
, 0);
165 wresize(c
->w
, c
->height
, COLS
);
166 mvwin(c
->s
, c
->top
+ c
->height
, 0);
176 /* --- @curses_ok@ --- */
180 if (!isatty(STDOUT_FILENO
)) {
181 moan("can't use curses: stdout isn't a terminal");
184 if (setupterm(0, STDOUT_FILENO
, 0) == ERR
) {
185 moan("can't use curses: couldn't read terminfo");
188 if (!tigetstr("cup")) {
189 moan("can't use curses: terminal insufficiently winning");
195 /* --- @curses_init@ --- */
197 int curses_init(archcons
*a
)
199 cwin
**cc
= &cwins
, *c
;
201 /* --- Allocate my window structures --- */
204 for (; a
; a
= a
->cdr
) {
208 c
= xmalloc(sizeof(cwin
));
218 /* --- Haul curses up by its naughty bits --- */
221 keypad(stdscr
, TRUE
);
227 /* --- Grind through everything setting up windows --- */
230 for (c
= cwins
; c
; c
= c
->next
) {
231 if ((c
->w
= newwin(c
->height
, COLS
, c
->top
, 0)) == 0 ||
232 (c
->s
= newwin(1, COLS
, c
->top
+ c
->height
, 0)) == 0)
234 scrollok(c
->w
, TRUE
);
237 wbkgd(c
->s
, A_STANDOUT
);
238 mvwprintw(c
->s
, 0, 0, " %s [running]\n", c
->e
->arch
);
245 signal(SIGWINCH
, sig_winch
);
248 signal(SIGTSTP
, sig_tstp
);
249 signal(SIGCONT
, sig_cont
);
268 /* --- @curses_output@ --- */
270 void curses_output(archent
*e
, const char *p
, size_t sz
)
281 /* --- @curses_close@ --- */
283 void curses_close(archent
*e
, int ok
, const char *summ
)
286 mvwprintw(c
->s
, 0, 0, " %s [%s]\n", e
->arch
, summ
);
290 /* --- @curses_done@ --- */
292 void curses_done(archcons
*a
)
294 if (opt_flags
& optFlag_beep
) {
300 for (; a
; a
= a
->cdr
) {
310 /* --- @curses_abort@ --- */
312 void curses_abort(archcons
*a
)
315 signal(SIGWINCH
, SIG_DFL
);
318 signal(SIGTSTP
, SIG_DFL
);
319 signal(SIGCONT
, SIG_DFL
);
324 /*----- That's all, folks -------------------------------------------------*/
327 int pres_curses__built
= 1;