2df34b43 |
1 | /* |
2 | * Internals of the Terminal structure, for those other modules |
3 | * which need to look inside it. It would be nice if this could be |
4 | * folded back into terminal.c in future, with an abstraction layer |
5 | * to handle everything that other modules need to know about it; |
6 | * but for the moment, this will do. |
7 | */ |
8 | |
9 | #ifndef PUTTY_TERMINAL_H |
10 | #define PUTTY_TERMINAL_H |
11 | |
12 | #include "tree234.h" |
13 | |
14 | struct beeptime { |
15 | struct beeptime *next; |
16 | unsigned long ticks; |
17 | }; |
18 | |
19 | typedef struct { |
20 | int y, x; |
21 | } pos; |
22 | |
341eb978 |
23 | #ifdef OPTIMISE_SCROLL |
24 | struct scrollregion { |
25 | struct scrollregion *next; |
26 | int topline; /* Top line of scroll region. */ |
27 | int botline; /* Bottom line of scroll region. */ |
28 | int lines; /* Number of lines to scroll by - +ve is forwards. */ |
29 | }; |
30 | #endif /* OPTIMISE_SCROLL */ |
31 | |
36566009 |
32 | typedef struct termchar termchar; |
33 | typedef struct termline termline; |
34 | |
35 | struct termchar { |
c6958dfe |
36 | /* |
37 | * Any code in terminal.c which definitely needs to be changed |
38 | * when extra fields are added here is labelled with a comment |
39 | * saying FULL-TERMCHAR. |
40 | */ |
36566009 |
41 | unsigned long chr; |
42 | unsigned long attr; |
c6958dfe |
43 | |
44 | /* |
45 | * The cc_next field is used to link multiple termchars |
46 | * together into a list, so as to fit more than one character |
47 | * into a character cell (Unicode combining characters). |
48 | * |
49 | * cc_next is a relative offset into the current array of |
50 | * termchars. I.e. to advance to the next character in a list, |
51 | * one does `tc += tc->next'. |
52 | * |
53 | * Zero means end of list. |
54 | */ |
55 | int cc_next; |
36566009 |
56 | }; |
57 | |
58 | struct termline { |
59 | unsigned short lattr; |
c6958dfe |
60 | int cols; /* number of real columns on the line */ |
61 | int size; /* number of allocated termchars |
62 | * (cc-lists may make this > cols) */ |
36566009 |
63 | int temporary; /* TRUE if decompressed from scrollback */ |
c6958dfe |
64 | int cc_free; /* offset to first cc in free list */ |
36566009 |
65 | struct termchar *chars; |
66 | }; |
67 | |
2caf3cd8 |
68 | struct bidi_cache_entry { |
69 | int width; |
70 | struct termchar *chars; |
3c5a620c |
71 | int *forward, *backward; /* the permutations of line positions */ |
2caf3cd8 |
72 | }; |
73 | |
2df34b43 |
74 | struct terminal_tag { |
75 | |
76 | int compatibility_level; |
77 | |
78 | tree234 *scrollback; /* lines scrolled off top of screen */ |
79 | tree234 *screen; /* lines on primary screen */ |
80 | tree234 *alt_screen; /* lines on alternate screen */ |
81 | int disptop; /* distance scrolled back (0 or -ve) */ |
e6717a98 |
82 | int tempsblines; /* number of lines of .scrollback that |
83 | can be retrieved onto the terminal |
84 | ("temporary scrollback") */ |
2df34b43 |
85 | |
36566009 |
86 | termline **disptext; /* buffer of text on real screen */ |
87 | int dispcursx, dispcursy; /* location of cursor on real screen */ |
88 | int curstype; /* type of cursor on real screen */ |
2df34b43 |
89 | |
90 | #define VBELL_TIMEOUT (TICKSPERSEC/10) /* visual bell lasts 1/10 sec */ |
91 | |
92 | struct beeptime *beephead, *beeptail; |
93 | int nbeeps; |
94 | int beep_overloaded; |
95 | long lastbeep; |
96 | |
36566009 |
97 | #define TTYPE termchar |
3d88e64d |
98 | #define TSIZE (sizeof(TTYPE)) |
2df34b43 |
99 | |
341eb978 |
100 | #ifdef OPTIMISE_SCROLL |
101 | struct scrollregion *scrollhead, *scrolltail; |
102 | #endif /* OPTIMISE_SCROLL */ |
103 | |
36566009 |
104 | int default_attr, curr_attr, save_attr; |
105 | termchar basic_erase_char, erase_char; |
2df34b43 |
106 | |
107 | bufchain inbuf; /* terminal input buffer */ |
108 | pos curs; /* cursor */ |
109 | pos savecurs; /* saved cursor position */ |
110 | int marg_t, marg_b; /* scroll margins */ |
111 | int dec_om; /* DEC origin mode flag */ |
112 | int wrap, wrapnext; /* wrap flags */ |
113 | int insert; /* insert-mode flag */ |
114 | int cset; /* 0 or 1: which char set */ |
115 | int save_cset, save_csattr; /* saved with cursor position */ |
116 | int save_utf, save_wnext; /* saved with cursor position */ |
117 | int rvideo; /* global reverse video flag */ |
118 | unsigned long rvbell_startpoint; /* for ESC[?5hESC[?5l vbell */ |
119 | int cursor_on; /* cursor enabled flag */ |
120 | int reset_132; /* Flag ESC c resets to 80 cols */ |
121 | int use_bce; /* Use Background coloured erase */ |
39934deb |
122 | int cblinker; /* When blinking is the cursor on ? */ |
2df34b43 |
123 | int tblinker; /* When the blinking text is on */ |
124 | int blink_is_real; /* Actually blink blinking text */ |
125 | int term_echoing; /* Does terminal want local echo? */ |
126 | int term_editing; /* Does terminal want local edit? */ |
127 | int sco_acs, save_sco_acs; /* CSI 10,11,12m -> OEM charset */ |
128 | int vt52_bold; /* Force bold on non-bold colours */ |
129 | int utf; /* Are we in toggleable UTF-8 mode? */ |
130 | int utf_state; /* Is there a pending UTF-8 character */ |
131 | int utf_char; /* and what is it so far. */ |
132 | int utf_size; /* The size of the UTF character. */ |
133 | int printing, only_printing; /* Are we doing ANSI printing? */ |
134 | int print_state; /* state of print-end-sequence scan */ |
135 | bufchain printer_buf; /* buffered data for printer */ |
136 | printer_job *print_job; |
137 | |
fc9748e2 |
138 | /* ESC 7 saved state for the alternate screen */ |
139 | pos alt_savecurs; |
140 | int alt_save_attr; |
141 | int alt_save_cset, alt_save_csattr; |
142 | int alt_save_utf, alt_save_wnext; |
143 | int alt_save_sco_acs; |
144 | |
2df34b43 |
145 | int rows, cols, savelines; |
146 | int has_focus; |
147 | int in_vbell; |
39934deb |
148 | long vbell_end; |
2df34b43 |
149 | int app_cursor_keys, app_keypad_keys, vt52_mode; |
150 | int repeat_off, cr_lf_return; |
151 | int seen_disp_event; |
152 | int big_cursor; |
153 | |
0fab0315 |
154 | int xterm_mouse; /* send mouse messages to host */ |
f82370e1 |
155 | int xterm_extended_mouse; |
156 | int urxvt_extended_mouse; |
b9d7bcad |
157 | int mouse_is_down; /* used while tracking mouse buttons */ |
2df34b43 |
158 | |
61cc757f |
159 | int bracketed_paste; |
160 | |
36566009 |
161 | int cset_attr[2]; |
2df34b43 |
162 | |
163 | /* |
164 | * Saved settings on the alternate screen. |
165 | */ |
166 | int alt_x, alt_y, alt_om, alt_wrap, alt_wnext, alt_ins; |
167 | int alt_cset, alt_sco_acs, alt_utf; |
168 | int alt_t, alt_b; |
169 | int alt_which; |
876e5d5e |
170 | int alt_sblines; /* # of lines on alternate screen that should be used for scrollback. */ |
2df34b43 |
171 | |
172 | #define ARGS_MAX 32 /* max # of esc sequence arguments */ |
173 | #define ARG_DEFAULT 0 /* if an arg isn't specified */ |
174 | #define def(a,d) ( (a) == ARG_DEFAULT ? (d) : (a) ) |
175 | int esc_args[ARGS_MAX]; |
176 | int esc_nargs; |
177 | int esc_query; |
178 | #define ANSI(x,y) ((x)+((y)<<8)) |
179 | #define ANSI_QUE(x) ANSI(x,TRUE) |
180 | |
181 | #define OSC_STR_MAX 2048 |
182 | int osc_strlen; |
183 | char osc_string[OSC_STR_MAX + 1]; |
184 | int osc_w; |
185 | |
186 | char id_string[1024]; |
187 | |
188 | unsigned char *tabs; |
189 | |
190 | enum { |
191 | TOPLEVEL, |
192 | SEEN_ESC, |
193 | SEEN_CSI, |
194 | SEEN_OSC, |
195 | SEEN_OSC_W, |
196 | |
197 | DO_CTRLS, |
198 | |
199 | SEEN_OSC_P, |
200 | OSC_STRING, OSC_MAYBE_ST, |
201 | VT52_ESC, |
202 | VT52_Y1, |
203 | VT52_Y2, |
204 | VT52_FG, |
205 | VT52_BG |
206 | } termstate; |
207 | |
208 | enum { |
209 | NO_SELECTION, ABOUT_TO, DRAGGING, SELECTED |
210 | } selstate; |
211 | enum { |
212 | LEXICOGRAPHIC, RECTANGULAR |
213 | } seltype; |
214 | enum { |
215 | SM_CHAR, SM_WORD, SM_LINE |
216 | } selmode; |
217 | pos selstart, selend, selanchor; |
218 | |
219 | short wordness[256]; |
220 | |
2647b103 |
221 | /* Mask of attributes to pay attention to when painting. */ |
36566009 |
222 | int attr_mask; |
2647b103 |
223 | |
2df34b43 |
224 | wchar_t *paste_buffer; |
225 | int paste_len, paste_pos, paste_hold; |
226 | long last_paste; |
51470298 |
227 | |
228 | void (*resize_fn)(void *, int, int); |
229 | void *resize_ctx; |
b9d7bcad |
230 | |
231 | void *ldisc; |
a8327734 |
232 | |
233 | void *frontend; |
234 | |
235 | void *logctx; |
f6b14226 |
236 | |
21d2b241 |
237 | struct unicode_data *ucsdata; |
238 | |
64734920 |
239 | /* |
4a693cfc |
240 | * We maintain a full copy of a Conf here, not merely a pointer |
241 | * to it. That way, when we're passed a new one for |
242 | * reconfiguration, we can check the differences and adjust the |
243 | * _current_ setting of (e.g.) auto wrap mode rather than only |
244 | * the default. |
64734920 |
245 | */ |
4a693cfc |
246 | Conf *conf; |
74aca06d |
247 | |
248 | /* |
249 | * from_backend calls term_out, but it can also be called from |
250 | * the ldisc if the ldisc is called _within_ term_out. So we |
251 | * have to guard against re-entrancy - if from_backend is |
252 | * called recursively like this, it will simply add data to the |
253 | * end of the buffer term_out is in the process of working |
254 | * through. |
255 | */ |
256 | int in_term_out; |
f0fccd51 |
257 | |
258 | /* |
39934deb |
259 | * We schedule a window update shortly after receiving terminal |
260 | * data. This tracks whether one is currently pending. |
261 | */ |
262 | int window_update_pending; |
263 | long next_update; |
264 | |
265 | /* |
266 | * Track pending blinks and tblinks. |
267 | */ |
268 | int tblink_pending, cblink_pending; |
269 | long next_tblink, next_cblink; |
270 | |
271 | /* |
f0fccd51 |
272 | * These are buffers used by the bidi and Arabic shaping code. |
273 | */ |
36566009 |
274 | termchar *ltemp; |
c6958dfe |
275 | int ltemp_size; |
f0fccd51 |
276 | bidi_char *wcFrom, *wcTo; |
c6958dfe |
277 | int wcFromTo_size; |
2caf3cd8 |
278 | struct bidi_cache_entry *pre_bidi_cache, *post_bidi_cache; |
f0fccd51 |
279 | int bidi_cache_size; |
4a693cfc |
280 | |
281 | /* |
282 | * We copy a bunch of stuff out of the Conf structure into local |
283 | * fields in the Terminal structure, to avoid the repeated |
284 | * tree234 lookups which would be involved in fetching them from |
285 | * the former every time. |
286 | */ |
287 | int ansi_colour; |
288 | char *answerback; |
289 | int answerbacklen; |
290 | int arabicshaping; |
291 | int beep; |
292 | int bellovl; |
293 | int bellovl_n; |
294 | int bellovl_s; |
295 | int bellovl_t; |
296 | int bidi; |
297 | int bksp_is_delete; |
298 | int blink_cur; |
299 | int blinktext; |
300 | int cjk_ambig_wide; |
301 | int conf_height; |
302 | int conf_width; |
303 | int crhaslf; |
304 | int erase_to_scrollback; |
305 | int funky_type; |
306 | int lfhascr; |
307 | int logflush; |
308 | int logtype; |
309 | int mouse_override; |
310 | int nethack_keypad; |
311 | int no_alt_screen; |
312 | int no_applic_c; |
313 | int no_applic_k; |
314 | int no_dbackspace; |
315 | int no_mouse_rep; |
316 | int no_remote_charset; |
317 | int no_remote_resize; |
318 | int no_remote_wintitle; |
319 | int rawcnp; |
320 | int rect_select; |
321 | int remote_qtitle_action; |
322 | int rxvt_homeend; |
323 | int scroll_on_disp; |
324 | int scroll_on_key; |
325 | int xterm_256_colour; |
2df34b43 |
326 | }; |
327 | |
21d2b241 |
328 | #define in_utf(term) ((term)->utf || (term)->ucsdata->line_codepage==CP_UTF8) |
2df34b43 |
329 | |
330 | #endif |