2 * Screen output handling
11 #include <sys/types.h>
16 #include <libcitadel.h>
18 #include "citadel_ipc.h"
19 #include "citadel_decls.h"
23 char status_line[1024] = " ";
25 /* the default paginator prompt will be replaced by the server's prompt when we learn it */
26 char *moreprompt = " -- more -- ";
28 extern int screenheight;
29 extern int screenwidth;
30 int lines_printed = 0;
33 extern int rc_ansi_color;
34 extern int rc_prompt_control;
35 extern void check_screen_dims(void);
37 void do_keepalive(void);
40 * Initialize the screen
55 void ctdl_beep(void) {
63 * scr_printf() outputs to the terminal
65 int scr_printf(char *fmt, ...)
67 static char outbuf[4096]; /* static for performance -- not re-entrant -- change if needed */
73 retval = vsnprintf(outbuf, sizeof outbuf, fmt, ap);
77 for (i=0; i<len; ++i) {
85 * Read one character from the terminal
87 int scr_getc(int delay)
94 if (!read (0, &buf, 1))
102 * Issue the paginator prompt (more / hit any key to continue)
104 void hit_any_key(void) {
109 scr_printf("%s\r", moreprompt);
112 for (a=0; a<screenwidth; ++a) {
117 if ( (rc_prompt_control == 1) || ((rc_prompt_control == 3) && (userflags & US_PROMPTCTL)) ) {
118 if (b == 'q' || b == 'Q' || b == 's' || b == 'S') {
121 if (b == 'n' || b == 'N') {
126 if (b==NEXT_KEY) sigcaught = SIGINT;
127 if (b==STOP_KEY) sigcaught = SIGQUIT;
132 * Output one character to the terminal
136 /* handle tabs normally */
140 } while ((cols_printed % 8) != 0);
144 /* Output the character... */
145 if (putc(c, stdout) == EOF) {
153 else if (c == '\r') {
156 else if (isprint(c)) {
158 if ((screenwidth > 0) && (cols_printed > screenwidth)) {
164 /* How many lines output before stopping for the paginator?
165 * Depends on whether we are displaying a status line.
167 int height_offset = ( ((enable_color) && (screenwidth > 0)) ? (3) : (2) ) ;
169 /* Ok, go check it. Stop and display the paginator prompt if necessary. */
170 if ((screenheight > 0) && (lines_printed > (screenheight-height_offset))) {
182 if ((enable_color) && (screenwidth > 0)) {
183 if (strlen(status_line) < screenwidth) {
184 memset(&status_line[strlen(status_line)], 32, screenwidth - strlen(status_line));
186 printf("\033[s\033[1;1H\033[K\033[7m");
187 fwrite(status_line, screenwidth, 1, stdout);
188 printf("\033[27m\033[u");
194 static volatile int caught_sigwinch = 0;
198 * scr_winch() handles window size changes from SIGWINCH
199 * resizes all our windows for us
201 RETSIGTYPE scr_winch(int signum)
203 /* if we receive this signal, we must be running
204 * in a terminal that supports resizing.
209 signal(SIGWINCH, scr_winch);
215 * Display a 3270-style "wait" indicator at the bottom of the screen
217 void scr_wait_indicator(int state) {
218 int sp = (screenwidth - 2);
220 if (screenwidth > 0) {
224 status_line[sp] = ' ';
226 case 1: /* Waiting */
227 status_line[sp] = 'X';
229 case 2: /* Receiving */
230 status_line[sp] = '<';
232 case 3: /* Sending */
233 status_line[sp] = '>';