2 * Screen output handling
11 #include <sys/types.h>
16 #include <libcitadel.h>
18 #include "citadel_ipc.h"
19 #include "citadel_decls.h"
25 extern int screenheight;
26 extern int screenwidth;
27 int lines_printed = 0;
30 extern int rc_ansi_color;
31 extern int rc_prompt_control;
32 extern void check_screen_dims(void);
34 void do_keepalive(void);
37 * Initialize the screen
52 void ctdl_beep(void) {
60 * scr_printf() outputs to the terminal
62 int scr_printf(char *fmt, ...)
64 static char outbuf[4096]; /* static for performance -- not re-entrant -- change if needed */
70 retval = vsnprintf(outbuf, sizeof outbuf, fmt, ap);
74 for (i=0; i<len; ++i) {
82 * Read one character from the terminal
84 int scr_getc(int delay)
91 if (!read (0, &buf, 1))
99 * Issue the paginator prompt (more / hit any key to continue)
101 void hit_any_key(void) {
106 /* scr_printf("%s\r", ipc->ServInfo.moreprompt); */
107 scr_printf("<<more>>\r"); // FIXME use the prompt given by the server
112 for (a=0; !IsEmptyStr(&ipc->ServInfo.moreprompt[a]); ++a)
119 if ( (rc_prompt_control == 1)
120 || ((rc_prompt_control == 3) && (userflags & US_PROMPTCTL)) ) {
121 if (b == 'q' || b == 'Q' || b == 's' || b == 'S')
123 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 // if we want to do a top status line, this is a reasonable way to do it
166 // printf("\033[s\033[0;70H");
167 // printf("\033[K %d/%d %d/%d", cols_printed, screenwidth, lines_printed, screenheight);
170 if ((screenheight > 0) && (lines_printed > (screenheight-2))) {
187 static volatile int caught_sigwinch = 0;
191 * scr_winch() handles window size changes from SIGWINCH
192 * resizes all our windows for us
194 RETSIGTYPE scr_winch(int signum)
196 /* if we receive this signal, we must be running
197 * in a terminal that supports resizing.
202 signal(SIGWINCH, scr_winch);