]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - terminal.h
Re-engineering of terminal emulator, phase 1.
[PuTTY.git] / 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 #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
32 typedef struct termchar termchar;
33 typedef struct termline termline;
34
35 struct termchar {
36     unsigned long chr;
37     unsigned long attr;
38 };
39
40 struct termline {
41     unsigned short lattr;
42     int cols;
43     int temporary;                     /* TRUE if decompressed from scrollback */
44     struct termchar *chars;
45 };
46
47 struct terminal_tag {
48
49     int compatibility_level;
50
51     tree234 *scrollback;               /* lines scrolled off top of screen */
52     tree234 *screen;                   /* lines on primary screen */
53     tree234 *alt_screen;               /* lines on alternate screen */
54     int disptop;                       /* distance scrolled back (0 or -ve) */
55     int tempsblines;                   /* number of lines in temporary
56                                           scrollback */
57
58     termchar *cpos;                    /* cursor position (convenience) */
59
60     termline **disptext;               /* buffer of text on real screen */
61     int dispcursx, dispcursy;          /* location of cursor on real screen */
62     int curstype;                      /* type of cursor on real screen */
63
64 #define VBELL_TIMEOUT (TICKSPERSEC/10) /* visual bell lasts 1/10 sec */
65
66     struct beeptime *beephead, *beeptail;
67     int nbeeps;
68     int beep_overloaded;
69     long lastbeep;
70
71 #define TTYPE termchar
72 #define TSIZE (sizeof(TTYPE))
73 #define fix_cpos do { \
74     term->cpos = lineptr(term->curs.y)->chars + term->curs.x; \
75 } while(0)
76
77 #ifdef OPTIMISE_SCROLL
78     struct scrollregion *scrollhead, *scrolltail;
79 #endif /* OPTIMISE_SCROLL */
80
81     int default_attr, curr_attr, save_attr;
82     termchar basic_erase_char, erase_char;
83
84     bufchain inbuf;                    /* terminal input buffer */
85     pos curs;                          /* cursor */
86     pos savecurs;                      /* saved cursor position */
87     int marg_t, marg_b;                /* scroll margins */
88     int dec_om;                        /* DEC origin mode flag */
89     int wrap, wrapnext;                /* wrap flags */
90     int insert;                        /* insert-mode flag */
91     int cset;                          /* 0 or 1: which char set */
92     int save_cset, save_csattr;        /* saved with cursor position */
93     int save_utf, save_wnext;          /* saved with cursor position */
94     int rvideo;                        /* global reverse video flag */
95     unsigned long rvbell_startpoint;   /* for ESC[?5hESC[?5l vbell */
96     int cursor_on;                     /* cursor enabled flag */
97     int reset_132;                     /* Flag ESC c resets to 80 cols */
98     int use_bce;                       /* Use Background coloured erase */
99     int blinker;                       /* When blinking is the cursor on ? */
100     int tblinker;                      /* When the blinking text is on */
101     int blink_is_real;                 /* Actually blink blinking text */
102     int term_echoing;                  /* Does terminal want local echo? */
103     int term_editing;                  /* Does terminal want local edit? */
104     int sco_acs, save_sco_acs;         /* CSI 10,11,12m -> OEM charset */
105     int vt52_bold;                     /* Force bold on non-bold colours */
106     int utf;                           /* Are we in toggleable UTF-8 mode? */
107     int utf_state;                     /* Is there a pending UTF-8 character */
108     int utf_char;                      /* and what is it so far. */
109     int utf_size;                      /* The size of the UTF character. */
110     int printing, only_printing;       /* Are we doing ANSI printing? */
111     int print_state;                   /* state of print-end-sequence scan */
112     bufchain printer_buf;              /* buffered data for printer */
113     printer_job *print_job;
114
115     int rows, cols, savelines;
116     int has_focus;
117     int in_vbell;
118     unsigned long vbell_startpoint;
119     int app_cursor_keys, app_keypad_keys, vt52_mode;
120     int repeat_off, cr_lf_return;
121     int seen_disp_event;
122     int big_cursor;
123
124     long last_blink;                   /* used for real blinking control */
125     long last_tblink;
126
127     int xterm_mouse;                   /* send mouse messages to app */
128     int mouse_is_down;                 /* used while tracking mouse buttons */
129
130     int cset_attr[2];
131
132 /*
133  * Saved settings on the alternate screen.
134  */
135     int alt_x, alt_y, alt_om, alt_wrap, alt_wnext, alt_ins;
136     int alt_cset, alt_sco_acs, alt_utf;
137     int alt_t, alt_b;
138     int alt_which;
139     int alt_sblines; /* # of lines on alternate screen that should be used for scrollback. */
140
141 #define ARGS_MAX 32                    /* max # of esc sequence arguments */
142 #define ARG_DEFAULT 0                  /* if an arg isn't specified */
143 #define def(a,d) ( (a) == ARG_DEFAULT ? (d) : (a) )
144     int esc_args[ARGS_MAX];
145     int esc_nargs;
146     int esc_query;
147 #define ANSI(x,y)       ((x)+((y)<<8))
148 #define ANSI_QUE(x)     ANSI(x,TRUE)
149
150 #define OSC_STR_MAX 2048
151     int osc_strlen;
152     char osc_string[OSC_STR_MAX + 1];
153     int osc_w;
154
155     char id_string[1024];
156
157     unsigned char *tabs;
158
159     enum {
160         TOPLEVEL,
161         SEEN_ESC,
162         SEEN_CSI,
163         SEEN_OSC,
164         SEEN_OSC_W,
165
166         DO_CTRLS,
167
168         SEEN_OSC_P,
169         OSC_STRING, OSC_MAYBE_ST,
170         VT52_ESC,
171         VT52_Y1,
172         VT52_Y2,
173         VT52_FG,
174         VT52_BG
175     } termstate;
176
177     enum {
178         NO_SELECTION, ABOUT_TO, DRAGGING, SELECTED
179     } selstate;
180     enum {
181         LEXICOGRAPHIC, RECTANGULAR
182     } seltype;
183     enum {
184         SM_CHAR, SM_WORD, SM_LINE
185     } selmode;
186     pos selstart, selend, selanchor;
187
188     short wordness[256];
189
190     /* Mask of attributes to pay attention to when painting. */
191     int attr_mask;
192
193     wchar_t *paste_buffer;
194     int paste_len, paste_pos, paste_hold;
195     long last_paste;
196
197     void (*resize_fn)(void *, int, int);
198     void *resize_ctx;
199
200     void *ldisc;
201
202     void *frontend;
203
204     void *logctx;
205
206     struct unicode_data *ucsdata;
207
208     /*
209      * We maintain a full _copy_ of a Config structure here, not
210      * merely a pointer to it. That way, when we're passed a new
211      * one for reconfiguration, we can check the differences and
212      * adjust the _current_ setting of (e.g.) auto wrap mode rather
213      * than only the default.
214      */
215     Config cfg;
216
217     /*
218      * from_backend calls term_out, but it can also be called from
219      * the ldisc if the ldisc is called _within_ term_out. So we
220      * have to guard against re-entrancy - if from_backend is
221      * called recursively like this, it will simply add data to the
222      * end of the buffer term_out is in the process of working
223      * through.
224      */
225     int in_term_out;
226
227     /*
228      * These are buffers used by the bidi and Arabic shaping code.
229      */
230     termchar *ltemp;
231     bidi_char *wcFrom, *wcTo;
232     termchar **pre_bidi_cache, **post_bidi_cache;
233     int bidi_cache_size;
234 };
235
236 #define in_utf(term) ((term)->utf || (term)->ucsdata->line_codepage==CP_UTF8)
237
238 #endif