Line discipline module now uses dynamically allocated data. Also
[u/mdw/putty] / terminal.h
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
23 struct terminal_tag {
24
25 int compatibility_level;
26
27 tree234 *scrollback; /* lines scrolled off top of screen */
28 tree234 *screen; /* lines on primary screen */
29 tree234 *alt_screen; /* lines on alternate screen */
30 int disptop; /* distance scrolled back (0 or -ve) */
31
32 unsigned long *cpos; /* cursor position (convenience) */
33
34 unsigned long *disptext; /* buffer of text on real screen */
35 unsigned long *dispcurs; /* location of cursor on real screen */
36 unsigned long curstype; /* type of cursor on real screen */
37
38 #define VBELL_TIMEOUT (TICKSPERSEC/10) /* visual bell lasts 1/10 sec */
39
40 struct beeptime *beephead, *beeptail;
41 int nbeeps;
42 int beep_overloaded;
43 long lastbeep;
44
45 #define TSIZE (sizeof(unsigned long))
46 #define fix_cpos do { \
47 term->cpos = lineptr(term->curs.y) + term->curs.x; \
48 } while(0)
49
50 unsigned long curr_attr, save_attr;
51 unsigned long erase_char;
52
53 bufchain inbuf; /* terminal input buffer */
54 pos curs; /* cursor */
55 pos savecurs; /* saved cursor position */
56 int marg_t, marg_b; /* scroll margins */
57 int dec_om; /* DEC origin mode flag */
58 int wrap, wrapnext; /* wrap flags */
59 int insert; /* insert-mode flag */
60 int cset; /* 0 or 1: which char set */
61 int save_cset, save_csattr; /* saved with cursor position */
62 int save_utf, save_wnext; /* saved with cursor position */
63 int rvideo; /* global reverse video flag */
64 unsigned long rvbell_startpoint; /* for ESC[?5hESC[?5l vbell */
65 int cursor_on; /* cursor enabled flag */
66 int reset_132; /* Flag ESC c resets to 80 cols */
67 int use_bce; /* Use Background coloured erase */
68 int blinker; /* When blinking is the cursor on ? */
69 int tblinker; /* When the blinking text is on */
70 int blink_is_real; /* Actually blink blinking text */
71 int term_echoing; /* Does terminal want local echo? */
72 int term_editing; /* Does terminal want local edit? */
73 int sco_acs, save_sco_acs; /* CSI 10,11,12m -> OEM charset */
74 int vt52_bold; /* Force bold on non-bold colours */
75 int utf; /* Are we in toggleable UTF-8 mode? */
76 int utf_state; /* Is there a pending UTF-8 character */
77 int utf_char; /* and what is it so far. */
78 int utf_size; /* The size of the UTF character. */
79 int printing, only_printing; /* Are we doing ANSI printing? */
80 int print_state; /* state of print-end-sequence scan */
81 bufchain printer_buf; /* buffered data for printer */
82 printer_job *print_job;
83
84 int rows, cols, savelines;
85 int has_focus;
86 int in_vbell;
87 unsigned long vbell_startpoint;
88 int app_cursor_keys, app_keypad_keys, vt52_mode;
89 int repeat_off, cr_lf_return;
90 int seen_disp_event;
91 int big_cursor;
92
93 long last_blink; /* used for real blinking control */
94 long last_tblink;
95
96 int xterm_mouse; /* send mouse messages to app */
97 int mouse_is_down; /* used while tracking mouse buttons */
98
99 unsigned long cset_attr[2];
100
101 /*
102 * Saved settings on the alternate screen.
103 */
104 int alt_x, alt_y, alt_om, alt_wrap, alt_wnext, alt_ins;
105 int alt_cset, alt_sco_acs, alt_utf;
106 int alt_t, alt_b;
107 int alt_which;
108
109 #define ARGS_MAX 32 /* max # of esc sequence arguments */
110 #define ARG_DEFAULT 0 /* if an arg isn't specified */
111 #define def(a,d) ( (a) == ARG_DEFAULT ? (d) : (a) )
112 int esc_args[ARGS_MAX];
113 int esc_nargs;
114 int esc_query;
115 #define ANSI(x,y) ((x)+((y)<<8))
116 #define ANSI_QUE(x) ANSI(x,TRUE)
117
118 #define OSC_STR_MAX 2048
119 int osc_strlen;
120 char osc_string[OSC_STR_MAX + 1];
121 int osc_w;
122
123 char id_string[1024];
124
125 unsigned char *tabs;
126
127 enum {
128 TOPLEVEL,
129 SEEN_ESC,
130 SEEN_CSI,
131 SEEN_OSC,
132 SEEN_OSC_W,
133
134 DO_CTRLS,
135
136 SEEN_OSC_P,
137 OSC_STRING, OSC_MAYBE_ST,
138 VT52_ESC,
139 VT52_Y1,
140 VT52_Y2,
141 VT52_FG,
142 VT52_BG
143 } termstate;
144
145 enum {
146 NO_SELECTION, ABOUT_TO, DRAGGING, SELECTED
147 } selstate;
148 enum {
149 LEXICOGRAPHIC, RECTANGULAR
150 } seltype;
151 enum {
152 SM_CHAR, SM_WORD, SM_LINE
153 } selmode;
154 pos selstart, selend, selanchor;
155
156 short wordness[256];
157
158 wchar_t *paste_buffer;
159 int paste_len, paste_pos, paste_hold;
160 long last_paste;
161
162 void (*resize_fn)(void *, int, int);
163 void *resize_ctx;
164
165 void *ldisc;
166 };
167
168 #define in_utf(term) ((term)->utf || line_codepage==CP_UTF8)
169
170 #endif