2 * Screen output handling
12 #include <sys/types.h>
17 #include <libcitadel.h>
19 #include "citadel_ipc.h"
20 #include "citadel_decls.h"
24 char status_line[1024] = " ";
26 /* the default paginator prompt will be replaced by the server's prompt when we learn it */
27 char *moreprompt = " -- more -- ";
29 extern int screenheight;
30 extern int screenwidth;
31 int lines_printed = 0;
34 extern int rc_ansi_color;
35 extern int rc_prompt_control;
36 extern void check_screen_dims(void);
38 void do_keepalive(void);
41 * Initialize the screen
56 void ctdl_beep(void) {
64 * scr_printf() outputs to the terminal
66 int scr_printf(char *fmt, ...)
68 static char outbuf[4096]; /* static for performance -- not re-entrant -- change if needed */
74 retval = vsnprintf(outbuf, sizeof outbuf, fmt, ap);
78 for (i=0; i<len; ++i) {
86 * Read one character from the terminal
88 int scr_getc(int delay)
95 if (!read (0, &buf, 1))
103 * Issue the paginator prompt (more / hit any key to continue)
105 void hit_any_key(void) {
110 scr_printf("%s\r", moreprompt);
113 for (a=0; a<screenwidth; ++a) {
118 if ( (rc_prompt_control == 1) || ((rc_prompt_control == 3) && (userflags & US_PROMPTCTL)) ) {
119 if (b == 'q' || b == 'Q' || b == 's' || b == 'S') {
122 if (b == 'n' || b == 'N') {
127 if (b==NEXT_KEY) sigcaught = SIGINT;
128 if (b==STOP_KEY) sigcaught = SIGQUIT;
133 * Output one character to the terminal
137 /* handle tabs normally */
141 } while ((cols_printed % 8) != 0);
145 /* Output the character... */
146 if (putc(c, stdout) == EOF) {
154 else if (c == '\r') {
157 else if (isprint(c)) {
159 if ((screenwidth > 0) && (cols_printed > screenwidth)) {
165 /* How many lines output before stopping for the paginator?
166 * Depends on whether we are displaying a status line.
168 int height_offset = ( ((enable_color) && (screenwidth > 0)) ? (3) : (2) ) ;
170 /* Ok, go check it. Stop and display the paginator prompt if necessary. */
171 if ((screenheight > 0) && (lines_printed > (screenheight-height_offset))) {
183 if ((enable_color) && (screenwidth > 0)) {
184 if (strlen(status_line) < screenwidth) {
185 memset(&status_line[strlen(status_line)], 32, screenwidth - strlen(status_line));
187 printf("\033[s\033[1;1H\033[K\033[7m");
188 fwrite(status_line, screenwidth, 1, stdout);
189 printf("\033[27m\033[u");
195 static volatile int caught_sigwinch = 0;
199 * scr_winch() handles window size changes from SIGWINCH
200 * resizes all our windows for us
202 RETSIGTYPE scr_winch(int signum)
204 /* if we receive this signal, we must be running
205 * in a terminal that supports resizing.
210 signal(SIGWINCH, scr_winch);
216 * Display a 3270-style "wait" indicator at the bottom of the screen
218 void scr_wait_indicator(int state) {
219 int sp = (screenwidth - 2);
221 if (screenwidth > 0) {
225 status_line[sp] = ' ';
227 case 1: /* Waiting */
228 status_line[sp] = 'X';
230 case 2: /* Receiving */
231 status_line[sp] = '<';
233 case 3: /* Sending */
234 status_line[sp] = '>';