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 /*----- Header files ------------------------------------------------------*/
40 #include <sys/types.h>
43 #if defined(HAVE_NCURSES_H)
45 #elif defined(HAVE_NCURSES_NCURSES_H)
46 # include <ncurses/ncurses.h>
47 #elif defined(HAVE_CURSES_H)
50 # error "Where's your <curses.h> header?"
54 #include <mLib/alloc.h>
55 #include <mLib/report.h>
59 #include "pres_curses.h"
65 /*----- Data structures ---------------------------------------------------*/
76 /*----- Static variables --------------------------------------------------*/
78 static cwin
*cwins
= 0;
81 /*----- Main code ---------------------------------------------------------*/
89 * Use: Calculates window sizes for all the windows. The heights are
90 * determined in a way which doesn't allow rounding errors to be
91 * an issue (although there will be up to a line's height
92 * difference between two windows). No actual changing of
93 * curses structures is done.
96 static void sizes(void)
99 int t
= 0, h
= LINES
, w
= nwins
;
101 for (c
= cwins
; c
; c
= c
->next
) {
111 /* --- @sig_tstp@ --- */
114 static void sig_tstp(int s
)
123 /* --- @sig_cont@ --- */
126 static void sig_cont(int s
)
134 /* --- @sig_winch@ --- */
138 static void sig_winch(int s
)
148 for (c
= cwins
; c
; c
= c
->next
) {
149 mvwin(c
->w
, c
->top
, 0);
150 wresize(c
->w
, c
->height
, COLS
);
151 mvwin(c
->s
, c
->top
+ c
->height
, 0);
165 /* --- @curses_ok@ --- */
169 if (!isatty(STDOUT_FILENO
)) {
170 moan("can't use curses: stdout isn't a terminal");
173 if (setupterm(0, STDOUT_FILENO
, 0) == ERR
) {
174 moan("can't use curses: couldn't read terminfo");
177 if (!tigetstr("cup")) {
178 moan("can't use curses: terminal insufficiently winning");
184 /* --- @curses_init@ --- */
186 int curses_init(archcons
*a
)
188 cwin
**cc
= &cwins
, *c
;
190 /* --- Allocate my window structures --- */
193 for (; a
; a
= a
->cdr
) {
197 c
= xmalloc(sizeof(cwin
));
207 /* --- Haul curses up by its naughty bits --- */
210 keypad(stdscr
, TRUE
);
216 /* --- Grind through everything setting up windows --- */
219 for (c
= cwins
; c
; c
= c
->next
) {
220 if ((c
->w
= newwin(c
->height
, COLS
, c
->top
, 0)) == 0 ||
221 (c
->s
= newwin(1, COLS
, c
->top
+ c
->height
, 0)) == 0)
223 scrollok(c
->w
, TRUE
);
226 wbkgd(c
->s
, A_STANDOUT
);
227 mvwprintw(c
->s
, 0, 0, " %s [running]\n", c
->e
->arch
);
234 signal(SIGWINCH
, sig_winch
);
237 signal(SIGTSTP
, sig_tstp
);
238 signal(SIGCONT
, sig_cont
);
257 /* --- @curses_output@ --- */
259 void curses_output(archent
*e
, const char *p
, size_t sz
)
271 if (y
< c
->height
- 1)
287 /* --- @curses_close@ --- */
289 void curses_close(archent
*e
, int ok
, const char *summ
)
292 mvwprintw(c
->s
, 0, 0, " %s [%s]\n", e
->arch
, summ
);
296 /* --- @curses_done@ --- */
298 void curses_done(archcons
*a
)
300 if (opt_flags
& optFlag_beep
) {
306 for (; a
; a
= a
->cdr
) {
316 /* --- @curses_abort@ --- */
318 void curses_abort(archcons
*a
)
321 signal(SIGWINCH
, SIG_DFL
);
324 signal(SIGTSTP
, SIG_DFL
);
325 signal(SIGCONT
, SIG_DFL
);
330 /*----- That's all, folks -------------------------------------------------*/
333 int pres_curses__built
= 1;