Removed err_* and sln_* functions; replaced all calls with scr_* functions.
[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         va_list ap;
90         register int retval;
91         va_start(ap, fmt);
92         retval = vprintf(fmt, ap);
93         va_end(ap);
94         return retval;
95 }
96
97
98 /*
99  * Read one character from the terminal
100  */
101 int scr_getc(int delay)
102 {
103         unsigned char buf;
104         buf = '\0';
105         if (!read (0, &buf, 1))
106                 logoff(NULL, 3);
107         return buf;
108 }
109
110 /*
111  * Output one character to the terminal
112  */
113 int scr_putc(int c)
114 {
115         if (putc(c, stdout) == EOF)
116                 logoff(NULL, 3);
117         return c;
118 }
119
120
121 /*
122  * scr_color() sets the window color for mainwindow
123  */
124 int scr_color(int colornum)
125 {
126         return 0;
127 }
128
129
130 void scr_flush(void)
131 {
132         fflush(stdout);
133 }
134
135
136 static volatile int caught_sigwinch = 0;
137
138 /*
139  * this is not supposed to be called from a signal handler.
140  */
141 int scr_set_windowsize(CtdlIPC* ipc)
142 {
143         return 0;
144 }
145
146 /*
147  * scr_winch() handles window size changes from SIGWINCH
148  * resizes all our windows for us
149  */
150 RETSIGTYPE scr_winch(int signum)
151 {
152         /* if we receive this signal, we must be running
153          * in a terminal that supports resizing.
154          */
155         have_xterm = 1;
156         caught_sigwinch = 1;
157         check_screen_dims();
158         signal(SIGWINCH, scr_winch);
159 }