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