Merge remote-tracking branch 'origin/master' into for-steve
[sxemacs] / src / ui / TTY / console-tty.h
1 /* Define TTY specific console, device, and frame object for XEmacs.
2    Copyright (C) 1995 Board of Trustees, University of Illinois.
3    Copyright (C) 1996 Ben Wing.
4    Copyright (C) 2007 Nelson Ferreira
5
6 This file is part of SXEmacs
7
8 SXEmacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 SXEmacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
20
21
22 /* Synched up with: Not in FSF. */
23
24 /* Written by Chuck Thompson, Ben Wing and Nelson Ferreira */
25
26 /* NOTE: Currently each TTY console can have only one device.
27    Therefore, all stuff for both input and output is lumped into
28    the console structure.  If it ever becomes meaningful to
29    have more than one device on a TTY console, the output stuff
30    will have to get separated out. */
31
32 #ifndef INCLUDED_console_tty_h_
33 #define INCLUDED_console_tty_h_
34
35 #include "ui/console.h"
36 #include "syssignal.h"          /* Always include before systty.h */
37 #include "ui/systty.h"
38
39 DECLARE_CONSOLE_TYPE(tty);
40
41 struct tty_console {
42         int infd, outfd;
43         Lisp_Object instream, outstream;
44         Lisp_Object terminal_type;
45         Lisp_Object controlling_process;
46         Lisp_Object term_cmap;
47         Lisp_Object term_crgb;
48
49         char *term_entry_buffer;
50
51         /* Physical location of cursor on this console. */
52         int cursor_x;
53         int cursor_y;
54
55         /* The real location of the cursor.  The above physical location may
56            be ahead of where we really are. */
57         int real_cursor_x;
58         int real_cursor_y;
59
60         int final_cursor_x;
61         int final_cursor_y;
62
63         int height;
64         int width;
65
66         int maxcolors;
67         int maxpairs;
68
69         /* The count of frame number. */
70         int frame_count;
71
72         /* flags indicating presence, absence or value of various features */
73         struct {
74                 /* terminal inserts nulls, not
75                    spaces to fill whitespace on
76                    screen
77                 */
78                 unsigned int must_write_spaces:1;
79
80                 /* cursor movement commands
81                    work while in insert mode
82                 */
83                 unsigned int insert_mode_motion:1;
84
85                 /* cursor movement is graceful
86                    in standout or underline mode */
87                 unsigned int standout_motion:1;
88
89                 /* display retained above screen */
90                 unsigned int memory_above_frame:1;
91
92                 /* display retained below screen */
93                 unsigned int memory_below_frame:1;
94                 unsigned int meta_key:2;        /* 0 == mask off top bit;
95                                                    1 == top bit is meta;
96                                                    2 == top bit is useful as
97                                                    character info */
98                 unsigned int flow_control:1;    /* Nonzero means use ^S/^Q as
99                                                    cretinous flow control.  */
100                 int standout_width;     /* # of spaces printed when
101                                            change to standout mode */
102                 int underline_width;    /* # of spaces printed when
103                                            change to underline mode */
104         } flags;
105
106         /* cursor motion entries - each entry is commented with the terminfo
107            and the termcap entry */
108         struct {
109                 /* local cursor movement */
110                 const char *up; /* cuu1, up */
111                 const char *down;       /* cud1, do */
112                 const char *left;       /* cub1, le */
113                 const char *right;      /* cuf1, nd */
114                 const char *home;       /* home, ho */
115                 const char *low_left;   /* ll, ll */
116                 const char *car_return; /* cr, cr */
117
118                 /* parameterized local cursor movement */
119                 const char *multi_up;    /* cuu, UP */
120                 const char *multi_down;  /* cud, DO */
121                 const char *multi_left;  /* cub, LE */
122                 const char *multi_right; /* cuf, RI */
123
124                 /* absolute cursor motion */
125                 const char *abs;        /* cup, cm */
126                 const char *hor_abs;    /* hpa, ch */
127                 const char *ver_abs;    /* vpa, cv */
128
129                 /* scrolling */
130                 const char *scroll_forw;        /* ind, sf */
131                 const char *scroll_back;        /* ri, sr */
132                 const char *multi_scroll_forw;  /* indn, SF */
133                 const char *multi_scroll_back;  /* rin, SR */
134                 const char *set_scroll_region;  /* csr, cs */
135
136         } cm;
137
138         /* screen editing entries - each entry is commented with the
139            terminfo and the termcap entry */
140         struct {
141                 /* adding to the screen */
142                 const char *ins_line;   /* il1, al */
143                 const char *multi_ins_line;     /* il, AL */
144                 const char *repeat;     /* rep, rp */
145                 const char *begin_ins_mode;     /* smir, im */
146                 const char *end_ins_mode;       /* rmir, ei */
147                 const char *ins_char;   /* ich1, ic */
148                 const char *multi_ins_char;     /* ich, IC */
149                 const char *insert_pad; /* ip, ip */
150
151                 /* deleting from the screen */
152                 const char *clr_frame;  /* clear, cl */
153                 const char *clr_from_cursor;    /* ed, cd */
154                 const char *clr_to_eol; /* el, ce */
155                 const char *del_line;   /* dl1, dl */
156                 const char *multi_del_line;     /* dl, DL */
157                 const char *del_char;   /* dch1, dc */
158                 const char *multi_del_char;     /* dch, DC */
159                 const char *begin_del_mode;     /* smdc, dm */
160                 const char *end_del_mode;       /* rmdc, ed */
161                 const char *erase_at_cursor;    /* ech, ec */
162         } se;
163
164         /* screen display entries - each entry is commented with the
165            terminfo and termcap entry */
166         struct {
167                 const char *begin_standout_;    /* smso, so */
168                 const char *end_standout_;      /* rmso, se */
169                 const char *begin_underline_;   /* smul, us */
170                 const char *end_underline_;     /* rmul, ue */
171                 const char *begin_alternate_;   /* smacs, as */
172                 const char *end_alternate_;     /* rmacs, ae */
173
174                 const char *turn_on_reverse_;           /* rev, mr */
175                 const char *turn_on_blinking_;          /* blink, mb */
176                 const char *turn_on_bold_;              /* bold, md */
177                 const char *turn_on_dim_;               /* dim, mh */
178                 const char *turn_off_attributes_;       /* sgr0, me */
179
180
181                 const char *visual_bell_;       /* flash, vb */
182                 const char *audio_bell_;        /* bel, bl */
183
184                 const char *cursor_visible_;    /* cvvis, vs */
185                 const char *cursor_normal_;     /* cnorm, ve */
186                 const char *init_motion_;       /* smcup, ti */
187                 const char *end_motion_;        /* rmcup, te */
188                 const char *keypad_on_;         /* smkx, ks */
189                 const char *keypad_off_;        /* rmkx, ke */
190
191                 /* colors */
192                 const char *set_fore_;  /* setf, Sf */
193                 const char *set_back_;  /* setb, Sb */
194                 /* tparm doesnt want these constant */
195                 char *set_afore_;       /* setaf, AF */
196                 char *set_aback_;       /* setab, AB */
197                 const char *orig_pair_; /* op, op */
198         } sd;
199
200         /* costs of various operations */
201         struct {
202                 int cm_up;
203                 int cm_down;
204                 int cm_left;
205                 int cm_right;
206                 int cm_home;
207                 int cm_low_left;
208                 int cm_car_return;
209                 int cm_abs;
210                 int cm_hor_abs;
211                 int cm_ver_abs;
212         } cost;
213
214         /* The initial tty mode bits */
215         struct emacs_tty old_tty;
216
217         /* Is this TTY our controlling terminal? */
218         unsigned int controlling_terminal:1;
219         unsigned int is_stdio:1;
220
221         /* Some flags relating to expanding the colors */
222         unsigned int is_bold_brighter    :1;
223         unsigned int is_reverse_brighter :1;
224         unsigned int nearest_color       :1;
225 };
226
227 #define CONSOLE_TTY_DATA(c) CONSOLE_TYPE_DATA (c, tty)
228 #define CONSOLE_TTY_CURSOR_X(c) (CONSOLE_TTY_DATA (c)->cursor_x)
229 #define CONSOLE_TTY_CURSOR_Y(c) (CONSOLE_TTY_DATA (c)->cursor_y)
230 #define CONSOLE_TTY_REAL_CURSOR_X(c) (CONSOLE_TTY_DATA (c)->real_cursor_x)
231 #define CONSOLE_TTY_REAL_CURSOR_Y(c) (CONSOLE_TTY_DATA (c)->real_cursor_y)
232 #define CONSOLE_TTY_FINAL_CURSOR_X(c) (CONSOLE_TTY_DATA (c)->final_cursor_x)
233 #define CONSOLE_TTY_FINAL_CURSOR_Y(c) (CONSOLE_TTY_DATA (c)->final_cursor_y)
234
235 #define TTY_CM(c) (CONSOLE_TTY_DATA (c)->cm)
236 #define TTY_SE(c) (CONSOLE_TTY_DATA (c)->se)
237 #define TTY_SD(c) (CONSOLE_TTY_DATA (c)->sd)
238 #define TTY_FLAGS(c) (CONSOLE_TTY_DATA (c)->flags)
239 #define TTY_COST(c) (CONSOLE_TTY_DATA (c)->cost)
240
241 #define TTY_INC_CURSOR_X(c, n) do {                                     \
242   int TICX_n = (n);                                                     \
243   assert (CONSOLE_TTY_CURSOR_X (c) == CONSOLE_TTY_REAL_CURSOR_X (c));   \
244   CONSOLE_TTY_CURSOR_X (c) += TICX_n;                                   \
245   CONSOLE_TTY_REAL_CURSOR_X (c) += TICX_n;                              \
246 } while (0)
247
248 #define TTY_INC_CURSOR_Y(c, n) do {             \
249   int TICY_n = (n);                             \
250   CONSOLE_TTY_CURSOR_Y (c) += TICY_n;           \
251   CONSOLE_TTY_REAL_CURSOR_Y (c) += TICY_n;      \
252 } while (0)
253
254 struct tty_device {
255 #ifdef HAVE_TERMIOS
256         speed_t ospeed;         /* Output speed (from sg_ospeed) */
257 #else
258         short ospeed;           /* Output speed (from sg_ospeed) */
259 #endif
260 };
261
262 #define DEVICE_TTY_DATA(d) DEVICE_TYPE_DATA (d, tty)
263
264 /* termcap requires this to be global */
265 #ifndef HAVE_TERMIOS
266 extern short ospeed;            /* Output speed (from sg_ospeed) */
267 #endif
268
269 extern FILE *termscript;
270
271 EXFUN(Fconsole_tty_controlling_process, 1);
272
273 /******************     Prototypes from cm.c     *******************/
274
275 /* #### Verify that all of these are still needed. */
276
277 void cm_cost_init(struct console *c);
278 void cmputc(int c);
279 void cmgoto(struct frame *f, int row, int col);
280 extern struct console *cmputc_console;
281 void send_string_to_tty_console(struct console *c, unsigned char *str, int len);
282
283 /***************     Prototypes from redisplay-tty.c     ****************/
284
285 enum term_init_status {
286         TTY_UNABLE_OPEN_DATABASE,
287         TTY_TYPE_UNDEFINED,
288         TTY_TYPE_INSUFFICIENT,
289         TTY_SIZE_UNSPECIFIED,
290         TTY_INIT_SUCCESS
291 };
292
293 int init_tty_for_redisplay(struct device *d, char *terminal_type);
294 /* #### These should probably be methods. */
295 void set_tty_modes(struct console *c);
296 void reset_tty_modes(struct console *c);
297
298 /* Used in sysdep.c to properly clear and position the cursor when exiting. */
299 void tty_redisplay_shutdown(struct console *c);
300
301 /* called from console-stream.c */
302 Lisp_Object tty_semi_canonicalize_console_connection(Lisp_Object connection,
303                                                      Error_behavior errb);
304 Lisp_Object tty_canonicalize_console_connection(Lisp_Object connection,
305                                                 Error_behavior errb);
306 Lisp_Object tty_semi_canonicalize_device_connection(Lisp_Object connection,
307                                                     Error_behavior errb);
308 Lisp_Object tty_canonicalize_device_connection(Lisp_Object connection,
309                                                Error_behavior errb);
310 struct console *tty_find_console_from_fd(int fd);
311
312 /* called from redisplay-tty.c */
313 EXFUN(find_tty_color,3);
314
315 #endif                          /* INCLUDED_console_tty_h_ */