]> code.citadel.org Git - citadel.git/blob - citadel/textclient/screen.c
All screen output now goes through scr_putc().
[citadel.git] / citadel / textclient / screen.c
1 /*
2  * Screen output handling
3  */
4
5 #include <stdlib.h>
6 #include <unistd.h>
7 #include <stdio.h>
8 #include <signal.h>
9 #include <string.h>
10 #include <stdarg.h>
11 #include <sys/types.h>
12 #include "sysdep.h"
13 #ifndef HAVE_SNPRINTF
14 #include "snprintf.h"
15 #endif
16 #include <libcitadel.h>
17 #include "citadel.h"
18 #include "citadel_ipc.h"
19 #include "citadel_decls.h"
20 #include "commands.h"
21 #include "screen.h"
22
23 char arg_screen;
24
25 extern int screenheight;
26 extern int screenwidth;
27 extern int rc_ansi_color;
28 extern void check_screen_dims(void);
29
30 void do_keepalive(void);
31
32
33 /*
34  * Initialize the screen
35  */
36 void screen_new(void)
37 {
38         send_ansi_detect();
39         look_for_ansi();
40         cls(0);
41         color(DIM_WHITE);
42 }
43
44
45 /*
46  * Kill the screen completely (used at exit).  It is safe to call this
47  * function more than once.
48  */
49 void screen_delete(void)
50 {
51         screen_reset();
52 }
53
54
55
56 /*
57  * Beep.
58  */
59 void ctdl_beep(void) {
60         putc(7, stdout);
61 }
62         
63
64
65 /*
66  * Set screen/IO parameters, e.g. at start of program or return from external
67  * program run.
68  */
69 int screen_set(void)
70 {
71         return 0;
72 }
73
74
75 /*
76  * Reset screen/IO parameters, e.g. at exit or fork of external program.
77  */
78 int screen_reset(void)
79 {
80         return 0;
81 }
82
83
84 /*
85  * scr_printf() outputs to the terminal
86  */
87 int scr_printf(char *fmt, ...)
88 {
89         static char outbuf[4096];       /* static for performance -- not re-entrant -- change if needed */
90         va_list ap;
91         register int retval;
92         int i, len;
93
94         va_start(ap, fmt);
95         retval = vsnprintf(outbuf, sizeof outbuf, fmt, ap);
96         va_end(ap);
97
98         len = strlen(outbuf);
99         for (i=0; i<len; ++i) {
100                 scr_putc(outbuf[i]);
101         }
102         return retval;
103 }
104
105
106 /*
107  * Read one character from the terminal
108  */
109 int scr_getc(int delay)
110 {
111         unsigned char buf;
112
113         scr_flush();
114
115         buf = '\0';
116         if (!read (0, &buf, 1))
117                 logoff(NULL, 3);
118         return buf;
119 }
120
121 /*
122  * Output one character to the terminal
123  */
124 int scr_putc(int c)
125 {
126         if (putc(c, stdout) == EOF) {
127                 logoff(NULL, 3);
128         }
129         return c;
130 }
131
132
133 void scr_flush(void)
134 {
135         fflush(stdout);
136 }
137
138
139 static volatile int caught_sigwinch = 0;
140
141 /*
142  * this is not supposed to be called from a signal handler.
143  */
144 int scr_set_windowsize(CtdlIPC* ipc)
145 {
146         return 0;
147 }
148
149 /*
150  * scr_winch() handles window size changes from SIGWINCH
151  * resizes all our windows for us
152  */
153 RETSIGTYPE scr_winch(int signum)
154 {
155         /* if we receive this signal, we must be running
156          * in a terminal that supports resizing.
157          */
158         have_xterm = 1;
159         caught_sigwinch = 1;
160         check_screen_dims();
161         signal(SIGWINCH, scr_winch);
162 }