2 * Screen output handling
4 * Copyright (c) 1987-2011 by the citadel.org team
6 * This program is open source software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include <sys/types.h>
34 #include <libcitadel.h>
36 #include "citadel_ipc.h"
37 #include "citadel_decls.h"
41 int enable_status_line = 0; /* FIXME the status line works, but not on Mac. Make this configurable. */
42 char status_line[1024] = " ";
44 /* the default paginator prompt will be replaced by the server's prompt when we learn it */
45 char *moreprompt = " -- more -- ";
47 extern int screenheight;
48 extern int screenwidth;
49 int lines_printed = 0;
52 extern int rc_ansi_color;
53 extern int rc_prompt_control;
54 extern void check_screen_dims(void);
56 void do_keepalive(void);
59 * Initialize the screen
74 void ctdl_beep(void) {
82 * scr_printf() outputs to the terminal
84 int scr_printf(char *fmt, ...)
86 static char outbuf[4096]; /* static for performance -- not re-entrant -- change if needed */
92 retval = vsnprintf(outbuf, sizeof outbuf, fmt, ap);
96 for (i=0; i<len; ++i) {
104 * Read one character from the terminal
106 int scr_getc(int delay)
113 if (!read (0, &buf, 1))
121 * Issue the paginator prompt (more / hit any key to continue)
123 void hit_any_key(void) {
128 scr_printf("%s\r", moreprompt);
131 for (a=0; a<screenwidth; ++a) {
136 if ( (rc_prompt_control == 1) || ((rc_prompt_control == 3) && (userflags & US_PROMPTCTL)) ) {
137 if (b == 'q' || b == 'Q' || b == 's' || b == 'S') {
140 if (b == 'n' || b == 'N') {
145 if (b==NEXT_KEY) sigcaught = SIGINT;
146 if (b==STOP_KEY) sigcaught = SIGQUIT;
151 * Output one character to the terminal
155 /* handle tabs normally */
159 } while ((cols_printed % 8) != 0);
163 /* Output the character... */
164 if (putc(c, stdout) == EOF) {
172 else if (c == '\r') {
175 else if (isprint(c)) {
177 if ((screenwidth > 0) && (cols_printed > screenwidth)) {
183 /* How many lines output before stopping for the paginator?
184 * Depends on whether we are displaying a status line.
186 int height_offset = ( ((enable_color) && (screenwidth > 0) && (enable_status_line)) ? (3) : (2) ) ;
188 /* Ok, go check it. Stop and display the paginator prompt if necessary. */
189 if ((screenheight > 0) && (lines_printed > (screenheight-height_offset))) {
201 if ((enable_color) && (screenwidth > 0) && (enable_status_line)) {
202 if (strlen(status_line) < screenwidth) {
203 memset(&status_line[strlen(status_line)], 32, screenwidth - strlen(status_line));
205 printf("\033[s\033[1;1H\033[K\033[7m");
206 fwrite(status_line, screenwidth, 1, stdout);
207 printf("\033[27m\033[u");
213 static volatile int caught_sigwinch = 0;
217 * scr_winch() handles window size changes from SIGWINCH
218 * resizes all our windows for us
220 RETSIGTYPE scr_winch(int signum)
222 /* if we receive this signal, we must be running
223 * in a terminal that supports resizing.
228 signal(SIGWINCH, scr_winch);
234 * Display a 3270-style "wait" indicator at the bottom of the screen
236 void scr_wait_indicator(int state) {
237 int sp = (screenwidth - 2);
239 if (!enable_status_line) return;
241 if (screenwidth > 0) {
245 status_line[sp] = ' ';
247 case 1: /* Waiting */
248 status_line[sp] = 'X';
250 case 2: /* Receiving */
251 status_line[sp] = '<';
253 case 3: /* Sending */
254 status_line[sp] = '>';