7
|
1 /* vi:set ts=8 sts=4 sw=4:
|
|
2 *
|
|
3 * VIM - Vi IMproved by Bram Moolenaar
|
|
4 *
|
|
5 * Do ":help uganda" in Vim to read copying and usage conditions.
|
|
6 * Do ":help credits" in Vim to see a list of people who contributed.
|
|
7 * See README.txt for an overview of the Vim source code.
|
|
8 */
|
|
9 /*
|
|
10 *
|
|
11 * term.c: functions for controlling the terminal
|
|
12 *
|
|
13 * primitive termcap support for Amiga, MSDOS, and Win32 included
|
|
14 *
|
|
15 * NOTE: padding and variable substitution is not performed,
|
|
16 * when compiling without HAVE_TGETENT, we use tputs() and tgoto() dummies.
|
|
17 */
|
|
18
|
|
19 /*
|
|
20 * Some systems have a prototype for tgetstr() with (char *) instead of
|
|
21 * (char **). This define removes that prototype. We include our own prototype
|
|
22 * below.
|
|
23 */
|
|
24
|
|
25 #define tgetstr tgetstr_defined_wrong
|
|
26 #include "vim.h"
|
|
27
|
|
28 #ifdef HAVE_TGETENT
|
|
29 # ifdef HAVE_TERMIOS_H
|
|
30 # include <termios.h> /* seems to be required for some Linux */
|
|
31 # endif
|
|
32 # ifdef HAVE_TERMCAP_H
|
|
33 # include <termcap.h>
|
|
34 # endif
|
|
35
|
|
36 /*
|
|
37 * A few linux systems define outfuntype in termcap.h to be used as the third
|
|
38 * argument for tputs().
|
|
39 */
|
|
40 # ifdef VMS
|
|
41 # define TPUTSFUNCAST
|
|
42 # else
|
|
43 # ifdef HAVE_OUTFUNTYPE
|
|
44 # define TPUTSFUNCAST (outfuntype)
|
|
45 # else
|
|
46 # define TPUTSFUNCAST (int (*)())
|
|
47 # endif
|
|
48 # endif
|
|
49 #endif
|
|
50
|
|
51 #undef tgetstr
|
|
52
|
|
53 /*
|
|
54 * Here are the builtin termcap entries. They are not stored as complete
|
|
55 * Tcarr structures, as such a structure is too big.
|
|
56 *
|
|
57 * The entries are compact, therefore they normally are included even when
|
|
58 * HAVE_TGETENT is defined. When HAVE_TGETENT is defined, the builtin entries
|
|
59 * can be accessed with "builtin_amiga", "builtin_ansi", "builtin_debug", etc.
|
|
60 *
|
|
61 * Each termcap is a list of builtin_term structures. It always starts with
|
|
62 * KS_NAME, which separates the entries. See parse_builtin_tcap() for all
|
|
63 * details.
|
|
64 * bt_entry is either a KS_xxx code (>= 0), or a K_xxx code.
|
|
65 *
|
|
66 * Entries marked with "guessed" may be wrong.
|
|
67 */
|
|
68 struct builtin_term
|
|
69 {
|
|
70 int bt_entry;
|
|
71 char *bt_string;
|
|
72 };
|
|
73
|
|
74 /* start of keys that are not directly used by Vim but can be mapped */
|
|
75 #define BT_EXTRA_KEYS 0x101
|
|
76
|
|
77 static struct builtin_term *find_builtin_term __ARGS((char_u *name));
|
|
78 static void parse_builtin_tcap __ARGS((char_u *s));
|
|
79 static void term_color __ARGS((char_u *s, int n));
|
|
80 static void gather_termleader __ARGS((void));
|
|
81 #ifdef FEAT_TERMRESPONSE
|
|
82 static void req_codes_from_term __ARGS((void));
|
|
83 static void req_more_codes_from_term __ARGS((void));
|
|
84 static void got_code_from_term __ARGS((char_u *code, int len));
|
|
85 static void check_for_codes_from_term __ARGS((void));
|
|
86 #endif
|
|
87 #if defined(FEAT_GUI) \
|
|
88 || (defined(FEAT_MOUSE) && (!defined(UNIX) || defined(FEAT_MOUSE_XTERM)))
|
|
89 static int get_bytes_from_buf __ARGS((char_u *, char_u *, int));
|
|
90 #endif
|
|
91 #ifdef FEAT_TERMRESPONSE
|
|
92 static void may_req_termresponse __ARGS((void));
|
|
93 #endif
|
|
94 static void del_termcode_idx __ARGS((int idx));
|
|
95 static int term_is_builtin __ARGS((char_u *name));
|
|
96 static int term_7to8bit __ARGS((char_u *p));
|
|
97 #ifdef FEAT_TERMRESPONSE
|
|
98 static void switch_to_8bit __ARGS((void));
|
|
99 #endif
|
|
100
|
|
101 #ifdef HAVE_TGETENT
|
|
102 static char_u *tgetent_error __ARGS((char_u *, char_u *));
|
|
103
|
|
104 /*
|
|
105 * Here is our own prototype for tgetstr(), any prototypes from the include
|
|
106 * files have been disabled by the define at the start of this file.
|
|
107 */
|
|
108 char *tgetstr __ARGS((char *, char **));
|
|
109
|
|
110 # ifdef FEAT_TERMRESPONSE
|
|
111 /* Request Terminal Version status: */
|
|
112 # define CRV_GET 1 /* send T_CRV when switched to RAW mode */
|
|
113 # define CRV_SENT 2 /* did send T_CRV, waiting for answer */
|
|
114 # define CRV_GOT 3 /* received T_CRV response */
|
|
115 static int crv_status = CRV_GET;
|
|
116 # endif
|
|
117
|
|
118 /*
|
|
119 * Don't declare these variables if termcap.h contains them.
|
|
120 * Autoconf checks if these variables should be declared extern (not all
|
|
121 * systems have them).
|
|
122 * Some versions define ospeed to be speed_t, but that is incompatible with
|
|
123 * BSD, where ospeed is short and speed_t is long.
|
|
124 */
|
|
125 # ifndef HAVE_OSPEED
|
|
126 # ifdef OSPEED_EXTERN
|
|
127 extern short ospeed;
|
|
128 # else
|
|
129 short ospeed;
|
|
130 # endif
|
|
131 # endif
|
|
132 # ifndef HAVE_UP_BC_PC
|
|
133 # ifdef UP_BC_PC_EXTERN
|
|
134 extern char *UP, *BC, PC;
|
|
135 # else
|
|
136 char *UP, *BC, PC;
|
|
137 # endif
|
|
138 # endif
|
|
139
|
|
140 # define TGETSTR(s, p) vim_tgetstr((s), (p))
|
|
141 # define TGETENT(b, t) tgetent((char *)(b), (char *)(t))
|
|
142 static char_u *vim_tgetstr __ARGS((char *s, char_u **pp));
|
|
143 #endif /* HAVE_TGETENT */
|
|
144
|
|
145 static int detected_8bit = FALSE; /* detected 8-bit terminal */
|
|
146
|
|
147 struct builtin_term builtin_termcaps[] =
|
|
148 {
|
|
149
|
|
150 #if defined(FEAT_GUI)
|
|
151 /*
|
|
152 * GUI pseudo term-cap.
|
|
153 */
|
|
154 {(int)KS_NAME, "gui"},
|
|
155 {(int)KS_CE, IF_EB("\033|$", ESC_STR "|$")},
|
|
156 {(int)KS_AL, IF_EB("\033|i", ESC_STR "|i")},
|
|
157 # ifdef TERMINFO
|
|
158 {(int)KS_CAL, IF_EB("\033|%p1%dI", ESC_STR "|%p1%dI")},
|
|
159 # else
|
|
160 {(int)KS_CAL, IF_EB("\033|%dI", ESC_STR "|%dI")},
|
|
161 # endif
|
|
162 {(int)KS_DL, IF_EB("\033|d", ESC_STR "|d")},
|
|
163 # ifdef TERMINFO
|
|
164 {(int)KS_CDL, IF_EB("\033|%p1%dD", ESC_STR "|%p1%dD")},
|
|
165 {(int)KS_CS, IF_EB("\033|%p1%d;%p2%dR", ESC_STR "|%p1%d;%p2%dR")},
|
|
166 # ifdef FEAT_VERTSPLIT
|
|
167 {(int)KS_CSV, IF_EB("\033|%p1%d;%p2%dV", ESC_STR "|%p1%d;%p2%dV")},
|
|
168 # endif
|
|
169 # else
|
|
170 {(int)KS_CDL, IF_EB("\033|%dD", ESC_STR "|%dD")},
|
|
171 {(int)KS_CS, IF_EB("\033|%d;%dR", ESC_STR "|%d;%dR")},
|
|
172 # ifdef FEAT_VERTSPLIT
|
|
173 {(int)KS_CSV, IF_EB("\033|%d;%dV", ESC_STR "|%d;%dV")},
|
|
174 # endif
|
|
175 # endif
|
|
176 {(int)KS_CL, IF_EB("\033|C", ESC_STR "|C")},
|
|
177 /* attributes switched on with 'h', off with * 'H' */
|
|
178 {(int)KS_ME, IF_EB("\033|31H", ESC_STR "|31H")}, /* HL_ALL */
|
|
179 {(int)KS_MR, IF_EB("\033|1h", ESC_STR "|1h")}, /* HL_INVERSE */
|
|
180 {(int)KS_MD, IF_EB("\033|2h", ESC_STR "|2h")}, /* HL_BOLD */
|
|
181 {(int)KS_SE, IF_EB("\033|16H", ESC_STR "|16H")}, /* HL_STANDOUT */
|
|
182 {(int)KS_SO, IF_EB("\033|16h", ESC_STR "|16h")}, /* HL_STANDOUT */
|
|
183 {(int)KS_UE, IF_EB("\033|8H", ESC_STR "|8H")}, /* HL_UNDERLINE */
|
|
184 {(int)KS_US, IF_EB("\033|8h", ESC_STR "|8h")}, /* HL_UNDERLINE */
|
|
185 {(int)KS_CZR, IF_EB("\033|4H", ESC_STR "|4H")}, /* HL_ITALIC */
|
|
186 {(int)KS_CZH, IF_EB("\033|4h", ESC_STR "|4h")}, /* HL_ITALIC */
|
|
187 {(int)KS_VB, IF_EB("\033|f", ESC_STR "|f")},
|
|
188 {(int)KS_MS, "y"},
|
|
189 {(int)KS_UT, "y"},
|
|
190 {(int)KS_LE, "\b"}, /* cursor-left = BS */
|
|
191 {(int)KS_ND, "\014"}, /* cursor-right = CTRL-L */
|
|
192 # ifdef TERMINFO
|
|
193 {(int)KS_CM, IF_EB("\033|%p1%d;%p2%dM", ESC_STR "|%p1%d;%p2%dM")},
|
|
194 # else
|
|
195 {(int)KS_CM, IF_EB("\033|%d;%dM", ESC_STR "|%d;%dM")},
|
|
196 # endif
|
|
197 /* there are no key sequences here, the GUI sequences are recognized
|
|
198 * in check_termcodes() */
|
|
199 #endif
|
|
200
|
|
201 #ifndef NO_BUILTIN_TCAPS
|
|
202 # if defined(RISCOS) || defined(ALL_BUILTIN_TCAPS)
|
|
203 /*
|
|
204 * Default for the Acorn.
|
|
205 */
|
|
206 {(int)KS_NAME, "riscos"},
|
|
207 {(int)KS_CL, "\014"}, /* Cls and Home Cursor */
|
|
208 {(int)KS_CM, "\001%d\001%d\002"}, /* Position cursor */
|
|
209
|
|
210 {(int)KS_CCO, "16"}, /* Allow 16 colors */
|
|
211
|
|
212 {(int)KS_CAF, "\001%d\021"}, /* Set foreground colour */
|
|
213 {(int)KS_CAB, "\001%d\022"}, /* Set background colour */
|
|
214
|
|
215
|
|
216 {(int)KS_ME, "\004"}, /* Normal mode */
|
|
217 {(int)KS_MR, "\005"}, /* Reverse */
|
|
218
|
|
219 {(int)KS_VI, "\016"}, /* Cursor invisible */
|
|
220 {(int)KS_VE, "\017"}, /* Cursor visible */
|
|
221 {(int)KS_VS, "\020"}, /* Cursor very visible */
|
|
222
|
|
223 {(int)KS_CS, "\001%d\001%d\003"}, /* Set scroll region */
|
|
224 {(int)KS_SR, "\023"}, /* Scroll text down */
|
|
225 {K_UP, "\217"},
|
|
226 {K_DOWN, "\216"},
|
|
227 {K_LEFT, "\214"},
|
|
228 {K_RIGHT, "\215"},
|
|
229 {K_S_UP, "\237"},
|
|
230 {K_S_DOWN, "\236"},
|
|
231 {K_S_LEFT, "\234"},
|
|
232 {K_S_RIGHT, "\235"},
|
|
233
|
|
234 {K_F1, "\201"},
|
|
235 {K_F2, "\202"},
|
|
236 {K_F3, "\203"},
|
|
237 {K_F4, "\204"},
|
|
238 {K_F5, "\205"},
|
|
239 {K_F6, "\206"},
|
|
240 {K_F7, "\207"},
|
|
241 {K_F8, "\210"},
|
|
242 {K_F9, "\211"},
|
|
243 {K_F10, "\312"},
|
|
244 {K_F11, "\313"},
|
|
245 {K_F12, "\314"},
|
|
246 {K_S_F1, "\221"},
|
|
247 {K_S_F2, "\222"},
|
|
248 {K_S_F3, "\223"},
|
|
249 {K_S_F4, "\224"},
|
|
250 {K_S_F5, "\225"},
|
|
251 {K_S_F6, "\226"},
|
|
252 {K_S_F7, "\227"},
|
|
253 {K_S_F8, "\230"},
|
|
254 {K_S_F9, "\231"},
|
|
255 {K_S_F10, "\332"},
|
|
256 {K_S_F11, "\333"},
|
|
257 {K_S_F12, "\334"},
|
|
258 {K_BS, "\010"},
|
|
259 {K_INS, "\315"},
|
|
260 {K_DEL, "\177"},
|
|
261 {K_HOME, "\036"},
|
|
262 {K_END, "\213"},
|
|
263 {K_PAGEUP, "\237"},
|
|
264 {K_PAGEDOWN, "\236"},
|
|
265 # endif /* Acorn terminal */
|
|
266
|
|
267
|
|
268 # if defined(AMIGA) || defined(ALL_BUILTIN_TCAPS)
|
|
269 /*
|
|
270 * Amiga console window, default for Amiga
|
|
271 */
|
|
272 {(int)KS_NAME, "amiga"},
|
|
273 {(int)KS_CE, "\033[K"},
|
|
274 {(int)KS_CD, "\033[J"},
|
|
275 {(int)KS_AL, "\033[L"},
|
|
276 # ifdef TERMINFO
|
|
277 {(int)KS_CAL, "\033[%p1%dL"},
|
|
278 # else
|
|
279 {(int)KS_CAL, "\033[%dL"},
|
|
280 # endif
|
|
281 {(int)KS_DL, "\033[M"},
|
|
282 # ifdef TERMINFO
|
|
283 {(int)KS_CDL, "\033[%p1%dM"},
|
|
284 # else
|
|
285 {(int)KS_CDL, "\033[%dM"},
|
|
286 # endif
|
|
287 {(int)KS_CL, "\014"},
|
|
288 {(int)KS_VI, "\033[0 p"},
|
|
289 {(int)KS_VE, "\033[1 p"},
|
|
290 {(int)KS_ME, "\033[0m"},
|
|
291 {(int)KS_MR, "\033[7m"},
|
|
292 {(int)KS_MD, "\033[1m"},
|
|
293 {(int)KS_SE, "\033[0m"},
|
|
294 {(int)KS_SO, "\033[33m"},
|
|
295 {(int)KS_US, "\033[4m"},
|
|
296 {(int)KS_UE, "\033[0m"},
|
|
297 {(int)KS_CZH, "\033[3m"},
|
|
298 {(int)KS_CZR, "\033[0m"},
|
|
299 #if defined(__MORPHOS__) || defined(__AROS__)
|
|
300 {(int)KS_CCO, "8"}, /* allow 8 colors */
|
|
301 # ifdef TERMINFO
|
|
302 {(int)KS_CAB, "\033[4%p1%dm"},/* set background color */
|
|
303 {(int)KS_CAF, "\033[3%p1%dm"},/* set foreground color */
|
|
304 # else
|
|
305 {(int)KS_CAB, "\033[4%dm"}, /* set background color */
|
|
306 {(int)KS_CAF, "\033[3%dm"}, /* set foreground color */
|
|
307 # endif
|
|
308 {(int)KS_OP, "\033[m"}, /* reset colors */
|
|
309 #endif
|
|
310 {(int)KS_MS, "y"},
|
|
311 {(int)KS_UT, "y"}, /* guessed */
|
|
312 {(int)KS_LE, "\b"},
|
|
313 # ifdef TERMINFO
|
|
314 {(int)KS_CM, "\033[%i%p1%d;%p2%dH"},
|
|
315 # else
|
|
316 {(int)KS_CM, "\033[%i%d;%dH"},
|
|
317 # endif
|
|
318 #if defined(__MORPHOS__)
|
|
319 {(int)KS_SR, "\033M"},
|
|
320 #endif
|
|
321 # ifdef TERMINFO
|
|
322 {(int)KS_CRI, "\033[%p1%dC"},
|
|
323 # else
|
|
324 {(int)KS_CRI, "\033[%dC"},
|
|
325 # endif
|
|
326 {K_UP, "\233A"},
|
|
327 {K_DOWN, "\233B"},
|
|
328 {K_LEFT, "\233D"},
|
|
329 {K_RIGHT, "\233C"},
|
|
330 {K_S_UP, "\233T"},
|
|
331 {K_S_DOWN, "\233S"},
|
|
332 {K_S_LEFT, "\233 A"},
|
|
333 {K_S_RIGHT, "\233 @"},
|
|
334 {K_S_TAB, "\233Z"},
|
|
335 {K_F1, "\233\060~"},/* some compilers don't dig "\2330" */
|
|
336 {K_F2, "\233\061~"},
|
|
337 {K_F3, "\233\062~"},
|
|
338 {K_F4, "\233\063~"},
|
|
339 {K_F5, "\233\064~"},
|
|
340 {K_F6, "\233\065~"},
|
|
341 {K_F7, "\233\066~"},
|
|
342 {K_F8, "\233\067~"},
|
|
343 {K_F9, "\233\070~"},
|
|
344 {K_F10, "\233\071~"},
|
|
345 {K_S_F1, "\233\061\060~"},
|
|
346 {K_S_F2, "\233\061\061~"},
|
|
347 {K_S_F3, "\233\061\062~"},
|
|
348 {K_S_F4, "\233\061\063~"},
|
|
349 {K_S_F5, "\233\061\064~"},
|
|
350 {K_S_F6, "\233\061\065~"},
|
|
351 {K_S_F7, "\233\061\066~"},
|
|
352 {K_S_F8, "\233\061\067~"},
|
|
353 {K_S_F9, "\233\061\070~"},
|
|
354 {K_S_F10, "\233\061\071~"},
|
|
355 {K_HELP, "\233?~"},
|
|
356 {K_INS, "\233\064\060~"}, /* 101 key keyboard */
|
|
357 {K_PAGEUP, "\233\064\061~"}, /* 101 key keyboard */
|
|
358 {K_PAGEDOWN, "\233\064\062~"}, /* 101 key keyboard */
|
|
359 {K_HOME, "\233\064\064~"}, /* 101 key keyboard */
|
|
360 {K_END, "\233\064\065~"}, /* 101 key keyboard */
|
|
361
|
|
362 {BT_EXTRA_KEYS, ""},
|
|
363 {TERMCAP2KEY('#', '2'), "\233\065\064~"}, /* shifted home key */
|
|
364 {TERMCAP2KEY('#', '3'), "\233\065\060~"}, /* shifted insert key */
|
|
365 {TERMCAP2KEY('*', '7'), "\233\065\065~"}, /* shifted end key */
|
|
366 # endif
|
|
367
|
|
368 # if defined(__BEOS__) || defined(ALL_BUILTIN_TCAPS)
|
|
369 /*
|
|
370 * almost standard ANSI terminal, default for bebox
|
|
371 */
|
|
372 {(int)KS_NAME, "beos-ansi"},
|
|
373 {(int)KS_CE, "\033[K"},
|
|
374 {(int)KS_CD, "\033[J"},
|
|
375 {(int)KS_AL, "\033[L"},
|
|
376 # ifdef TERMINFO
|
|
377 {(int)KS_CAL, "\033[%p1%dL"},
|
|
378 # else
|
|
379 {(int)KS_CAL, "\033[%dL"},
|
|
380 # endif
|
|
381 {(int)KS_DL, "\033[M"},
|
|
382 # ifdef TERMINFO
|
|
383 {(int)KS_CDL, "\033[%p1%dM"},
|
|
384 # else
|
|
385 {(int)KS_CDL, "\033[%dM"},
|
|
386 # endif
|
|
387 #ifdef BEOS_PR_OR_BETTER
|
|
388 # ifdef TERMINFO
|
|
389 {(int)KS_CS, "\033[%i%p1%d;%p2%dr"},
|
|
390 # else
|
|
391 {(int)KS_CS, "\033[%i%d;%dr"}, /* scroll region */
|
|
392 # endif
|
|
393 #endif
|
|
394 {(int)KS_CL, "\033[H\033[2J"},
|
|
395 #ifdef notyet
|
|
396 {(int)KS_VI, "[VI]"}, /* cursor invisible, VT320: CSI ? 25 l */
|
|
397 {(int)KS_VE, "[VE]"}, /* cursor visible, VT320: CSI ? 25 h */
|
|
398 #endif
|
|
399 {(int)KS_ME, "\033[m"}, /* normal mode */
|
|
400 {(int)KS_MR, "\033[7m"}, /* reverse */
|
|
401 {(int)KS_MD, "\033[1m"}, /* bold */
|
|
402 {(int)KS_SO, "\033[31m"}, /* standout mode: red */
|
|
403 {(int)KS_SE, "\033[m"}, /* standout end */
|
|
404 {(int)KS_CZH, "\033[35m"}, /* italic: purple */
|
|
405 {(int)KS_CZR, "\033[m"}, /* italic end */
|
|
406 {(int)KS_US, "\033[4m"}, /* underscore mode */
|
|
407 {(int)KS_UE, "\033[m"}, /* underscore end */
|
|
408 {(int)KS_CCO, "8"}, /* allow 8 colors */
|
|
409 # ifdef TERMINFO
|
|
410 {(int)KS_CAB, "\033[4%p1%dm"},/* set background color */
|
|
411 {(int)KS_CAF, "\033[3%p1%dm"},/* set foreground color */
|
|
412 # else
|
|
413 {(int)KS_CAB, "\033[4%dm"}, /* set background color */
|
|
414 {(int)KS_CAF, "\033[3%dm"}, /* set foreground color */
|
|
415 # endif
|
|
416 {(int)KS_OP, "\033[m"}, /* reset colors */
|
|
417 {(int)KS_MS, "y"}, /* safe to move cur in reverse mode */
|
|
418 {(int)KS_UT, "y"}, /* guessed */
|
|
419 {(int)KS_LE, "\b"},
|
|
420 # ifdef TERMINFO
|
|
421 {(int)KS_CM, "\033[%i%p1%d;%p2%dH"},
|
|
422 # else
|
|
423 {(int)KS_CM, "\033[%i%d;%dH"},
|
|
424 # endif
|
|
425 {(int)KS_SR, "\033M"},
|
|
426 # ifdef TERMINFO
|
|
427 {(int)KS_CRI, "\033[%p1%dC"},
|
|
428 # else
|
|
429 {(int)KS_CRI, "\033[%dC"},
|
|
430 # endif
|
|
431 #if defined(BEOS_DR8)
|
|
432 {(int)KS_DB, ""}, /* hack! see screen.c */
|
|
433 #endif
|
|
434
|
|
435 {K_UP, "\033[A"},
|
|
436 {K_DOWN, "\033[B"},
|
|
437 {K_LEFT, "\033[D"},
|
|
438 {K_RIGHT, "\033[C"},
|
|
439 # endif
|
|
440
|
|
441 # if defined(UNIX) || defined(ALL_BUILTIN_TCAPS) || defined(SOME_BUILTIN_TCAPS) || defined(__EMX__)
|
|
442 /*
|
|
443 * standard ANSI terminal, default for unix
|
|
444 */
|
|
445 {(int)KS_NAME, "ansi"},
|
|
446 {(int)KS_CE, IF_EB("\033[K", ESC_STR "[K")},
|
|
447 {(int)KS_AL, IF_EB("\033[L", ESC_STR "[L")},
|
|
448 # ifdef TERMINFO
|
|
449 {(int)KS_CAL, IF_EB("\033[%p1%dL", ESC_STR "[%p1%dL")},
|
|
450 # else
|
|
451 {(int)KS_CAL, IF_EB("\033[%dL", ESC_STR "[%dL")},
|
|
452 # endif
|
|
453 {(int)KS_DL, IF_EB("\033[M", ESC_STR "[M")},
|
|
454 # ifdef TERMINFO
|
|
455 {(int)KS_CDL, IF_EB("\033[%p1%dM", ESC_STR "[%p1%dM")},
|
|
456 # else
|
|
457 {(int)KS_CDL, IF_EB("\033[%dM", ESC_STR "[%dM")},
|
|
458 # endif
|
|
459 {(int)KS_CL, IF_EB("\033[H\033[2J", ESC_STR "[H" ESC_STR_nc "[2J")},
|
|
460 {(int)KS_ME, IF_EB("\033[0m", ESC_STR "[0m")},
|
|
461 {(int)KS_MR, IF_EB("\033[7m", ESC_STR "[7m")},
|
|
462 {(int)KS_MS, "y"},
|
|
463 {(int)KS_UT, "y"}, /* guessed */
|
|
464 {(int)KS_LE, "\b"},
|
|
465 # ifdef TERMINFO
|
|
466 {(int)KS_CM, IF_EB("\033[%i%p1%d;%p2%dH", ESC_STR "[%i%p1%d;%p2%dH")},
|
|
467 # else
|
|
468 {(int)KS_CM, IF_EB("\033[%i%d;%dH", ESC_STR "[%i%d;%dH")},
|
|
469 # endif
|
|
470 # ifdef TERMINFO
|
|
471 {(int)KS_CRI, IF_EB("\033[%p1%dC", ESC_STR "[%p1%dC")},
|
|
472 # else
|
|
473 {(int)KS_CRI, IF_EB("\033[%dC", ESC_STR "[%dC")},
|
|
474 # endif
|
|
475 # endif
|
|
476
|
|
477 # if defined(MSDOS) || defined(ALL_BUILTIN_TCAPS) || defined(__EMX__)
|
|
478 /*
|
|
479 * These codes are valid when nansi.sys or equivalent has been installed.
|
|
480 * Function keys on a PC are preceded with a NUL. These are converted into
|
|
481 * K_NUL '\316' in mch_inchar(), because we cannot handle NULs in key codes.
|
|
482 * CTRL-arrow is used instead of SHIFT-arrow.
|
|
483 */
|
|
484 #ifdef __EMX__
|
|
485 {(int)KS_NAME, "os2ansi"},
|
|
486 #else
|
|
487 {(int)KS_NAME, "pcansi"},
|
|
488 {(int)KS_DL, "\033[M"},
|
|
489 {(int)KS_AL, "\033[L"},
|
|
490 #endif
|
|
491 {(int)KS_CE, "\033[K"},
|
|
492 {(int)KS_CL, "\033[2J"},
|
|
493 {(int)KS_ME, "\033[0m"},
|
|
494 {(int)KS_MR, "\033[5m"}, /* reverse: black on lightgrey */
|
|
495 {(int)KS_MD, "\033[1m"}, /* bold: white text */
|
|
496 {(int)KS_SE, "\033[0m"}, /* standout end */
|
|
497 {(int)KS_SO, "\033[31m"}, /* standout: white on blue */
|
|
498 {(int)KS_CZH, "\033[34;43m"}, /* italic mode: blue text on yellow */
|
|
499 {(int)KS_CZR, "\033[0m"}, /* italic mode end */
|
|
500 {(int)KS_US, "\033[36;41m"}, /* underscore mode: cyan text on red */
|
|
501 {(int)KS_UE, "\033[0m"}, /* underscore mode end */
|
|
502 {(int)KS_CCO, "8"}, /* allow 8 colors */
|
|
503 # ifdef TERMINFO
|
|
504 {(int)KS_CAB, "\033[4%p1%dm"},/* set background color */
|
|
505 {(int)KS_CAF, "\033[3%p1%dm"},/* set foreground color */
|
|
506 # else
|
|
507 {(int)KS_CAB, "\033[4%dm"}, /* set background color */
|
|
508 {(int)KS_CAF, "\033[3%dm"}, /* set foreground color */
|
|
509 # endif
|
|
510 {(int)KS_OP, "\033[0m"}, /* reset colors */
|
|
511 {(int)KS_MS, "y"},
|
|
512 {(int)KS_UT, "y"}, /* guessed */
|
|
513 {(int)KS_LE, "\b"},
|
|
514 # ifdef TERMINFO
|
|
515 {(int)KS_CM, "\033[%i%p1%d;%p2%dH"},
|
|
516 # else
|
|
517 {(int)KS_CM, "\033[%i%d;%dH"},
|
|
518 # endif
|
|
519 # ifdef TERMINFO
|
|
520 {(int)KS_CRI, "\033[%p1%dC"},
|
|
521 # else
|
|
522 {(int)KS_CRI, "\033[%dC"},
|
|
523 # endif
|
|
524 {K_UP, "\316H"},
|
|
525 {K_DOWN, "\316P"},
|
|
526 {K_LEFT, "\316K"},
|
|
527 {K_RIGHT, "\316M"},
|
|
528 {K_S_LEFT, "\316s"},
|
|
529 {K_S_RIGHT, "\316t"},
|
|
530 {K_F1, "\316;"},
|
|
531 {K_F2, "\316<"},
|
|
532 {K_F3, "\316="},
|
|
533 {K_F4, "\316>"},
|
|
534 {K_F5, "\316?"},
|
|
535 {K_F6, "\316@"},
|
|
536 {K_F7, "\316A"},
|
|
537 {K_F8, "\316B"},
|
|
538 {K_F9, "\316C"},
|
|
539 {K_F10, "\316D"},
|
|
540 {K_F11, "\316\205"}, /* guessed */
|
|
541 {K_F12, "\316\206"}, /* guessed */
|
|
542 {K_S_F1, "\316T"},
|
|
543 {K_S_F2, "\316U"},
|
|
544 {K_S_F3, "\316V"},
|
|
545 {K_S_F4, "\316W"},
|
|
546 {K_S_F5, "\316X"},
|
|
547 {K_S_F6, "\316Y"},
|
|
548 {K_S_F7, "\316Z"},
|
|
549 {K_S_F8, "\316["},
|
|
550 {K_S_F9, "\316\\"},
|
|
551 {K_S_F10, "\316]"},
|
|
552 {K_S_F11, "\316\207"}, /* guessed */
|
|
553 {K_S_F12, "\316\210"}, /* guessed */
|
|
554 {K_INS, "\316R"},
|
|
555 {K_DEL, "\316S"},
|
|
556 {K_HOME, "\316G"},
|
|
557 {K_END, "\316O"},
|
|
558 {K_PAGEDOWN, "\316Q"},
|
|
559 {K_PAGEUP, "\316I"},
|
|
560 # endif
|
|
561
|
|
562 # if defined(MSDOS)
|
|
563 /*
|
|
564 * These codes are valid for the pc video. The entries that start with ESC |
|
|
565 * are translated into conio calls in os_msdos.c. Default for MSDOS.
|
|
566 */
|
|
567 {(int)KS_NAME, "pcterm"},
|
|
568 {(int)KS_CE, "\033|K"},
|
|
569 {(int)KS_AL, "\033|L"},
|
|
570 {(int)KS_DL, "\033|M"},
|
|
571 # ifdef TERMINFO
|
|
572 {(int)KS_CS, "\033|%i%p1%d;%p2%dr"},
|
|
573 # ifdef FEAT_VERTSPLIT
|
|
574 {(int)KS_CSV, "\033|%i%p1%d;%p2%dV"},
|
|
575 # endif
|
|
576 # else
|
|
577 {(int)KS_CS, "\033|%i%d;%dr"},
|
|
578 # ifdef FEAT_VERTSPLIT
|
|
579 {(int)KS_CSV, "\033|%i%d;%dV"},
|
|
580 # endif
|
|
581 # endif
|
|
582 {(int)KS_CL, "\033|J"},
|
|
583 {(int)KS_ME, "\033|0m"}, /* normal */
|
|
584 {(int)KS_MR, "\033|112m"}, /* reverse: black on lightgrey */
|
|
585 {(int)KS_MD, "\033|15m"}, /* bold: white text */
|
|
586 {(int)KS_SE, "\033|0m"}, /* standout end */
|
|
587 {(int)KS_SO, "\033|31m"}, /* standout: white on blue */
|
|
588 {(int)KS_CZH, "\033|225m"}, /* italic mode: blue text on yellow */
|
|
589 {(int)KS_CZR, "\033|0m"}, /* italic mode end */
|
|
590 {(int)KS_US, "\033|67m"}, /* underscore mode: cyan text on red */
|
|
591 {(int)KS_UE, "\033|0m"}, /* underscore mode end */
|
|
592 {(int)KS_CCO, "16"}, /* allow 16 colors */
|
|
593 # ifdef TERMINFO
|
|
594 {(int)KS_CAB, "\033|%p1%db"}, /* set background color */
|
|
595 {(int)KS_CAF, "\033|%p1%df"}, /* set foreground color */
|
|
596 # else
|
|
597 {(int)KS_CAB, "\033|%db"}, /* set background color */
|
|
598 {(int)KS_CAF, "\033|%df"}, /* set foreground color */
|
|
599 # endif
|
|
600 {(int)KS_MS, "y"},
|
|
601 {(int)KS_UT, "y"},
|
|
602 {(int)KS_LE, "\b"},
|
|
603 # ifdef TERMINFO
|
|
604 {(int)KS_CM, "\033|%i%p1%d;%p2%dH"},
|
|
605 # else
|
|
606 {(int)KS_CM, "\033|%i%d;%dH"},
|
|
607 # endif
|
|
608 #ifdef DJGPP
|
|
609 {(int)KS_VB, "\033|B"}, /* visual bell */
|
|
610 #endif
|
|
611 {K_UP, "\316H"},
|
|
612 {K_DOWN, "\316P"},
|
|
613 {K_LEFT, "\316K"},
|
|
614 {K_RIGHT, "\316M"},
|
|
615 {K_S_LEFT, "\316s"},
|
|
616 {K_S_RIGHT, "\316t"},
|
|
617 {K_S_TAB, "\316\017"},
|
|
618 {K_F1, "\316;"},
|
|
619 {K_F2, "\316<"},
|
|
620 {K_F3, "\316="},
|
|
621 {K_F4, "\316>"},
|
|
622 {K_F5, "\316?"},
|
|
623 {K_F6, "\316@"},
|
|
624 {K_F7, "\316A"},
|
|
625 {K_F8, "\316B"},
|
|
626 {K_F9, "\316C"},
|
|
627 {K_F10, "\316D"},
|
|
628 {K_F11, "\316\205"},
|
|
629 {K_F12, "\316\206"},
|
|
630 {K_S_F1, "\316T"},
|
|
631 {K_S_F2, "\316U"},
|
|
632 {K_S_F3, "\316V"},
|
|
633 {K_S_F4, "\316W"},
|
|
634 {K_S_F5, "\316X"},
|
|
635 {K_S_F6, "\316Y"},
|
|
636 {K_S_F7, "\316Z"},
|
|
637 {K_S_F8, "\316["},
|
|
638 {K_S_F9, "\316\\"},
|
|
639 {K_S_F10, "\316]"},
|
|
640 {K_S_F11, "\316\207"},
|
|
641 {K_S_F12, "\316\210"},
|
|
642 {K_INS, "\316R"},
|
|
643 {K_DEL, "\316S"},
|
|
644 {K_HOME, "\316G"},
|
|
645 {K_END, "\316O"},
|
|
646 {K_PAGEDOWN, "\316Q"},
|
|
647 {K_PAGEUP, "\316I"},
|
|
648 {K_KPLUS, "\316N"},
|
|
649 {K_KMINUS, "\316J"},
|
|
650 {K_KMULTIPLY, "\3167"},
|
|
651 {K_K0, "\316\332"},
|
|
652 {K_K1, "\316\336"},
|
|
653 {K_K2, "\316\342"},
|
|
654 {K_K3, "\316\346"},
|
|
655 {K_K4, "\316\352"},
|
|
656 {K_K5, "\316\356"},
|
|
657 {K_K6, "\316\362"},
|
|
658 {K_K7, "\316\366"},
|
|
659 {K_K8, "\316\372"},
|
|
660 {K_K9, "\316\376"},
|
|
661 # endif
|
|
662
|
|
663 # if defined(WIN3264) || defined(ALL_BUILTIN_TCAPS) || defined(__EMX__)
|
|
664 /*
|
|
665 * These codes are valid for the Win32 Console . The entries that start with
|
|
666 * ESC | are translated into console calls in os_win32.c. The function keys
|
|
667 * are also translated in os_win32.c.
|
|
668 */
|
|
669 {(int)KS_NAME, "win32"},
|
|
670 {(int)KS_CE, "\033|K"}, /* clear to end of line */
|
|
671 {(int)KS_AL, "\033|L"}, /* add new blank line */
|
|
672 # ifdef TERMINFO
|
|
673 {(int)KS_CAL, "\033|%p1%dL"}, /* add number of new blank lines */
|
|
674 # else
|
|
675 {(int)KS_CAL, "\033|%dL"}, /* add number of new blank lines */
|
|
676 # endif
|
|
677 {(int)KS_DL, "\033|M"}, /* delete line */
|
|
678 # ifdef TERMINFO
|
|
679 {(int)KS_CDL, "\033|%p1%dM"}, /* delete number of lines */
|
|
680 # else
|
|
681 {(int)KS_CDL, "\033|%dM"}, /* delete number of lines */
|
|
682 # endif
|
|
683 {(int)KS_CL, "\033|J"}, /* clear screen */
|
|
684 {(int)KS_CD, "\033|j"}, /* clear to end of display */
|
|
685 {(int)KS_VI, "\033|v"}, /* cursor invisible */
|
|
686 {(int)KS_VE, "\033|V"}, /* cursor visible */
|
|
687
|
|
688 {(int)KS_ME, "\033|0m"}, /* normal */
|
|
689 {(int)KS_MR, "\033|112m"}, /* reverse: black on lightgray */
|
|
690 {(int)KS_MD, "\033|15m"}, /* bold: white on black */
|
|
691 #if 1
|
|
692 {(int)KS_SO, "\033|31m"}, /* standout: white on blue */
|
|
693 {(int)KS_SE, "\033|0m"}, /* standout end */
|
|
694 #else
|
|
695 {(int)KS_SO, "\033|F"}, /* standout: high intensity */
|
|
696 {(int)KS_SE, "\033|f"}, /* standout end */
|
|
697 #endif
|
|
698 {(int)KS_CZH, "\033|225m"}, /* italic: blue text on yellow */
|
|
699 {(int)KS_CZR, "\033|0m"}, /* italic end */
|
|
700 {(int)KS_US, "\033|67m"}, /* underscore: cyan text on red */
|
|
701 {(int)KS_UE, "\033|0m"}, /* underscore end */
|
|
702 {(int)KS_CCO, "16"}, /* allow 16 colors */
|
|
703 # ifdef TERMINFO
|
|
704 {(int)KS_CAB, "\033|%p1%db"}, /* set background color */
|
|
705 {(int)KS_CAF, "\033|%p1%df"}, /* set foreground color */
|
|
706 # else
|
|
707 {(int)KS_CAB, "\033|%db"}, /* set background color */
|
|
708 {(int)KS_CAF, "\033|%df"}, /* set foreground color */
|
|
709 # endif
|
|
710
|
|
711 {(int)KS_MS, "y"}, /* save to move cur in reverse mode */
|
|
712 {(int)KS_UT, "y"},
|
|
713 {(int)KS_LE, "\b"},
|
|
714 # ifdef TERMINFO
|
|
715 {(int)KS_CM, "\033|%i%p1%d;%p2%dH"},/* cursor motion */
|
|
716 # else
|
|
717 {(int)KS_CM, "\033|%i%d;%dH"},/* cursor motion */
|
|
718 # endif
|
|
719 {(int)KS_VB, "\033|B"}, /* visual bell */
|
|
720 {(int)KS_TI, "\033|S"}, /* put terminal in termcap mode */
|
|
721 {(int)KS_TE, "\033|E"}, /* out of termcap mode */
|
|
722 # ifdef TERMINFO
|
|
723 {(int)KS_CS, "\033|%i%p1%d;%p2%dr"},/* scroll region */
|
|
724 # else
|
|
725 {(int)KS_CS, "\033|%i%d;%dr"},/* scroll region */
|
|
726 # endif
|
|
727
|
|
728 {K_UP, "\316H"},
|
|
729 {K_DOWN, "\316P"},
|
|
730 {K_LEFT, "\316K"},
|
|
731 {K_RIGHT, "\316M"},
|
|
732 {K_S_UP, "\316\304"},
|
|
733 {K_S_DOWN, "\316\317"},
|
|
734 {K_S_LEFT, "\316\311"},
|
|
735 {K_C_LEFT, "\316s"},
|
|
736 {K_S_RIGHT, "\316\313"},
|
|
737 {K_C_RIGHT, "\316t"},
|
|
738 {K_S_TAB, "\316\017"},
|
|
739 {K_F1, "\316;"},
|
|
740 {K_F2, "\316<"},
|
|
741 {K_F3, "\316="},
|
|
742 {K_F4, "\316>"},
|
|
743 {K_F5, "\316?"},
|
|
744 {K_F6, "\316@"},
|
|
745 {K_F7, "\316A"},
|
|
746 {K_F8, "\316B"},
|
|
747 {K_F9, "\316C"},
|
|
748 {K_F10, "\316D"},
|
|
749 {K_F11, "\316\205"},
|
|
750 {K_F12, "\316\206"},
|
|
751 {K_S_F1, "\316T"},
|
|
752 {K_S_F2, "\316U"},
|
|
753 {K_S_F3, "\316V"},
|
|
754 {K_S_F4, "\316W"},
|
|
755 {K_S_F5, "\316X"},
|
|
756 {K_S_F6, "\316Y"},
|
|
757 {K_S_F7, "\316Z"},
|
|
758 {K_S_F8, "\316["},
|
|
759 {K_S_F9, "\316\\"},
|
|
760 {K_S_F10, "\316]"},
|
|
761 {K_S_F11, "\316\207"},
|
|
762 {K_S_F12, "\316\210"},
|
|
763 {K_INS, "\316R"},
|
|
764 {K_DEL, "\316S"},
|
|
765 {K_HOME, "\316G"},
|
|
766 {K_S_HOME, "\316\302"},
|
|
767 {K_C_HOME, "\316w"},
|
|
768 {K_END, "\316O"},
|
|
769 {K_S_END, "\316\315"},
|
|
770 {K_C_END, "\316u"},
|
|
771 {K_PAGEDOWN, "\316Q"},
|
|
772 {K_PAGEUP, "\316I"},
|
|
773 {K_KPLUS, "\316N"},
|
|
774 {K_KMINUS, "\316J"},
|
|
775 {K_KMULTIPLY, "\316\067"},
|
|
776 {K_K0, "\316\332"},
|
|
777 {K_K1, "\316\336"},
|
|
778 {K_K2, "\316\342"},
|
|
779 {K_K3, "\316\346"},
|
|
780 {K_K4, "\316\352"},
|
|
781 {K_K5, "\316\356"},
|
|
782 {K_K6, "\316\362"},
|
|
783 {K_K7, "\316\366"},
|
|
784 {K_K8, "\316\372"},
|
|
785 {K_K9, "\316\376"},
|
|
786 # endif
|
|
787
|
|
788 # if defined(VMS) || defined(ALL_BUILTIN_TCAPS)
|
|
789 /*
|
|
790 * VT320 is working as an ANSI terminal compatible DEC terminal.
|
|
791 * (it covers VT1x0, VT2x0 and VT3x0 up to VT320 on VMS as well)
|
|
792 * Note: K_F1...K_F5 are for internal use, should not be defined.
|
|
793 * TODO:- rewrite ESC[ codes to CSI
|
|
794 * - keyboard languages (CSI ? 26 n)
|
|
795 */
|
|
796 {(int)KS_NAME, "vt320"},
|
|
797 {(int)KS_CE, IF_EB("\033[K", ESC_STR "[K")},
|
|
798 {(int)KS_AL, IF_EB("\033[L", ESC_STR "[L")},
|
|
799 # ifdef TERMINFO
|
|
800 {(int)KS_CAL, IF_EB("\033[%p1%dL", ESC_STR "[%p1%dL")},
|
|
801 # else
|
|
802 {(int)KS_CAL, IF_EB("\033[%dL", ESC_STR "[%dL")},
|
|
803 # endif
|
|
804 {(int)KS_DL, IF_EB("\033[M", ESC_STR "[M")},
|
|
805 # ifdef TERMINFO
|
|
806 {(int)KS_CDL, IF_EB("\033[%p1%dM", ESC_STR "[%p1%dM")},
|
|
807 # else
|
|
808 {(int)KS_CDL, IF_EB("\033[%dM", ESC_STR "[%dM")},
|
|
809 # endif
|
|
810 {(int)KS_CL, IF_EB("\033[H\033[2J", ESC_STR "[H" ESC_STR_nc "[2J")},
|
22
|
811 {(int)KS_CD, IF_EB("\033[J", ESC_STR "[J")},
|
|
812 {(int)KS_CCO, "8"}, /* allow 8 colors */
|
7
|
813 {(int)KS_ME, IF_EB("\033[0m", ESC_STR "[0m")},
|
|
814 {(int)KS_MR, IF_EB("\033[7m", ESC_STR "[7m")},
|
22
|
815 {(int)KS_MD, IF_EB("\033[1m", ESC_STR "[1m")}, /* bold mode */
|
|
816 {(int)KS_SE, IF_EB("\033[22m", ESC_STR "[22m")},/* normal mode */
|
|
817 {(int)KS_UE, IF_EB("\033[24m", ESC_STR "[24m")},/* exit underscore mode */
|
|
818 {(int)KS_US, IF_EB("\033[4m", ESC_STR "[4m")}, /* underscore mode */
|
|
819 {(int)KS_CZH, IF_EB("\033[34;43m", ESC_STR "[34;43m" )}, /* italic mode: blue text on yellow */
|
|
820 {(int)KS_CZR, IF_EB("\033[0m", ESC_STR "[0m")}, /* italic mode end */
|
|
821 {(int)KS_CAB, IF_EB("\033[4%dm", ESC_STR "[4%dm" )}, /* set background color (ANSI) */
|
|
822 {(int)KS_CAF, IF_EB("\033[3%dm", ESC_STR "[3%dm" )}, /* set foreground color (ANSI) */
|
|
823 {(int)KS_CSB, IF_EB("\033[102;%dm", ESC_STR "[102;%dm" )}, /* set screen background color */
|
|
824 {(int)KS_CSF, IF_EB("\033[101;%dm", ESC_STR "[101;%dm" )}, /* set screen foreground color */
|
7
|
825 {(int)KS_MS, "y"},
|
|
826 {(int)KS_UT, "y"},
|
|
827 {(int)KS_LE, "\b"},
|
|
828 # ifdef TERMINFO
|
|
829 {(int)KS_CM, IF_EB("\033[%i%p1%d;%p2%dH",
|
|
830 ESC_STR "[%i%p1%d;%p2%dH")},
|
|
831 # else
|
|
832 {(int)KS_CM, IF_EB("\033[%i%d;%dH", ESC_STR "[%i%d;%dH")},
|
|
833 # endif
|
|
834 # ifdef TERMINFO
|
|
835 {(int)KS_CRI, IF_EB("\033[%p1%dC", ESC_STR "[%p1%dC")},
|
|
836 # else
|
|
837 {(int)KS_CRI, IF_EB("\033[%dC", ESC_STR "[%dC")},
|
|
838 # endif
|
|
839 {K_UP, IF_EB("\033[A", ESC_STR "[A")},
|
|
840 {K_DOWN, IF_EB("\033[B", ESC_STR "[B")},
|
|
841 {K_RIGHT, IF_EB("\033[C", ESC_STR "[C")},
|
|
842 {K_LEFT, IF_EB("\033[D", ESC_STR "[D")},
|
|
843 {K_F6, IF_EB("\033[17~", ESC_STR "[17~")},
|
|
844 {K_F7, IF_EB("\033[18~", ESC_STR "[18~")},
|
|
845 {K_F8, IF_EB("\033[19~", ESC_STR "[19~")},
|
|
846 {K_F9, IF_EB("\033[20~", ESC_STR "[20~")},
|
|
847 {K_F10, IF_EB("\033[21~", ESC_STR "[21~")},
|
|
848 /* {K_F11, IF_EB("\033[23~", ESC_STR "[23~")},
|
|
849 * (ESC) should not define, sometimes does not work */
|
|
850 {K_F12, IF_EB("\033[24~", ESC_STR "[24~")},
|
|
851 {K_F13, IF_EB("\033[25~", ESC_STR "[25~")},
|
|
852 {K_F14, IF_EB("\033[26~", ESC_STR "[26~")},
|
|
853 {K_F15, IF_EB("\033[28~", ESC_STR "[28~")}, /* Help */
|
|
854 {K_F16, IF_EB("\033[29~", ESC_STR "[29~")}, /* Select */
|
|
855 {K_F17, IF_EB("\033[31~", ESC_STR "[31~")},
|
|
856 {K_F18, IF_EB("\033[32~", ESC_STR "[32~")},
|
|
857 {K_F19, IF_EB("\033[33~", ESC_STR "[33~")},
|
|
858 {K_F20, IF_EB("\033[34~", ESC_STR "[34~")},
|
|
859 {K_INS, IF_EB("\033[2~", ESC_STR "[2~")},
|
|
860 {K_DEL, IF_EB("\033[3~", ESC_STR "[3~")},
|
|
861 {K_HOME, IF_EB("\033[1~", ESC_STR "[1~")},
|
|
862 {K_END, IF_EB("\033[4~", ESC_STR "[4~")},
|
|
863 {K_PAGEUP, IF_EB("\033[5~", ESC_STR "[5~")},
|
|
864 {K_PAGEDOWN, IF_EB("\033[6~", ESC_STR "[6~")},
|
|
865 {K_KPLUS, IF_EB("\033Ok", ESC_STR "Ok")}, /* keypad plus */
|
|
866 {K_KMINUS, IF_EB("\033Om", ESC_STR "Om")}, /* keypad minus */
|
|
867 {K_KDIVIDE, IF_EB("\033Oo", ESC_STR "Oo")}, /* keypad / */
|
|
868 {K_KMULTIPLY, IF_EB("\033Oj", ESC_STR "Oj")}, /* keypad * */
|
|
869 {K_KENTER, IF_EB("\033OM", ESC_STR "OM")}, /* keypad Enter */
|
|
870 {K_BS, "\x7f"}, /* for some reason 0177 doesn't work */
|
|
871 # endif
|
|
872
|
|
873 # if defined(ALL_BUILTIN_TCAPS) || defined(__MINT__)
|
|
874 /*
|
|
875 * Ordinary vt52
|
|
876 */
|
|
877 {(int)KS_NAME, "vt52"},
|
|
878 {(int)KS_CE, IF_EB("\033K", ESC_STR "K")},
|
|
879 {(int)KS_CD, IF_EB("\033J", ESC_STR "J")},
|
|
880 {(int)KS_CM, IF_EB("\033Y%+ %+ ", ESC_STR "Y%+ %+ ")},
|
|
881 {(int)KS_LE, "\b"},
|
|
882 # ifdef __MINT__
|
|
883 {(int)KS_AL, IF_EB("\033L", ESC_STR "L")},
|
|
884 {(int)KS_DL, IF_EB("\033M", ESC_STR "M")},
|
|
885 {(int)KS_CL, IF_EB("\033E", ESC_STR "E")},
|
|
886 {(int)KS_SR, IF_EB("\033I", ESC_STR "I")},
|
|
887 {(int)KS_VE, IF_EB("\033e", ESC_STR "e")},
|
|
888 {(int)KS_VI, IF_EB("\033f", ESC_STR "f")},
|
|
889 {(int)KS_SO, IF_EB("\033p", ESC_STR "p")},
|
|
890 {(int)KS_SE, IF_EB("\033q", ESC_STR "q")},
|
|
891 {K_UP, IF_EB("\033A", ESC_STR "A")},
|
|
892 {K_DOWN, IF_EB("\033B", ESC_STR "B")},
|
|
893 {K_LEFT, IF_EB("\033D", ESC_STR "D")},
|
|
894 {K_RIGHT, IF_EB("\033C", ESC_STR "C")},
|
|
895 {K_S_UP, IF_EB("\033a", ESC_STR "a")},
|
|
896 {K_S_DOWN, IF_EB("\033b", ESC_STR "b")},
|
|
897 {K_S_LEFT, IF_EB("\033d", ESC_STR "d")},
|
|
898 {K_S_RIGHT, IF_EB("\033c", ESC_STR "c")},
|
|
899 {K_F1, IF_EB("\033P", ESC_STR "P")},
|
|
900 {K_F2, IF_EB("\033Q", ESC_STR "Q")},
|
|
901 {K_F3, IF_EB("\033R", ESC_STR "R")},
|
|
902 {K_F4, IF_EB("\033S", ESC_STR "S")},
|
|
903 {K_F5, IF_EB("\033T", ESC_STR "T")},
|
|
904 {K_F6, IF_EB("\033U", ESC_STR "U")},
|
|
905 {K_F7, IF_EB("\033V", ESC_STR "V")},
|
|
906 {K_F8, IF_EB("\033W", ESC_STR "W")},
|
|
907 {K_F9, IF_EB("\033X", ESC_STR "X")},
|
|
908 {K_F10, IF_EB("\033Y", ESC_STR "Y")},
|
|
909 {K_S_F1, IF_EB("\033p", ESC_STR "p")},
|
|
910 {K_S_F2, IF_EB("\033q", ESC_STR "q")},
|
|
911 {K_S_F3, IF_EB("\033r", ESC_STR "r")},
|
|
912 {K_S_F4, IF_EB("\033s", ESC_STR "s")},
|
|
913 {K_S_F5, IF_EB("\033t", ESC_STR "t")},
|
|
914 {K_S_F6, IF_EB("\033u", ESC_STR "u")},
|
|
915 {K_S_F7, IF_EB("\033v", ESC_STR "v")},
|
|
916 {K_S_F8, IF_EB("\033w", ESC_STR "w")},
|
|
917 {K_S_F9, IF_EB("\033x", ESC_STR "x")},
|
|
918 {K_S_F10, IF_EB("\033y", ESC_STR "y")},
|
|
919 {K_INS, IF_EB("\033I", ESC_STR "I")},
|
|
920 {K_HOME, IF_EB("\033E", ESC_STR "E")},
|
|
921 {K_PAGEDOWN, IF_EB("\033b", ESC_STR "b")},
|
|
922 {K_PAGEUP, IF_EB("\033a", ESC_STR "a")},
|
|
923 # else
|
|
924 {(int)KS_AL, IF_EB("\033T", ESC_STR "T")},
|
|
925 {(int)KS_DL, IF_EB("\033U", ESC_STR "U")},
|
|
926 {(int)KS_CL, IF_EB("\033H\033J", ESC_STR "H" ESC_STR_nc "J")},
|
|
927 {(int)KS_ME, IF_EB("\033SO", ESC_STR "SO")},
|
|
928 {(int)KS_MR, IF_EB("\033S2", ESC_STR "S2")},
|
|
929 {(int)KS_MS, "y"},
|
|
930 # endif
|
|
931 # endif
|
|
932
|
|
933 # if defined(UNIX) || defined(ALL_BUILTIN_TCAPS) || defined(SOME_BUILTIN_TCAPS) || defined(__EMX__)
|
|
934 {(int)KS_NAME, "xterm"},
|
|
935 {(int)KS_CE, IF_EB("\033[K", ESC_STR "[K")},
|
|
936 {(int)KS_AL, IF_EB("\033[L", ESC_STR "[L")},
|
|
937 # ifdef TERMINFO
|
|
938 {(int)KS_CAL, IF_EB("\033[%p1%dL", ESC_STR "[%p1%dL")},
|
|
939 # else
|
|
940 {(int)KS_CAL, IF_EB("\033[%dL", ESC_STR "[%dL")},
|
|
941 # endif
|
|
942 {(int)KS_DL, IF_EB("\033[M", ESC_STR "[M")},
|
|
943 # ifdef TERMINFO
|
|
944 {(int)KS_CDL, IF_EB("\033[%p1%dM", ESC_STR "[%p1%dM")},
|
|
945 # else
|
|
946 {(int)KS_CDL, IF_EB("\033[%dM", ESC_STR "[%dM")},
|
|
947 # endif
|
|
948 # ifdef TERMINFO
|
|
949 {(int)KS_CS, IF_EB("\033[%i%p1%d;%p2%dr",
|
|
950 ESC_STR "[%i%p1%d;%p2%dr")},
|
|
951 # else
|
|
952 {(int)KS_CS, IF_EB("\033[%i%d;%dr", ESC_STR "[%i%d;%dr")},
|
|
953 # endif
|
|
954 {(int)KS_CL, IF_EB("\033[H\033[2J", ESC_STR "[H" ESC_STR_nc "[2J")},
|
|
955 {(int)KS_CD, IF_EB("\033[J", ESC_STR "[J")},
|
|
956 {(int)KS_ME, IF_EB("\033[m", ESC_STR "[m")},
|
|
957 {(int)KS_MR, IF_EB("\033[7m", ESC_STR "[7m")},
|
|
958 {(int)KS_MD, IF_EB("\033[1m", ESC_STR "[1m")},
|
|
959 {(int)KS_UE, IF_EB("\033[m", ESC_STR "[m")},
|
|
960 {(int)KS_US, IF_EB("\033[4m", ESC_STR "[4m")},
|
|
961 {(int)KS_MS, "y"},
|
|
962 {(int)KS_UT, "y"},
|
|
963 {(int)KS_LE, "\b"},
|
|
964 # ifdef TERMINFO
|
|
965 {(int)KS_CM, IF_EB("\033[%i%p1%d;%p2%dH",
|
|
966 ESC_STR "[%i%p1%d;%p2%dH")},
|
|
967 # else
|
|
968 {(int)KS_CM, IF_EB("\033[%i%d;%dH", ESC_STR "[%i%d;%dH")},
|
|
969 # endif
|
|
970 {(int)KS_SR, IF_EB("\033M", ESC_STR "M")},
|
|
971 # ifdef TERMINFO
|
|
972 {(int)KS_CRI, IF_EB("\033[%p1%dC", ESC_STR "[%p1%dC")},
|
|
973 # else
|
|
974 {(int)KS_CRI, IF_EB("\033[%dC", ESC_STR "[%dC")},
|
|
975 # endif
|
|
976 {(int)KS_KS, IF_EB("\033[?1h\033=", ESC_STR "[?1h" ESC_STR_nc "=")},
|
|
977 {(int)KS_KE, IF_EB("\033[?1l\033>", ESC_STR "[?1l" ESC_STR_nc ">")},
|
|
978 # ifdef FEAT_XTERM_SAVE
|
|
979 {(int)KS_TI, IF_EB("\0337\033[?47h", ESC_STR "7" ESC_STR_nc "[?47h")},
|
|
980 {(int)KS_TE, IF_EB("\033[2J\033[?47l\0338",
|
|
981 ESC_STR "[2J" ESC_STR_nc "[?47l" ESC_STR_nc "8")},
|
|
982 # endif
|
|
983 {(int)KS_CIS, IF_EB("\033]1;", ESC_STR "]1;")},
|
|
984 {(int)KS_CIE, "\007"},
|
|
985 {(int)KS_TS, IF_EB("\033]2;", ESC_STR "]2;")},
|
|
986 {(int)KS_FS, "\007"},
|
|
987 # ifdef TERMINFO
|
|
988 {(int)KS_CWS, IF_EB("\033[8;%p1%d;%p2%dt",
|
|
989 ESC_STR "[8;%p1%d;%p2%dt")},
|
|
990 {(int)KS_CWP, IF_EB("\033[3;%p1%d;%p2%dt",
|
|
991 ESC_STR "[3;%p1%d;%p2%dt")},
|
|
992 # else
|
|
993 {(int)KS_CWS, IF_EB("\033[8;%d;%dt", ESC_STR "[8;%d;%dt")},
|
|
994 {(int)KS_CWP, IF_EB("\033[3;%d;%dt", ESC_STR "[3;%d;%dt")},
|
|
995 # endif
|
|
996 {(int)KS_CRV, IF_EB("\033[>c", ESC_STR "[>c")},
|
180
|
997
|
|
998 {K_UP, IF_EB("\033O*A", ESC_STR "O*A")},
|
|
999 {K_DOWN, IF_EB("\033O*B", ESC_STR "O*B")},
|
|
1000 {K_RIGHT, IF_EB("\033O*C", ESC_STR "O*C")},
|
|
1001 {K_LEFT, IF_EB("\033O*D", ESC_STR "O*D")},
|
|
1002 /* An extra set of cursor keys for vt100 mode */
|
|
1003 {K_XUP, IF_EB("\033[1;*A", ESC_STR "[1;*A")},
|
|
1004 {K_XDOWN, IF_EB("\033[1;*B", ESC_STR "[1;*B")},
|
|
1005 {K_XRIGHT, IF_EB("\033[1;*C", ESC_STR "[1;*C")},
|
|
1006 {K_XLEFT, IF_EB("\033[1;*D", ESC_STR "[1;*D")},
|
7
|
1007 /* An extra set of function keys for vt100 mode */
|
180
|
1008 {K_XF1, IF_EB("\033O*P", ESC_STR "O*P")},
|
|
1009 {K_XF2, IF_EB("\033O*Q", ESC_STR "O*Q")},
|
|
1010 {K_XF3, IF_EB("\033O*R", ESC_STR "O*R")},
|
|
1011 {K_XF4, IF_EB("\033O*S", ESC_STR "O*S")},
|
179
|
1012 {K_F1, IF_EB("\033[11;*~", ESC_STR "[11;*~")},
|
|
1013 {K_F2, IF_EB("\033[12;*~", ESC_STR "[12;*~")},
|
|
1014 {K_F3, IF_EB("\033[13;*~", ESC_STR "[13;*~")},
|
|
1015 {K_F4, IF_EB("\033[14;*~", ESC_STR "[14;*~")},
|
|
1016 {K_F5, IF_EB("\033[15;*~", ESC_STR "[15;*~")},
|
|
1017 {K_F6, IF_EB("\033[17;*~", ESC_STR "[17;*~")},
|
|
1018 {K_F7, IF_EB("\033[18;*~", ESC_STR "[18;*~")},
|
|
1019 {K_F8, IF_EB("\033[19;*~", ESC_STR "[19;*~")},
|
|
1020 {K_F9, IF_EB("\033[20;*~", ESC_STR "[20;*~")},
|
|
1021 {K_F10, IF_EB("\033[21;*~", ESC_STR "[21;*~")},
|
|
1022 {K_F11, IF_EB("\033[23;*~", ESC_STR "[23;*~")},
|
|
1023 {K_F12, IF_EB("\033[24;*~", ESC_STR "[24;*~")},
|
7
|
1024 {K_S_TAB, IF_EB("\033[Z", ESC_STR "[Z")},
|
179
|
1025 {K_HELP, IF_EB("\033[28;*~", ESC_STR "[28;*~")},
|
|
1026 {K_UNDO, IF_EB("\033[26;*~", ESC_STR "[26;*~")},
|
|
1027 {K_INS, IF_EB("\033[2;*~", ESC_STR "[2;*~")},
|
|
1028 {K_HOME, IF_EB("\033[1;*H", ESC_STR "[1;*H")},
|
180
|
1029 /* {K_S_HOME, IF_EB("\033O2H", ESC_STR "O2H")}, */
|
|
1030 /* {K_C_HOME, IF_EB("\033O5H", ESC_STR "O5H")}, */
|
179
|
1031 {K_KHOME, IF_EB("\033[7;*~", ESC_STR "[7;*~")},
|
180
|
1032 {K_XHOME, IF_EB("\033O*H", ESC_STR "O*H")}, /* other Home */
|
179
|
1033 {K_END, IF_EB("\033[1;*F", ESC_STR "[1;*F")},
|
180
|
1034 /* {K_S_END, IF_EB("\033O2F", ESC_STR "O2F")}, */
|
|
1035 /* {K_C_END, IF_EB("\033O5F", ESC_STR "O5F")}, */
|
179
|
1036 {K_KEND, IF_EB("\033[4;*~", ESC_STR "[4;*~")},
|
180
|
1037 {K_XEND, IF_EB("\033O*F", ESC_STR "O*F")}, /* other End */
|
179
|
1038 {K_PAGEUP, IF_EB("\033[5;*~", ESC_STR "[5;*~")},
|
|
1039 {K_PAGEDOWN, IF_EB("\033[6;*~", ESC_STR "[6;*~")},
|
180
|
1040 {K_KPLUS, IF_EB("\033O*k", ESC_STR "O*k")}, /* keypad plus */
|
|
1041 {K_KMINUS, IF_EB("\033O*m", ESC_STR "O*m")}, /* keypad minus */
|
|
1042 {K_KDIVIDE, IF_EB("\033O*o", ESC_STR "O*o")}, /* keypad / */
|
|
1043 {K_KMULTIPLY, IF_EB("\033O*j", ESC_STR "O*j")}, /* keypad * */
|
|
1044 {K_KENTER, IF_EB("\033O*M", ESC_STR "O*M")}, /* keypad Enter */
|
|
1045 {K_KPOINT, IF_EB("\033O*n", ESC_STR "O*n")}, /* keypad . */
|
179
|
1046 {K_KDEL, IF_EB("\033[3;*~", ESC_STR "[3;*~")}, /* keypad Del */
|
7
|
1047
|
|
1048 {BT_EXTRA_KEYS, ""},
|
179
|
1049 {TERMCAP2KEY('k', '0'), IF_EB("\033[10;*~", ESC_STR "[10;*~")}, /* F0 */
|
|
1050 {TERMCAP2KEY('F', '3'), IF_EB("\033[25;*~", ESC_STR "[25;*~")}, /* F13 */
|
|
1051 /* F14 and F15 are missing, because they send the same codes as the undo
|
|
1052 * and help key, although they don't work on all keyboards. */
|
|
1053 {TERMCAP2KEY('F', '6'), IF_EB("\033[29;*~", ESC_STR "[29;*~")}, /* F16 */
|
|
1054 {TERMCAP2KEY('F', '7'), IF_EB("\033[31;*~", ESC_STR "[31;*~")}, /* F17 */
|
|
1055 {TERMCAP2KEY('F', '8'), IF_EB("\033[32;*~", ESC_STR "[32;*~")}, /* F18 */
|
|
1056 {TERMCAP2KEY('F', '9'), IF_EB("\033[33;*~", ESC_STR "[33;*~")}, /* F19 */
|
|
1057 {TERMCAP2KEY('F', 'A'), IF_EB("\033[34;*~", ESC_STR "[34;*~")}, /* F20 */
|
|
1058
|
|
1059 {TERMCAP2KEY('F', 'B'), IF_EB("\033[42;*~", ESC_STR "[42;*~")}, /* F21 */
|
|
1060 {TERMCAP2KEY('F', 'C'), IF_EB("\033[43;*~", ESC_STR "[43;*~")}, /* F22 */
|
|
1061 {TERMCAP2KEY('F', 'D'), IF_EB("\033[44;*~", ESC_STR "[44;*~")}, /* F23 */
|
|
1062 {TERMCAP2KEY('F', 'E'), IF_EB("\033[45;*~", ESC_STR "[45;*~")}, /* F24 */
|
|
1063 {TERMCAP2KEY('F', 'F'), IF_EB("\033[46;*~", ESC_STR "[46;*~")}, /* F25 */
|
|
1064 {TERMCAP2KEY('F', 'G'), IF_EB("\033[47;*~", ESC_STR "[47;*~")}, /* F26 */
|
|
1065 {TERMCAP2KEY('F', 'H'), IF_EB("\033[48;*~", ESC_STR "[48;*~")}, /* F27 */
|
|
1066 {TERMCAP2KEY('F', 'I'), IF_EB("\033[49;*~", ESC_STR "[49;*~")}, /* F28 */
|
|
1067 {TERMCAP2KEY('F', 'J'), IF_EB("\033[50;*~", ESC_STR "[50;*~")}, /* F29 */
|
|
1068 {TERMCAP2KEY('F', 'K'), IF_EB("\033[51;*~", ESC_STR "[51;*~")}, /* F30 */
|
|
1069
|
|
1070 {TERMCAP2KEY('F', 'L'), IF_EB("\033[52;*~", ESC_STR "[52;*~")}, /* F31 */
|
|
1071 {TERMCAP2KEY('F', 'M'), IF_EB("\033[53;*~", ESC_STR "[53;*~")}, /* F32 */
|
|
1072 {TERMCAP2KEY('F', 'N'), IF_EB("\033[54;*~", ESC_STR "[54;*~")}, /* F33 */
|
|
1073 {TERMCAP2KEY('F', 'O'), IF_EB("\033[55;*~", ESC_STR "[55;*~")}, /* F34 */
|
|
1074 {TERMCAP2KEY('F', 'P'), IF_EB("\033[56;*~", ESC_STR "[56;*~")}, /* F35 */
|
|
1075 {TERMCAP2KEY('F', 'Q'), IF_EB("\033[57;*~", ESC_STR "[57;*~")}, /* F36 */
|
|
1076 {TERMCAP2KEY('F', 'R'), IF_EB("\033[58;*~", ESC_STR "[58;*~")}, /* F37 */
|
7
|
1077 # endif
|
|
1078
|
|
1079 # if defined(UNIX) || defined(ALL_BUILTIN_TCAPS)
|
|
1080 /*
|
|
1081 * iris-ansi for Silicon Graphics machines.
|
|
1082 */
|
|
1083 {(int)KS_NAME, "iris-ansi"},
|
|
1084 {(int)KS_CE, "\033[K"},
|
|
1085 {(int)KS_CD, "\033[J"},
|
|
1086 {(int)KS_AL, "\033[L"},
|
|
1087 # ifdef TERMINFO
|
|
1088 {(int)KS_CAL, "\033[%p1%dL"},
|
|
1089 # else
|
|
1090 {(int)KS_CAL, "\033[%dL"},
|
|
1091 # endif
|
|
1092 {(int)KS_DL, "\033[M"},
|
|
1093 # ifdef TERMINFO
|
|
1094 {(int)KS_CDL, "\033[%p1%dM"},
|
|
1095 # else
|
|
1096 {(int)KS_CDL, "\033[%dM"},
|
|
1097 # endif
|
|
1098 #if 0 /* The scroll region is not working as Vim expects. */
|
|
1099 # ifdef TERMINFO
|
|
1100 {(int)KS_CS, "\033[%i%p1%d;%p2%dr"},
|
|
1101 # else
|
|
1102 {(int)KS_CS, "\033[%i%d;%dr"},
|
|
1103 # endif
|
|
1104 #endif
|
|
1105 {(int)KS_CL, "\033[H\033[2J"},
|
|
1106 {(int)KS_VE, "\033[9/y\033[12/y"}, /* These aren't documented */
|
|
1107 {(int)KS_VS, "\033[10/y\033[=1h\033[=2l"}, /* These aren't documented */
|
|
1108 {(int)KS_TI, "\033[=6h"},
|
|
1109 {(int)KS_TE, "\033[=6l"},
|
|
1110 {(int)KS_SE, "\033[21;27m"},
|
|
1111 {(int)KS_SO, "\033[1;7m"},
|
|
1112 {(int)KS_ME, "\033[m"},
|
|
1113 {(int)KS_MR, "\033[7m"},
|
|
1114 {(int)KS_MD, "\033[1m"},
|
|
1115 {(int)KS_CCO, "8"}, /* allow 8 colors */
|
|
1116 {(int)KS_CZH, "\033[3m"}, /* italic mode on */
|
|
1117 {(int)KS_CZR, "\033[23m"}, /* italic mode off */
|
|
1118 {(int)KS_US, "\033[4m"}, /* underline on */
|
|
1119 {(int)KS_UE, "\033[24m"}, /* underline off */
|
|
1120 # ifdef TERMINFO
|
|
1121 {(int)KS_CAB, "\033[4%p1%dm"}, /* set background color (ANSI) */
|
|
1122 {(int)KS_CAF, "\033[3%p1%dm"}, /* set foreground color (ANSI) */
|
|
1123 {(int)KS_CSB, "\033[102;%p1%dm"}, /* set screen background color */
|
|
1124 {(int)KS_CSF, "\033[101;%p1%dm"}, /* set screen foreground color */
|
|
1125 # else
|
|
1126 {(int)KS_CAB, "\033[4%dm"}, /* set background color (ANSI) */
|
|
1127 {(int)KS_CAF, "\033[3%dm"}, /* set foreground color (ANSI) */
|
|
1128 {(int)KS_CSB, "\033[102;%dm"}, /* set screen background color */
|
|
1129 {(int)KS_CSF, "\033[101;%dm"}, /* set screen foreground color */
|
|
1130 # endif
|
|
1131 {(int)KS_MS, "y"}, /* guessed */
|
|
1132 {(int)KS_UT, "y"}, /* guessed */
|
|
1133 {(int)KS_LE, "\b"},
|
|
1134 # ifdef TERMINFO
|
|
1135 {(int)KS_CM, "\033[%i%p1%d;%p2%dH"},
|
|
1136 # else
|
|
1137 {(int)KS_CM, "\033[%i%d;%dH"},
|
|
1138 # endif
|
|
1139 {(int)KS_SR, "\033M"},
|
|
1140 # ifdef TERMINFO
|
|
1141 {(int)KS_CRI, "\033[%p1%dC"},
|
|
1142 # else
|
|
1143 {(int)KS_CRI, "\033[%dC"},
|
|
1144 # endif
|
|
1145 {(int)KS_CIS, "\033P3.y"},
|
|
1146 {(int)KS_CIE, "\234"}, /* ST "String Terminator" */
|
|
1147 {(int)KS_TS, "\033P1.y"},
|
|
1148 {(int)KS_FS, "\234"}, /* ST "String Terminator" */
|
|
1149 # ifdef TERMINFO
|
|
1150 {(int)KS_CWS, "\033[203;%p1%d;%p2%d/y"},
|
|
1151 {(int)KS_CWP, "\033[205;%p1%d;%p2%d/y"},
|
|
1152 # else
|
|
1153 {(int)KS_CWS, "\033[203;%d;%d/y"},
|
|
1154 {(int)KS_CWP, "\033[205;%d;%d/y"},
|
|
1155 # endif
|
|
1156 {K_UP, "\033[A"},
|
|
1157 {K_DOWN, "\033[B"},
|
|
1158 {K_LEFT, "\033[D"},
|
|
1159 {K_RIGHT, "\033[C"},
|
|
1160 {K_S_UP, "\033[161q"},
|
|
1161 {K_S_DOWN, "\033[164q"},
|
|
1162 {K_S_LEFT, "\033[158q"},
|
|
1163 {K_S_RIGHT, "\033[167q"},
|
|
1164 {K_F1, "\033[001q"},
|
|
1165 {K_F2, "\033[002q"},
|
|
1166 {K_F3, "\033[003q"},
|
|
1167 {K_F4, "\033[004q"},
|
|
1168 {K_F5, "\033[005q"},
|
|
1169 {K_F6, "\033[006q"},
|
|
1170 {K_F7, "\033[007q"},
|
|
1171 {K_F8, "\033[008q"},
|
|
1172 {K_F9, "\033[009q"},
|
|
1173 {K_F10, "\033[010q"},
|
|
1174 {K_F11, "\033[011q"},
|
|
1175 {K_F12, "\033[012q"},
|
|
1176 {K_S_F1, "\033[013q"},
|
|
1177 {K_S_F2, "\033[014q"},
|
|
1178 {K_S_F3, "\033[015q"},
|
|
1179 {K_S_F4, "\033[016q"},
|
|
1180 {K_S_F5, "\033[017q"},
|
|
1181 {K_S_F6, "\033[018q"},
|
|
1182 {K_S_F7, "\033[019q"},
|
|
1183 {K_S_F8, "\033[020q"},
|
|
1184 {K_S_F9, "\033[021q"},
|
|
1185 {K_S_F10, "\033[022q"},
|
|
1186 {K_S_F11, "\033[023q"},
|
|
1187 {K_S_F12, "\033[024q"},
|
|
1188 {K_INS, "\033[139q"},
|
|
1189 {K_HOME, "\033[H"},
|
|
1190 {K_END, "\033[146q"},
|
|
1191 {K_PAGEUP, "\033[150q"},
|
|
1192 {K_PAGEDOWN, "\033[154q"},
|
|
1193 # endif
|
|
1194
|
|
1195 # if defined(DEBUG) || defined(ALL_BUILTIN_TCAPS)
|
|
1196 /*
|
|
1197 * for debugging
|
|
1198 */
|
|
1199 {(int)KS_NAME, "debug"},
|
|
1200 {(int)KS_CE, "[CE]"},
|
|
1201 {(int)KS_CD, "[CD]"},
|
|
1202 {(int)KS_AL, "[AL]"},
|
|
1203 # ifdef TERMINFO
|
|
1204 {(int)KS_CAL, "[CAL%p1%d]"},
|
|
1205 # else
|
|
1206 {(int)KS_CAL, "[CAL%d]"},
|
|
1207 # endif
|
|
1208 {(int)KS_DL, "[DL]"},
|
|
1209 # ifdef TERMINFO
|
|
1210 {(int)KS_CDL, "[CDL%p1%d]"},
|
|
1211 # else
|
|
1212 {(int)KS_CDL, "[CDL%d]"},
|
|
1213 # endif
|
|
1214 # ifdef TERMINFO
|
|
1215 {(int)KS_CS, "[%p1%dCS%p2%d]"},
|
|
1216 # else
|
|
1217 {(int)KS_CS, "[%dCS%d]"},
|
|
1218 # endif
|
|
1219 # ifdef FEAT_VERTSPLIT
|
|
1220 # ifdef TERMINFO
|
|
1221 {(int)KS_CSV, "[%p1%dCSV%p2%d]"},
|
|
1222 # else
|
|
1223 {(int)KS_CSV, "[%dCSV%d]"},
|
|
1224 # endif
|
|
1225 # endif
|
|
1226 # ifdef TERMINFO
|
|
1227 {(int)KS_CAB, "[CAB%p1%d]"},
|
|
1228 {(int)KS_CAF, "[CAF%p1%d]"},
|
|
1229 {(int)KS_CSB, "[CSB%p1%d]"},
|
|
1230 {(int)KS_CSF, "[CSF%p1%d]"},
|
|
1231 # else
|
|
1232 {(int)KS_CAB, "[CAB%d]"},
|
|
1233 {(int)KS_CAF, "[CAF%d]"},
|
|
1234 {(int)KS_CSB, "[CSB%d]"},
|
|
1235 {(int)KS_CSF, "[CSF%d]"},
|
|
1236 # endif
|
|
1237 {(int)KS_OP, "[OP]"},
|
|
1238 {(int)KS_LE, "[LE]"},
|
|
1239 {(int)KS_CL, "[CL]"},
|
|
1240 {(int)KS_VI, "[VI]"},
|
|
1241 {(int)KS_VE, "[VE]"},
|
|
1242 {(int)KS_VS, "[VS]"},
|
|
1243 {(int)KS_ME, "[ME]"},
|
|
1244 {(int)KS_MR, "[MR]"},
|
|
1245 {(int)KS_MB, "[MB]"},
|
|
1246 {(int)KS_MD, "[MD]"},
|
|
1247 {(int)KS_SE, "[SE]"},
|
|
1248 {(int)KS_SO, "[SO]"},
|
|
1249 {(int)KS_UE, "[UE]"},
|
|
1250 {(int)KS_US, "[US]"},
|
|
1251 {(int)KS_MS, "[MS]"},
|
|
1252 {(int)KS_UT, "[UT]"},
|
|
1253 # ifdef TERMINFO
|
|
1254 {(int)KS_CM, "[%p1%dCM%p2%d]"},
|
|
1255 # else
|
|
1256 {(int)KS_CM, "[%dCM%d]"},
|
|
1257 # endif
|
|
1258 {(int)KS_SR, "[SR]"},
|
|
1259 # ifdef TERMINFO
|
|
1260 {(int)KS_CRI, "[CRI%p1%d]"},
|
|
1261 # else
|
|
1262 {(int)KS_CRI, "[CRI%d]"},
|
|
1263 # endif
|
|
1264 {(int)KS_VB, "[VB]"},
|
|
1265 {(int)KS_KS, "[KS]"},
|
|
1266 {(int)KS_KE, "[KE]"},
|
|
1267 {(int)KS_TI, "[TI]"},
|
|
1268 {(int)KS_TE, "[TE]"},
|
|
1269 {(int)KS_CIS, "[CIS]"},
|
|
1270 {(int)KS_CIE, "[CIE]"},
|
|
1271 {(int)KS_TS, "[TS]"},
|
|
1272 {(int)KS_FS, "[FS]"},
|
|
1273 # ifdef TERMINFO
|
|
1274 {(int)KS_CWS, "[%p1%dCWS%p2%d]"},
|
|
1275 {(int)KS_CWP, "[%p1%dCWP%p2%d]"},
|
|
1276 # else
|
|
1277 {(int)KS_CWS, "[%dCWS%d]"},
|
|
1278 {(int)KS_CWP, "[%dCWP%d]"},
|
|
1279 # endif
|
|
1280 {(int)KS_CRV, "[CRV]"},
|
|
1281 {K_UP, "[KU]"},
|
|
1282 {K_DOWN, "[KD]"},
|
|
1283 {K_LEFT, "[KL]"},
|
|
1284 {K_RIGHT, "[KR]"},
|
180
|
1285 {K_XUP, "[xKU]"},
|
|
1286 {K_XDOWN, "[xKD]"},
|
|
1287 {K_XLEFT, "[xKL]"},
|
|
1288 {K_XRIGHT, "[xKR]"},
|
7
|
1289 {K_S_UP, "[S-KU]"},
|
|
1290 {K_S_DOWN, "[S-KD]"},
|
|
1291 {K_S_LEFT, "[S-KL]"},
|
|
1292 {K_C_LEFT, "[C-KL]"},
|
|
1293 {K_S_RIGHT, "[S-KR]"},
|
|
1294 {K_C_RIGHT, "[C-KR]"},
|
|
1295 {K_F1, "[F1]"},
|
|
1296 {K_XF1, "[xF1]"},
|
|
1297 {K_F2, "[F2]"},
|
|
1298 {K_XF2, "[xF2]"},
|
|
1299 {K_F3, "[F3]"},
|
|
1300 {K_XF3, "[xF3]"},
|
|
1301 {K_F4, "[F4]"},
|
|
1302 {K_XF4, "[xF4]"},
|
|
1303 {K_F5, "[F5]"},
|
|
1304 {K_F6, "[F6]"},
|
|
1305 {K_F7, "[F7]"},
|
|
1306 {K_F8, "[F8]"},
|
|
1307 {K_F9, "[F9]"},
|
|
1308 {K_F10, "[F10]"},
|
|
1309 {K_F11, "[F11]"},
|
|
1310 {K_F12, "[F12]"},
|
|
1311 {K_S_F1, "[S-F1]"},
|
|
1312 {K_S_XF1, "[S-xF1]"},
|
|
1313 {K_S_F2, "[S-F2]"},
|
|
1314 {K_S_XF2, "[S-xF2]"},
|
|
1315 {K_S_F3, "[S-F3]"},
|
|
1316 {K_S_XF3, "[S-xF3]"},
|
|
1317 {K_S_F4, "[S-F4]"},
|
|
1318 {K_S_XF4, "[S-xF4]"},
|
|
1319 {K_S_F5, "[S-F5]"},
|
|
1320 {K_S_F6, "[S-F6]"},
|
|
1321 {K_S_F7, "[S-F7]"},
|
|
1322 {K_S_F8, "[S-F8]"},
|
|
1323 {K_S_F9, "[S-F9]"},
|
|
1324 {K_S_F10, "[S-F10]"},
|
|
1325 {K_S_F11, "[S-F11]"},
|
|
1326 {K_S_F12, "[S-F12]"},
|
|
1327 {K_HELP, "[HELP]"},
|
|
1328 {K_UNDO, "[UNDO]"},
|
|
1329 {K_BS, "[BS]"},
|
|
1330 {K_INS, "[INS]"},
|
|
1331 {K_KINS, "[KINS]"},
|
|
1332 {K_DEL, "[DEL]"},
|
|
1333 {K_KDEL, "[KDEL]"},
|
|
1334 {K_HOME, "[HOME]"},
|
|
1335 {K_S_HOME, "[C-HOME]"},
|
|
1336 {K_C_HOME, "[C-HOME]"},
|
|
1337 {K_KHOME, "[KHOME]"},
|
|
1338 {K_XHOME, "[XHOME]"},
|
|
1339 {K_END, "[END]"},
|
|
1340 {K_S_END, "[C-END]"},
|
|
1341 {K_C_END, "[C-END]"},
|
|
1342 {K_KEND, "[KEND]"},
|
|
1343 {K_XEND, "[XEND]"},
|
|
1344 {K_PAGEUP, "[PAGEUP]"},
|
|
1345 {K_PAGEDOWN, "[PAGEDOWN]"},
|
|
1346 {K_KPAGEUP, "[KPAGEUP]"},
|
|
1347 {K_KPAGEDOWN, "[KPAGEDOWN]"},
|
|
1348 {K_MOUSE, "[MOUSE]"},
|
|
1349 {K_KPLUS, "[KPLUS]"},
|
|
1350 {K_KMINUS, "[KMINUS]"},
|
|
1351 {K_KDIVIDE, "[KDIVIDE]"},
|
|
1352 {K_KMULTIPLY, "[KMULTIPLY]"},
|
|
1353 {K_KENTER, "[KENTER]"},
|
|
1354 {K_KPOINT, "[KPOINT]"},
|
|
1355 {K_K0, "[K0]"},
|
|
1356 {K_K1, "[K1]"},
|
|
1357 {K_K2, "[K2]"},
|
|
1358 {K_K3, "[K3]"},
|
|
1359 {K_K4, "[K4]"},
|
|
1360 {K_K5, "[K5]"},
|
|
1361 {K_K6, "[K6]"},
|
|
1362 {K_K7, "[K7]"},
|
|
1363 {K_K8, "[K8]"},
|
|
1364 {K_K9, "[K9]"},
|
|
1365 # endif
|
|
1366
|
|
1367 #endif /* NO_BUILTIN_TCAPS */
|
|
1368
|
|
1369 /*
|
|
1370 * The most minimal terminal: only clear screen and cursor positioning
|
|
1371 * Always included.
|
|
1372 */
|
|
1373 {(int)KS_NAME, "dumb"},
|
|
1374 {(int)KS_CL, "\014"},
|
|
1375 #ifdef TERMINFO
|
|
1376 {(int)KS_CM, IF_EB("\033[%i%p1%d;%p2%dH",
|
|
1377 ESC_STR "[%i%p1%d;%p2%dH")},
|
|
1378 #else
|
|
1379 {(int)KS_CM, IF_EB("\033[%i%d;%dH", ESC_STR "[%i%d;%dH")},
|
|
1380 #endif
|
|
1381
|
|
1382 /*
|
|
1383 * end marker
|
|
1384 */
|
|
1385 {(int)KS_NAME, NULL}
|
|
1386
|
|
1387 }; /* end of builtin_termcaps */
|
|
1388
|
|
1389 /*
|
|
1390 * DEFAULT_TERM is used, when no terminal is specified with -T option or $TERM.
|
|
1391 */
|
|
1392 #ifdef RISCOS
|
|
1393 # define DEFAULT_TERM (char_u *)"riscos"
|
|
1394 #endif
|
|
1395
|
|
1396 #ifdef AMIGA
|
|
1397 # define DEFAULT_TERM (char_u *)"amiga"
|
|
1398 #endif
|
|
1399
|
|
1400 #ifdef MSWIN
|
|
1401 # define DEFAULT_TERM (char_u *)"win32"
|
|
1402 #endif
|
|
1403
|
|
1404 #ifdef MSDOS
|
|
1405 # define DEFAULT_TERM (char_u *)"pcterm"
|
|
1406 #endif
|
|
1407
|
|
1408 #if defined(UNIX) && !defined(__MINT__)
|
|
1409 # define DEFAULT_TERM (char_u *)"ansi"
|
|
1410 #endif
|
|
1411
|
|
1412 #ifdef __MINT__
|
|
1413 # define DEFAULT_TERM (char_u *)"vt52"
|
|
1414 #endif
|
|
1415
|
|
1416 #ifdef __EMX__
|
|
1417 # define DEFAULT_TERM (char_u *)"os2ansi"
|
|
1418 #endif
|
|
1419
|
|
1420 #ifdef VMS
|
|
1421 # define DEFAULT_TERM (char_u *)"vt320"
|
|
1422 #endif
|
|
1423
|
|
1424 #ifdef __BEOS__
|
|
1425 # undef DEFAULT_TERM
|
|
1426 # define DEFAULT_TERM (char_u *)"beos-ansi"
|
|
1427 #endif
|
|
1428
|
|
1429 #ifndef DEFAULT_TERM
|
|
1430 # define DEFAULT_TERM (char_u *)"dumb"
|
|
1431 #endif
|
|
1432
|
|
1433 /*
|
|
1434 * Term_strings contains currently used terminal output strings.
|
|
1435 * It is initialized with the default values by parse_builtin_tcap().
|
|
1436 * The values can be changed by setting the option with the same name.
|
|
1437 */
|
|
1438 char_u *(term_strings[(int)KS_LAST + 1]);
|
|
1439
|
|
1440 static int need_gather = FALSE; /* need to fill termleader[] */
|
|
1441 static char_u termleader[256 + 1]; /* for check_termcode() */
|
|
1442 #ifdef FEAT_TERMRESPONSE
|
|
1443 static int check_for_codes = FALSE; /* check for key code reponse */
|
|
1444 #endif
|
|
1445
|
|
1446 static struct builtin_term *
|
|
1447 find_builtin_term(term)
|
|
1448 char_u *term;
|
|
1449 {
|
|
1450 struct builtin_term *p;
|
|
1451
|
|
1452 p = builtin_termcaps;
|
|
1453 while (p->bt_string != NULL)
|
|
1454 {
|
|
1455 if (p->bt_entry == (int)KS_NAME)
|
|
1456 {
|
|
1457 #ifdef UNIX
|
|
1458 if (STRCMP(p->bt_string, "iris-ansi") == 0 && vim_is_iris(term))
|
|
1459 return p;
|
|
1460 else if (STRCMP(p->bt_string, "xterm") == 0 && vim_is_xterm(term))
|
|
1461 return p;
|
|
1462 else
|
|
1463 #endif
|
|
1464 #ifdef VMS
|
|
1465 if (STRCMP(p->bt_string, "vt320") == 0 && vim_is_vt300(term))
|
|
1466 return p;
|
|
1467 else
|
|
1468 #endif
|
|
1469 if (STRCMP(term, p->bt_string) == 0)
|
|
1470 return p;
|
|
1471 }
|
|
1472 ++p;
|
|
1473 }
|
|
1474 return p;
|
|
1475 }
|
|
1476
|
|
1477 /*
|
|
1478 * Parsing of the builtin termcap entries.
|
|
1479 * Caller should check if 'name' is a valid builtin term.
|
|
1480 * The terminal's name is not set, as this is already done in termcapinit().
|
|
1481 */
|
|
1482 static void
|
|
1483 parse_builtin_tcap(term)
|
|
1484 char_u *term;
|
|
1485 {
|
|
1486 struct builtin_term *p;
|
|
1487 char_u name[2];
|
|
1488 int term_8bit;
|
|
1489
|
|
1490 p = find_builtin_term(term);
|
|
1491 term_8bit = term_is_8bit(term);
|
|
1492
|
|
1493 /* Do not parse if builtin term not found */
|
|
1494 if (p->bt_string == NULL)
|
|
1495 return;
|
|
1496
|
|
1497 for (++p; p->bt_entry != (int)KS_NAME && p->bt_entry != BT_EXTRA_KEYS; ++p)
|
|
1498 {
|
|
1499 if ((int)p->bt_entry >= 0) /* KS_xx entry */
|
|
1500 {
|
|
1501 /* Only set the value if it wasn't set yet. */
|
|
1502 if (term_strings[p->bt_entry] == NULL
|
|
1503 || term_strings[p->bt_entry] == empty_option)
|
|
1504 {
|
|
1505 /* 8bit terminal: use CSI instead of <Esc>[ */
|
|
1506 if (term_8bit && term_7to8bit((char_u *)p->bt_string) != 0)
|
|
1507 {
|
|
1508 char_u *s, *t;
|
|
1509
|
|
1510 s = vim_strsave((char_u *)p->bt_string);
|
|
1511 if (s != NULL)
|
|
1512 {
|
|
1513 for (t = s; *t; ++t)
|
|
1514 if (term_7to8bit(t))
|
|
1515 {
|
|
1516 *t = term_7to8bit(t);
|
|
1517 STRCPY(t + 1, t + 2);
|
|
1518 }
|
|
1519 term_strings[p->bt_entry] = s;
|
|
1520 set_term_option_alloced(&term_strings[p->bt_entry]);
|
|
1521 }
|
|
1522 }
|
|
1523 else
|
|
1524 term_strings[p->bt_entry] = (char_u *)p->bt_string;
|
|
1525 }
|
|
1526 }
|
|
1527 else
|
|
1528 {
|
|
1529 name[0] = KEY2TERMCAP0((int)p->bt_entry);
|
|
1530 name[1] = KEY2TERMCAP1((int)p->bt_entry);
|
|
1531 if (find_termcode(name) == NULL)
|
|
1532 add_termcode(name, (char_u *)p->bt_string, term_8bit);
|
|
1533 }
|
|
1534 }
|
|
1535 }
|
|
1536 #if defined(HAVE_TGETENT) || defined(FEAT_TERMRESPONSE)
|
|
1537 static void set_color_count __ARGS((int nr));
|
|
1538
|
|
1539 /*
|
|
1540 * Set number of colors.
|
|
1541 * Store it as a number in t_colors.
|
|
1542 * Store it as a string in T_CCO (using nr_colors[]).
|
|
1543 */
|
|
1544 static void
|
|
1545 set_color_count(nr)
|
|
1546 int nr;
|
|
1547 {
|
|
1548 char_u nr_colors[20]; /* string for number of colors */
|
|
1549
|
|
1550 t_colors = nr;
|
|
1551 if (t_colors > 1)
|
|
1552 sprintf((char *)nr_colors, "%d", t_colors);
|
|
1553 else
|
|
1554 *nr_colors = NUL;
|
|
1555 set_string_option_direct((char_u *)"t_Co", -1, nr_colors, OPT_FREE);
|
|
1556 }
|
|
1557 #endif
|
|
1558
|
|
1559 #ifdef HAVE_TGETENT
|
|
1560 static char *(key_names[]) =
|
|
1561 {
|
|
1562 #ifdef FEAT_TERMRESPONSE
|
|
1563 /* Do this one first, it may cause a screen redraw. */
|
|
1564 "Co",
|
|
1565 #endif
|
|
1566 "ku", "kd", "kr", "kl",
|
|
1567 # ifdef ARCHIE
|
|
1568 "su", "sd", /* Termcap code made up! */
|
|
1569 # endif
|
|
1570 "#2", "#4", "%i", "*7",
|
|
1571 "k1", "k2", "k3", "k4", "k5", "k6",
|
|
1572 "k7", "k8", "k9", "k;", "F1", "F2",
|
|
1573 "%1", "&8", "kb", "kI", "kD", "kh",
|
|
1574 "@7", "kP", "kN", "K1", "K3", "K4", "K5", "kB",
|
|
1575 NULL
|
|
1576 };
|
|
1577 #endif
|
|
1578
|
|
1579 /*
|
|
1580 * Set terminal options for terminal "term".
|
|
1581 * Return OK if terminal 'term' was found in a termcap, FAIL otherwise.
|
|
1582 *
|
|
1583 * While doing this, until ttest(), some options may be NULL, be careful.
|
|
1584 */
|
|
1585 int
|
|
1586 set_termname(term)
|
|
1587 char_u *term;
|
|
1588 {
|
|
1589 struct builtin_term *termp;
|
|
1590 #ifdef HAVE_TGETENT
|
|
1591 int builtin_first = p_tbi;
|
|
1592 int try;
|
|
1593 int termcap_cleared = FALSE;
|
|
1594 #endif
|
|
1595 int width = 0, height = 0;
|
|
1596 char_u *error_msg = NULL;
|
|
1597 char_u *bs_p, *del_p;
|
|
1598
|
168
|
1599 /* In silect mode (ex -s) we don't use the 'term' option. */
|
|
1600 if (silent_mode)
|
|
1601 return OK;
|
|
1602
|
7
|
1603 detected_8bit = FALSE; /* reset 8-bit detection */
|
|
1604
|
|
1605 if (term_is_builtin(term))
|
|
1606 {
|
|
1607 term += 8;
|
|
1608 #ifdef HAVE_TGETENT
|
|
1609 builtin_first = 1;
|
|
1610 #endif
|
|
1611 }
|
|
1612
|
|
1613 /*
|
|
1614 * If HAVE_TGETENT is not defined, only the builtin termcap is used, otherwise:
|
|
1615 * If builtin_first is TRUE:
|
|
1616 * 0. try builtin termcap
|
|
1617 * 1. try external termcap
|
|
1618 * 2. if both fail default to a builtin terminal
|
|
1619 * If builtin_first is FALSE:
|
|
1620 * 1. try external termcap
|
|
1621 * 2. try builtin termcap, if both fail default to a builtin terminal
|
|
1622 */
|
|
1623 #ifdef HAVE_TGETENT
|
|
1624 for (try = builtin_first ? 0 : 1; try < 3; ++try)
|
|
1625 {
|
|
1626 /*
|
|
1627 * Use external termcap
|
|
1628 */
|
|
1629 if (try == 1)
|
|
1630 {
|
|
1631 char_u *p;
|
|
1632 static char_u tstrbuf[TBUFSZ];
|
|
1633 int i;
|
|
1634 char_u tbuf[TBUFSZ];
|
|
1635 char_u *tp;
|
|
1636 static struct {
|
|
1637 enum SpecialKey dest; /* index in term_strings[] */
|
|
1638 char *name; /* termcap name for string */
|
|
1639 } string_names[] =
|
|
1640 { {KS_CE, "ce"}, {KS_AL, "al"}, {KS_CAL,"AL"},
|
|
1641 {KS_DL, "dl"}, {KS_CDL,"DL"}, {KS_CS, "cs"},
|
|
1642 {KS_CL, "cl"}, {KS_CD, "cd"},
|
|
1643 {KS_VI, "vi"}, {KS_VE, "ve"}, {KS_MB, "mb"},
|
|
1644 {KS_VS, "vs"}, {KS_ME, "me"}, {KS_MR, "mr"},
|
|
1645 {KS_MD, "md"}, {KS_SE, "se"}, {KS_SO, "so"},
|
|
1646 {KS_CZH,"ZH"}, {KS_CZR,"ZR"}, {KS_UE, "ue"},
|
|
1647 {KS_US, "us"}, {KS_CM, "cm"}, {KS_SR, "sr"},
|
|
1648 {KS_CRI,"RI"}, {KS_VB, "vb"}, {KS_KS, "ks"},
|
|
1649 {KS_KE, "ke"}, {KS_TI, "ti"}, {KS_TE, "te"},
|
|
1650 {KS_BC, "bc"}, {KS_CSB,"Sb"}, {KS_CSF,"Sf"},
|
|
1651 {KS_CAB,"AB"}, {KS_CAF,"AF"}, {KS_LE, "le"},
|
|
1652 {KS_ND, "nd"}, {KS_OP, "op"}, {KS_CRV, "RV"},
|
|
1653 {KS_CIS, "IS"}, {KS_CIE, "IE"},
|
|
1654 {KS_TS, "ts"}, {KS_FS, "fs"},
|
|
1655 {KS_CWP, "WP"}, {KS_CWS, "WS"},
|
36
|
1656 {KS_CSI, "SI"}, {KS_CEI, "EI"},
|
7
|
1657 {(enum SpecialKey)0, NULL}
|
|
1658 };
|
|
1659
|
|
1660 /*
|
|
1661 * If the external termcap does not have a matching entry, try the
|
|
1662 * builtin ones.
|
|
1663 */
|
|
1664 if ((error_msg = tgetent_error(tbuf, term)) == NULL)
|
|
1665 {
|
|
1666 tp = tstrbuf;
|
|
1667 if (!termcap_cleared)
|
|
1668 {
|
|
1669 clear_termoptions(); /* clear old options */
|
|
1670 termcap_cleared = TRUE;
|
|
1671 }
|
|
1672
|
|
1673 /* get output strings */
|
|
1674 for (i = 0; string_names[i].name != NULL; ++i)
|
|
1675 {
|
|
1676 if (term_str(string_names[i].dest) == NULL
|
|
1677 || term_str(string_names[i].dest) == empty_option)
|
|
1678 term_str(string_names[i].dest) =
|
|
1679 TGETSTR(string_names[i].name, &tp);
|
|
1680 }
|
|
1681
|
|
1682 /* tgetflag() returns 1 if the flag is present, 0 if not and
|
|
1683 * possibly -1 if the flag doesn't exist. */
|
|
1684 if ((T_MS == NULL || T_MS == empty_option)
|
|
1685 && tgetflag("ms") > 0)
|
|
1686 T_MS = (char_u *)"y";
|
|
1687 if ((T_XS == NULL || T_XS == empty_option)
|
|
1688 && tgetflag("xs") > 0)
|
|
1689 T_XS = (char_u *)"y";
|
|
1690 if ((T_DB == NULL || T_DB == empty_option)
|
|
1691 && tgetflag("db") > 0)
|
|
1692 T_DB = (char_u *)"y";
|
|
1693 if ((T_DA == NULL || T_DA == empty_option)
|
|
1694 && tgetflag("da") > 0)
|
|
1695 T_DA = (char_u *)"y";
|
|
1696 if ((T_UT == NULL || T_UT == empty_option)
|
|
1697 && tgetflag("ut") > 0)
|
|
1698 T_UT = (char_u *)"y";
|
|
1699
|
|
1700
|
|
1701 /*
|
|
1702 * get key codes
|
|
1703 */
|
|
1704 for (i = 0; key_names[i] != NULL; ++i)
|
|
1705 {
|
|
1706 if (find_termcode((char_u *)key_names[i]) == NULL)
|
|
1707 {
|
|
1708 p = TGETSTR(key_names[i], &tp);
|
|
1709 /* if cursor-left == backspace, ignore it (televideo
|
|
1710 * 925) */
|
|
1711 if (p != NULL
|
|
1712 && (*p != Ctrl_H
|
|
1713 || key_names[i][0] != 'k'
|
|
1714 || key_names[i][1] != 'l'))
|
|
1715 add_termcode((char_u *)key_names[i], p, FALSE);
|
|
1716 }
|
|
1717 }
|
|
1718
|
|
1719 if (height == 0)
|
|
1720 height = tgetnum("li");
|
|
1721 if (width == 0)
|
|
1722 width = tgetnum("co");
|
|
1723
|
|
1724 /*
|
|
1725 * Get number of colors (if not done already).
|
|
1726 */
|
|
1727 if (term_str(KS_CCO) == NULL
|
|
1728 || term_str(KS_CCO) == empty_option)
|
|
1729 set_color_count(tgetnum("Co"));
|
|
1730
|
|
1731 # ifndef hpux
|
|
1732 BC = (char *)TGETSTR("bc", &tp);
|
|
1733 UP = (char *)TGETSTR("up", &tp);
|
|
1734 p = TGETSTR("pc", &tp);
|
|
1735 if (p)
|
|
1736 PC = *p;
|
|
1737 # endif /* hpux */
|
|
1738 }
|
|
1739 }
|
|
1740 else /* try == 0 || try == 2 */
|
|
1741 #endif /* HAVE_TGETENT */
|
|
1742 /*
|
|
1743 * Use builtin termcap
|
|
1744 */
|
|
1745 {
|
|
1746 #ifdef HAVE_TGETENT
|
|
1747 /*
|
|
1748 * If builtin termcap was already used, there is no need to search
|
|
1749 * for the builtin termcap again, quit now.
|
|
1750 */
|
|
1751 if (try == 2 && builtin_first && termcap_cleared)
|
|
1752 break;
|
|
1753 #endif
|
|
1754 /*
|
|
1755 * search for 'term' in builtin_termcaps[]
|
|
1756 */
|
|
1757 termp = find_builtin_term(term);
|
|
1758 if (termp->bt_string == NULL) /* did not find it */
|
|
1759 {
|
|
1760 #ifdef HAVE_TGETENT
|
|
1761 /*
|
|
1762 * If try == 0, first try the external termcap. If that is not
|
|
1763 * found we'll get back here with try == 2.
|
|
1764 * If termcap_cleared is set we used the external termcap,
|
|
1765 * don't complain about not finding the term in the builtin
|
|
1766 * termcap.
|
|
1767 */
|
|
1768 if (try == 0) /* try external one */
|
|
1769 continue;
|
|
1770 if (termcap_cleared) /* found in external termcap */
|
|
1771 break;
|
|
1772 #endif
|
|
1773
|
|
1774 mch_errmsg("\r\n");
|
|
1775 if (error_msg != NULL)
|
|
1776 {
|
|
1777 mch_errmsg((char *)error_msg);
|
|
1778 mch_errmsg("\r\n");
|
|
1779 }
|
|
1780 mch_errmsg("'");
|
|
1781 mch_errmsg((char *)term);
|
|
1782 mch_errmsg(_("' not known. Available builtin terminals are:"));
|
|
1783 mch_errmsg("\r\n");
|
|
1784 for (termp = &(builtin_termcaps[0]); termp->bt_string != NULL;
|
|
1785 ++termp)
|
|
1786 {
|
|
1787 if (termp->bt_entry == (int)KS_NAME)
|
|
1788 {
|
|
1789 #ifdef HAVE_TGETENT
|
|
1790 mch_errmsg(" builtin_");
|
|
1791 #else
|
|
1792 mch_errmsg(" ");
|
|
1793 #endif
|
|
1794 mch_errmsg(termp->bt_string);
|
|
1795 mch_errmsg("\r\n");
|
|
1796 }
|
|
1797 }
|
|
1798 /* when user typed :set term=xxx, quit here */
|
|
1799 if (starting != NO_SCREEN)
|
|
1800 {
|
|
1801 screen_start(); /* don't know where cursor is now */
|
|
1802 wait_return(TRUE);
|
|
1803 return FAIL;
|
|
1804 }
|
|
1805 term = DEFAULT_TERM;
|
|
1806 mch_errmsg(_("defaulting to '"));
|
|
1807 mch_errmsg((char *)term);
|
|
1808 mch_errmsg("'\r\n");
|
|
1809 if (emsg_silent == 0)
|
|
1810 {
|
|
1811 screen_start(); /* don't know where cursor is now */
|
|
1812 out_flush();
|
|
1813 ui_delay(2000L, TRUE);
|
|
1814 }
|
|
1815 set_string_option_direct((char_u *)"term", -1, term, OPT_FREE);
|
|
1816 display_errors();
|
|
1817 }
|
|
1818 out_flush();
|
|
1819 #ifdef HAVE_TGETENT
|
|
1820 if (!termcap_cleared)
|
|
1821 {
|
|
1822 #endif
|
|
1823 clear_termoptions(); /* clear old options */
|
|
1824 #ifdef HAVE_TGETENT
|
|
1825 termcap_cleared = TRUE;
|
|
1826 }
|
|
1827 #endif
|
|
1828 parse_builtin_tcap(term);
|
|
1829 #ifdef FEAT_GUI
|
|
1830 if (term_is_gui(term))
|
|
1831 {
|
|
1832 out_flush();
|
|
1833 gui_init();
|
|
1834 /* If starting the GUI failed, don't do any of the other
|
|
1835 * things for this terminal */
|
|
1836 if (!gui.in_use)
|
|
1837 return FAIL;
|
|
1838 #ifdef HAVE_TGETENT
|
|
1839 break; /* don't try using external termcap */
|
|
1840 #endif
|
|
1841 }
|
|
1842 #endif /* FEAT_GUI */
|
|
1843 }
|
|
1844 #ifdef HAVE_TGETENT
|
|
1845 }
|
|
1846 #endif
|
|
1847
|
|
1848 /*
|
|
1849 * special: There is no info in the termcap about whether the cursor
|
|
1850 * positioning is relative to the start of the screen or to the start of the
|
|
1851 * scrolling region. We just guess here. Only msdos pcterm is known to do it
|
|
1852 * relative.
|
|
1853 */
|
|
1854 if (STRCMP(term, "pcterm") == 0)
|
|
1855 T_CCS = (char_u *)"yes";
|
|
1856 else
|
|
1857 T_CCS = empty_option;
|
|
1858
|
|
1859 #ifdef UNIX
|
|
1860 /*
|
|
1861 * Any "stty" settings override the default for t_kb from the termcap.
|
|
1862 * This is in os_unix.c, because it depends a lot on the version of unix that
|
|
1863 * is being used.
|
|
1864 * Don't do this when the GUI is active, it uses "t_kb" and "t_kD" directly.
|
|
1865 */
|
|
1866 #ifdef FEAT_GUI
|
|
1867 if (!gui.in_use)
|
|
1868 #endif
|
|
1869 get_stty();
|
|
1870 #endif
|
|
1871
|
|
1872 /*
|
|
1873 * If the termcap has no entry for 'bs' and/or 'del' and the ioctl() also
|
|
1874 * didn't work, use the default CTRL-H
|
|
1875 * The default for t_kD is DEL, unless t_kb is DEL.
|
|
1876 * The vim_strsave'd strings are probably lost forever, well it's only two
|
|
1877 * bytes. Don't do this when the GUI is active, it uses "t_kb" and "t_kD"
|
|
1878 * directly.
|
|
1879 */
|
|
1880 #ifdef FEAT_GUI
|
|
1881 if (!gui.in_use)
|
|
1882 #endif
|
|
1883 {
|
|
1884 bs_p = find_termcode((char_u *)"kb");
|
|
1885 del_p = find_termcode((char_u *)"kD");
|
|
1886 if (bs_p == NULL || *bs_p == NUL)
|
|
1887 add_termcode((char_u *)"kb", (bs_p = (char_u *)CTRL_H_STR), FALSE);
|
|
1888 if ((del_p == NULL || *del_p == NUL) &&
|
|
1889 (bs_p == NULL || *bs_p != DEL))
|
|
1890 add_termcode((char_u *)"kD", (char_u *)DEL_STR, FALSE);
|
|
1891 }
|
|
1892
|
|
1893 #if defined(UNIX) || defined(VMS)
|
|
1894 term_is_xterm = vim_is_xterm(term);
|
|
1895 #endif
|
|
1896
|
|
1897 #ifdef FEAT_MOUSE
|
|
1898 # if defined(UNIX) || defined(VMS)
|
|
1899 # ifdef FEAT_MOUSE_TTY
|
|
1900 /*
|
|
1901 * For Unix, set the 'ttymouse' option to the type of mouse to be used.
|
|
1902 * The termcode for the mouse is added as a side effect in option.c.
|
|
1903 */
|
|
1904 {
|
|
1905 char_u *p;
|
|
1906
|
|
1907 p = (char_u *)"";
|
|
1908 # ifdef FEAT_MOUSE_XTERM
|
|
1909 # ifdef FEAT_CLIPBOARD
|
|
1910 # ifdef FEAT_GUI
|
|
1911 if (!gui.in_use)
|
|
1912 # endif
|
|
1913 clip_init(FALSE);
|
|
1914 # endif
|
|
1915 if (term_is_xterm)
|
|
1916 {
|
|
1917 if (use_xterm_mouse())
|
|
1918 p = NULL; /* keep existing value, might be "xterm2" */
|
|
1919 else
|
|
1920 p = (char_u *)"xterm";
|
|
1921 }
|
|
1922 # endif
|
|
1923 if (p != NULL)
|
|
1924 set_option_value((char_u *)"ttym", 0L, p, 0);
|
|
1925 if (p == NULL
|
|
1926 # ifdef FEAT_GUI
|
|
1927 || gui.in_use
|
|
1928 # endif
|
|
1929 )
|
|
1930 check_mouse_termcode(); /* set mouse termcode anyway */
|
|
1931 }
|
|
1932 # endif
|
|
1933 # else
|
|
1934 set_mouse_termcode(KS_MOUSE, (char_u *)"\233M");
|
|
1935 # endif
|
|
1936 #endif /* FEAT_MOUSE */
|
|
1937
|
|
1938 #ifdef FEAT_SNIFF
|
|
1939 {
|
|
1940 char_u name[2];
|
|
1941
|
|
1942 name[0] = (int)KS_EXTRA;
|
|
1943 name[1] = (int)KE_SNIFF;
|
|
1944 add_termcode(name, (char_u *)"\233sniff", FALSE);
|
|
1945 }
|
|
1946 #endif
|
|
1947
|
|
1948 #ifdef USE_TERM_CONSOLE
|
|
1949 /* DEFAULT_TERM indicates that it is the machine console. */
|
|
1950 if (STRCMP(term, DEFAULT_TERM) != 0)
|
|
1951 term_console = FALSE;
|
|
1952 else
|
|
1953 {
|
|
1954 term_console = TRUE;
|
|
1955 # ifdef AMIGA
|
|
1956 win_resize_on(); /* enable window resizing reports */
|
|
1957 # endif
|
|
1958 }
|
|
1959 #endif
|
|
1960
|
|
1961 #if defined(UNIX) || defined(VMS)
|
|
1962 /*
|
|
1963 * 'ttyfast' is default on for xterm, iris-ansi and a few others.
|
|
1964 */
|
|
1965 if (vim_is_fastterm(term))
|
|
1966 p_tf = TRUE;
|
|
1967 #endif
|
|
1968 #ifdef USE_TERM_CONSOLE
|
|
1969 /*
|
|
1970 * 'ttyfast' is default on consoles
|
|
1971 */
|
|
1972 if (term_console)
|
|
1973 p_tf = TRUE;
|
|
1974 #endif
|
|
1975
|
|
1976 ttest(TRUE); /* make sure we have a valid set of terminal codes */
|
|
1977
|
|
1978 full_screen = TRUE; /* we can use termcap codes from now on */
|
|
1979 set_term_defaults(); /* use current values as defaults */
|
|
1980 #ifdef FEAT_TERMRESPONSE
|
|
1981 crv_status = CRV_GET; /* Get terminal version later */
|
|
1982 #endif
|
|
1983
|
|
1984 /*
|
|
1985 * Initialize the terminal with the appropriate termcap codes.
|
|
1986 * Set the mouse and window title if possible.
|
|
1987 * Don't do this when starting, need to parse the .vimrc first, because it
|
|
1988 * may redefine t_TI etc.
|
|
1989 */
|
|
1990 if (starting != NO_SCREEN)
|
|
1991 {
|
|
1992 starttermcap(); /* may change terminal mode */
|
|
1993 #ifdef FEAT_MOUSE
|
|
1994 setmouse(); /* may start using the mouse */
|
|
1995 #endif
|
|
1996 #ifdef FEAT_TITLE
|
|
1997 maketitle(); /* may display window title */
|
|
1998 #endif
|
|
1999 }
|
|
2000
|
|
2001 /* display initial screen after ttest() checking. jw. */
|
|
2002 if (width <= 0 || height <= 0)
|
|
2003 {
|
|
2004 /* termcap failed to report size */
|
|
2005 /* set defaults, in case ui_get_shellsize() also fails */
|
|
2006 width = 80;
|
|
2007 #if defined(MSDOS) || defined(WIN3264)
|
|
2008 height = 25; /* console is often 25 lines */
|
|
2009 #else
|
|
2010 height = 24; /* most terminals are 24 lines */
|
|
2011 #endif
|
|
2012 }
|
|
2013 set_shellsize(width, height, FALSE); /* may change Rows */
|
|
2014 if (starting != NO_SCREEN)
|
|
2015 {
|
|
2016 if (scroll_region)
|
|
2017 scroll_region_reset(); /* In case Rows changed */
|
|
2018 check_map_keycodes(); /* check mappings for terminal codes used */
|
|
2019
|
|
2020 #ifdef FEAT_AUTOCMD
|
|
2021 {
|
|
2022 buf_T *old_curbuf;
|
|
2023
|
|
2024 /*
|
|
2025 * Execute the TermChanged autocommands for each buffer that is
|
|
2026 * loaded.
|
|
2027 */
|
|
2028 old_curbuf = curbuf;
|
|
2029 for (curbuf = firstbuf; curbuf != NULL; curbuf = curbuf->b_next)
|
|
2030 {
|
|
2031 if (curbuf->b_ml.ml_mfp != NULL)
|
|
2032 apply_autocmds(EVENT_TERMCHANGED, NULL, NULL, FALSE,
|
|
2033 curbuf);
|
|
2034 }
|
|
2035 if (buf_valid(old_curbuf))
|
|
2036 curbuf = old_curbuf;
|
|
2037 }
|
|
2038 #endif
|
|
2039 }
|
|
2040
|
|
2041 #ifdef FEAT_TERMRESPONSE
|
|
2042 may_req_termresponse();
|
|
2043 #endif
|
|
2044
|
|
2045 return OK;
|
|
2046 }
|
|
2047
|
|
2048 #if defined(FEAT_MOUSE) || defined(PROTO)
|
|
2049
|
|
2050 # ifdef FEAT_MOUSE_TTY
|
|
2051 # define HMT_NORMAL 1
|
|
2052 # define HMT_NETTERM 2
|
|
2053 # define HMT_DEC 4
|
|
2054 # define HMT_JSBTERM 8
|
|
2055 # define HMT_PTERM 16
|
|
2056 static int has_mouse_termcode = 0;
|
|
2057 # endif
|
|
2058
|
|
2059 # if (!defined(UNIX) || defined(FEAT_MOUSE_XTERM) || defined(FEAT_MOUSE_NET) \
|
|
2060 || defined(FEAT_MOUSE_DEC)) || defined(FEAT_MOUSE_JSB) \
|
|
2061 || defined(FEAT_MOUSE_PTERM) || defined(PROTO)
|
|
2062 void
|
|
2063 set_mouse_termcode(n, s)
|
|
2064 int n; /* KS_MOUSE, KS_NETTERM_MOUSE or KS_DEC_MOUSE */
|
|
2065 char_u *s;
|
|
2066 {
|
|
2067 char_u name[2];
|
|
2068
|
|
2069 name[0] = n;
|
|
2070 name[1] = KE_FILLER;
|
|
2071 add_termcode(name, s, FALSE);
|
|
2072 # ifdef FEAT_MOUSE_TTY
|
|
2073 # ifdef FEAT_MOUSE_JSB
|
|
2074 if (n == KS_JSBTERM_MOUSE)
|
|
2075 has_mouse_termcode |= HMT_JSBTERM;
|
|
2076 else
|
|
2077 # endif
|
|
2078 # ifdef FEAT_MOUSE_NET
|
|
2079 if (n == KS_NETTERM_MOUSE)
|
|
2080 has_mouse_termcode |= HMT_NETTERM;
|
|
2081 else
|
|
2082 # endif
|
|
2083 # ifdef FEAT_MOUSE_DEC
|
|
2084 if (n == KS_DEC_MOUSE)
|
|
2085 has_mouse_termcode |= HMT_DEC;
|
|
2086 else
|
|
2087 # endif
|
|
2088 # ifdef FEAT_MOUSE_PTERM
|
|
2089 if (n == KS_PTERM_MOUSE)
|
|
2090 has_mouse_termcode |= HMT_PTERM;
|
|
2091 else
|
|
2092 # endif
|
|
2093 has_mouse_termcode |= HMT_NORMAL;
|
|
2094 # endif
|
|
2095 }
|
|
2096 # endif
|
|
2097
|
|
2098 # if ((defined(UNIX) || defined(VMS) || defined(OS2)) \
|
|
2099 && (defined(FEAT_MOUSE_XTERM) || defined(FEAT_MOUSE_DEC) \
|
|
2100 || defined(FEAT_MOUSE_GPM) || defined(FEAT_MOUSE_PTERM))) \
|
|
2101 || defined(PROTO)
|
|
2102 void
|
|
2103 del_mouse_termcode(n)
|
|
2104 int n; /* KS_MOUSE, KS_NETTERM_MOUSE or KS_DEC_MOUSE */
|
|
2105 {
|
|
2106 char_u name[2];
|
|
2107
|
|
2108 name[0] = n;
|
|
2109 name[1] = KE_FILLER;
|
|
2110 del_termcode(name);
|
|
2111 # ifdef FEAT_MOUSE_TTY
|
|
2112 # ifdef FEAT_MOUSE_JSB
|
|
2113 if (n == KS_JSBTERM_MOUSE)
|
|
2114 has_mouse_termcode &= ~HMT_JSBTERM;
|
|
2115 else
|
|
2116 # endif
|
|
2117 # ifdef FEAT_MOUSE_NET
|
|
2118 if (n == KS_NETTERM_MOUSE)
|
|
2119 has_mouse_termcode &= ~HMT_NETTERM;
|
|
2120 else
|
|
2121 # endif
|
|
2122 # ifdef FEAT_MOUSE_DEC
|
|
2123 if (n == KS_DEC_MOUSE)
|
|
2124 has_mouse_termcode &= ~HMT_DEC;
|
|
2125 else
|
|
2126 # endif
|
|
2127 # ifdef FEAT_MOUSE_PTERM
|
|
2128 if (n == KS_PTERM_MOUSE)
|
|
2129 has_mouse_termcode &= ~HMT_PTERM;
|
|
2130 else
|
|
2131 # endif
|
|
2132 has_mouse_termcode &= ~HMT_NORMAL;
|
|
2133 # endif
|
|
2134 }
|
|
2135 # endif
|
|
2136 #endif
|
|
2137
|
|
2138 #ifdef HAVE_TGETENT
|
|
2139 /*
|
|
2140 * Call tgetent()
|
|
2141 * Return error message if it fails, NULL if it's OK.
|
|
2142 */
|
|
2143 static char_u *
|
|
2144 tgetent_error(tbuf, term)
|
|
2145 char_u *tbuf;
|
|
2146 char_u *term;
|
|
2147 {
|
|
2148 int i;
|
|
2149
|
|
2150 i = TGETENT(tbuf, term);
|
|
2151 if (i < 0 /* -1 is always an error */
|
|
2152 # ifdef TGETENT_ZERO_ERR
|
|
2153 || i == 0 /* sometimes zero is also an error */
|
|
2154 # endif
|
|
2155 )
|
|
2156 {
|
|
2157 /* On FreeBSD tputs() gets a SEGV after a tgetent() which fails. Call
|
|
2158 * tgetent() with the always existing "dumb" entry to avoid a crash or
|
|
2159 * hang. */
|
|
2160 (void)TGETENT(tbuf, "dumb");
|
|
2161
|
|
2162 if (i < 0)
|
|
2163 # ifdef TGETENT_ZERO_ERR
|
|
2164 return (char_u *)_("E557: Cannot open termcap file");
|
|
2165 if (i == 0)
|
|
2166 # endif
|
|
2167 #ifdef TERMINFO
|
|
2168 return (char_u *)_("E558: Terminal entry not found in terminfo");
|
|
2169 #else
|
|
2170 return (char_u *)_("E559: Terminal entry not found in termcap");
|
|
2171 #endif
|
|
2172 }
|
|
2173 return NULL;
|
|
2174 }
|
|
2175
|
|
2176 /*
|
|
2177 * Some versions of tgetstr() have been reported to return -1 instead of NULL.
|
|
2178 * Fix that here.
|
|
2179 */
|
|
2180 static char_u *
|
|
2181 vim_tgetstr(s, pp)
|
|
2182 char *s;
|
|
2183 char_u **pp;
|
|
2184 {
|
|
2185 char *p;
|
|
2186
|
|
2187 p = tgetstr(s, (char **)pp);
|
|
2188 if (p == (char *)-1)
|
|
2189 p = NULL;
|
|
2190 return (char_u *)p;
|
|
2191 }
|
|
2192 #endif /* HAVE_TGETENT */
|
|
2193
|
|
2194 #if defined(HAVE_TGETENT) && (defined(UNIX) || defined(__EMX__) || defined(VMS) || defined(MACOS_X))
|
|
2195 /*
|
|
2196 * Get Columns and Rows from the termcap. Used after a window signal if the
|
|
2197 * ioctl() fails. It doesn't make sense to call tgetent each time if the "co"
|
|
2198 * and "li" entries never change. But on some systems this works.
|
|
2199 * Errors while getting the entries are ignored.
|
|
2200 */
|
|
2201 void
|
|
2202 getlinecol(cp, rp)
|
|
2203 long *cp; /* pointer to columns */
|
|
2204 long *rp; /* pointer to rows */
|
|
2205 {
|
|
2206 char_u tbuf[TBUFSZ];
|
|
2207
|
|
2208 if (T_NAME != NULL && *T_NAME != NUL && tgetent_error(tbuf, T_NAME) == NULL)
|
|
2209 {
|
|
2210 if (*cp == 0)
|
|
2211 *cp = tgetnum("co");
|
|
2212 if (*rp == 0)
|
|
2213 *rp = tgetnum("li");
|
|
2214 }
|
|
2215 }
|
|
2216 #endif /* defined(HAVE_TGETENT) && defined(UNIX) */
|
|
2217
|
|
2218 /*
|
|
2219 * Get a string entry from the termcap and add it to the list of termcodes.
|
|
2220 * Used for <t_xx> special keys.
|
|
2221 * Give an error message for failure when not sourcing.
|
|
2222 * If force given, replace an existing entry.
|
|
2223 * Return FAIL if the entry was not found, OK if the entry was added.
|
|
2224 */
|
|
2225 int
|
|
2226 add_termcap_entry(name, force)
|
|
2227 char_u *name;
|
|
2228 int force;
|
|
2229 {
|
|
2230 char_u *term;
|
|
2231 int key;
|
|
2232 struct builtin_term *termp;
|
|
2233 #ifdef HAVE_TGETENT
|
|
2234 char_u *string;
|
|
2235 int i;
|
|
2236 int builtin_first;
|
|
2237 char_u tbuf[TBUFSZ];
|
|
2238 char_u tstrbuf[TBUFSZ];
|
|
2239 char_u *tp = tstrbuf;
|
|
2240 char_u *error_msg = NULL;
|
|
2241 #endif
|
|
2242
|
|
2243 /*
|
|
2244 * If the GUI is running or will start in a moment, we only support the keys
|
|
2245 * that the GUI can produce.
|
|
2246 */
|
|
2247 #ifdef FEAT_GUI
|
|
2248 if (gui.in_use || gui.starting)
|
|
2249 return gui_mch_haskey(name);
|
|
2250 #endif
|
|
2251
|
|
2252 if (!force && find_termcode(name) != NULL) /* it's already there */
|
|
2253 return OK;
|
|
2254
|
|
2255 term = T_NAME;
|
|
2256 if (term == NULL || *term == NUL) /* 'term' not defined yet */
|
|
2257 return FAIL;
|
|
2258
|
|
2259 if (term_is_builtin(term)) /* name starts with "builtin_" */
|
|
2260 {
|
|
2261 term += 8;
|
|
2262 #ifdef HAVE_TGETENT
|
|
2263 builtin_first = TRUE;
|
|
2264 #endif
|
|
2265 }
|
|
2266 #ifdef HAVE_TGETENT
|
|
2267 else
|
|
2268 builtin_first = p_tbi;
|
|
2269 #endif
|
|
2270
|
|
2271 #ifdef HAVE_TGETENT
|
|
2272 /*
|
|
2273 * We can get the entry from the builtin termcap and from the external one.
|
|
2274 * If 'ttybuiltin' is on or the terminal name starts with "builtin_", try
|
|
2275 * builtin termcap first.
|
|
2276 * If 'ttybuiltin' is off, try external termcap first.
|
|
2277 */
|
|
2278 for (i = 0; i < 2; ++i)
|
|
2279 {
|
|
2280 if (!builtin_first == i)
|
|
2281 #endif
|
|
2282 /*
|
|
2283 * Search in builtin termcap
|
|
2284 */
|
|
2285 {
|
|
2286 termp = find_builtin_term(term);
|
|
2287 if (termp->bt_string != NULL) /* found it */
|
|
2288 {
|
|
2289 key = TERMCAP2KEY(name[0], name[1]);
|
|
2290 while (termp->bt_entry != (int)KS_NAME)
|
|
2291 {
|
|
2292 if ((int)termp->bt_entry == key)
|
|
2293 {
|
|
2294 add_termcode(name, (char_u *)termp->bt_string,
|
|
2295 term_is_8bit(term));
|
|
2296 return OK;
|
|
2297 }
|
|
2298 ++termp;
|
|
2299 }
|
|
2300 }
|
|
2301 }
|
|
2302 #ifdef HAVE_TGETENT
|
|
2303 else
|
|
2304 /*
|
|
2305 * Search in external termcap
|
|
2306 */
|
|
2307 {
|
|
2308 error_msg = tgetent_error(tbuf, term);
|
|
2309 if (error_msg == NULL)
|
|
2310 {
|
|
2311 string = TGETSTR((char *)name, &tp);
|
|
2312 if (string != NULL && *string != NUL)
|
|
2313 {
|
|
2314 add_termcode(name, string, FALSE);
|
|
2315 return OK;
|
|
2316 }
|
|
2317 }
|
|
2318 }
|
|
2319 }
|
|
2320 #endif
|
|
2321
|
|
2322 if (sourcing_name == NULL)
|
|
2323 {
|
|
2324 #ifdef HAVE_TGETENT
|
|
2325 if (error_msg != NULL)
|
|
2326 EMSG(error_msg);
|
|
2327 else
|
|
2328 #endif
|
|
2329 EMSG2(_("E436: No \"%s\" entry in termcap"), name);
|
|
2330 }
|
|
2331 return FAIL;
|
|
2332 }
|
|
2333
|
|
2334 static int
|
|
2335 term_is_builtin(name)
|
|
2336 char_u *name;
|
|
2337 {
|
|
2338 return (STRNCMP(name, "builtin_", (size_t)8) == 0);
|
|
2339 }
|
|
2340
|
|
2341 /*
|
|
2342 * Return TRUE if terminal "name" uses CSI instead of <Esc>[.
|
|
2343 * Assume that the terminal is using 8-bit controls when the name contains
|
|
2344 * "8bit", like in "xterm-8bit".
|
|
2345 */
|
|
2346 int
|
|
2347 term_is_8bit(name)
|
|
2348 char_u *name;
|
|
2349 {
|
|
2350 return (detected_8bit || strstr((char *)name, "8bit") != NULL);
|
|
2351 }
|
|
2352
|
|
2353 /*
|
|
2354 * Translate terminal control chars from 7-bit to 8-bit:
|
|
2355 * <Esc>[ -> CSI
|
|
2356 * <Esc>] -> <M-C-]>
|
|
2357 * <Esc>O -> <M-C-O>
|
|
2358 */
|
|
2359 static int
|
|
2360 term_7to8bit(p)
|
|
2361 char_u *p;
|
|
2362 {
|
|
2363 if (*p == ESC)
|
|
2364 {
|
|
2365 if (p[1] == '[')
|
|
2366 return CSI;
|
|
2367 if (p[1] == ']')
|
|
2368 return 0x9d;
|
|
2369 if (p[1] == 'O')
|
|
2370 return 0x8f;
|
|
2371 }
|
|
2372 return 0;
|
|
2373 }
|
|
2374
|
|
2375 #ifdef FEAT_GUI
|
|
2376 int
|
|
2377 term_is_gui(name)
|
|
2378 char_u *name;
|
|
2379 {
|
|
2380 return (STRCMP(name, "builtin_gui") == 0 || STRCMP(name, "gui") == 0);
|
|
2381 }
|
|
2382 #endif
|
|
2383
|
|
2384 #if !defined(HAVE_TGETENT) || defined(AMIGA) || defined(PROTO)
|
|
2385
|
|
2386 char_u *
|
|
2387 tltoa(i)
|
|
2388 unsigned long i;
|
|
2389 {
|
|
2390 static char_u buf[16];
|
|
2391 char_u *p;
|
|
2392
|
|
2393 p = buf + 15;
|
|
2394 *p = '\0';
|
|
2395 do
|
|
2396 {
|
|
2397 --p;
|
|
2398 *p = (char_u) (i % 10 + '0');
|
|
2399 i /= 10;
|
|
2400 }
|
|
2401 while (i > 0 && p > buf);
|
|
2402 return p;
|
|
2403 }
|
|
2404 #endif
|
|
2405
|
|
2406 #ifndef HAVE_TGETENT
|
|
2407
|
|
2408 /*
|
|
2409 * minimal tgoto() implementation.
|
|
2410 * no padding and we only parse for %i %d and %+char
|
|
2411 */
|
|
2412 char *tgoto __ARGS((char *, int, int));
|
|
2413
|
|
2414 char *
|
|
2415 tgoto(cm, x, y)
|
|
2416 char *cm;
|
|
2417 int x, y;
|
|
2418 {
|
|
2419 static char buf[30];
|
|
2420 char *p, *s, *e;
|
|
2421
|
|
2422 if (!cm)
|
|
2423 return "OOPS";
|
|
2424 e = buf + 29;
|
|
2425 for (s = buf; s < e && *cm; cm++)
|
|
2426 {
|
|
2427 if (*cm != '%')
|
|
2428 {
|
|
2429 *s++ = *cm;
|
|
2430 continue;
|
|
2431 }
|
|
2432 switch (*++cm)
|
|
2433 {
|
|
2434 case 'd':
|
|
2435 p = (char *)tltoa((unsigned long)y);
|
|
2436 y = x;
|
|
2437 while (*p)
|
|
2438 *s++ = *p++;
|
|
2439 break;
|
|
2440 case 'i':
|
|
2441 x++;
|
|
2442 y++;
|
|
2443 break;
|
|
2444 case '+':
|
|
2445 *s++ = (char)(*++cm + y);
|
|
2446 y = x;
|
|
2447 break;
|
|
2448 case '%':
|
|
2449 *s++ = *cm;
|
|
2450 break;
|
|
2451 default:
|
|
2452 return "OOPS";
|
|
2453 }
|
|
2454 }
|
|
2455 *s = '\0';
|
|
2456 return buf;
|
|
2457 }
|
|
2458
|
|
2459 #endif /* HAVE_TGETENT */
|
|
2460
|
|
2461 /*
|
|
2462 * Set the terminal name and initialize the terminal options.
|
|
2463 * If "name" is NULL or empty, get the terminal name from the environment.
|
|
2464 * If that fails, use the default terminal name.
|
|
2465 */
|
|
2466 void
|
|
2467 termcapinit(name)
|
|
2468 char_u *name;
|
|
2469 {
|
|
2470 char_u *term;
|
|
2471
|
|
2472 if (name != NULL && *name == NUL)
|
|
2473 name = NULL; /* empty name is equal to no name */
|
|
2474 term = name;
|
|
2475
|
|
2476 #ifdef __BEOS__
|
|
2477 /*
|
|
2478 * TERM environment variable is normally set to 'ansi' on the Bebox;
|
|
2479 * Since the BeBox doesn't quite support full ANSI yet, we use our
|
|
2480 * own custom 'ansi-beos' termcap instead, unless the -T option has
|
|
2481 * been given on the command line.
|
|
2482 */
|
|
2483 if (term == NULL
|
|
2484 && strcmp((char *)mch_getenv((char_u *)"TERM"), "ansi") == 0)
|
|
2485 term = DEFAULT_TERM;
|
|
2486 #endif
|
|
2487 #ifndef MSWIN
|
|
2488 if (term == NULL)
|
|
2489 term = mch_getenv((char_u *)"TERM");
|
|
2490 #endif
|
|
2491 if (term == NULL || *term == NUL)
|
|
2492 term = DEFAULT_TERM;
|
|
2493 set_string_option_direct((char_u *)"term", -1, term, OPT_FREE);
|
|
2494
|
|
2495 /* Set the default terminal name. */
|
|
2496 set_string_default("term", term);
|
|
2497 set_string_default("ttytype", term);
|
|
2498
|
|
2499 /*
|
|
2500 * Avoid using "term" here, because the next mch_getenv() may overwrite it.
|
|
2501 */
|
|
2502 set_termname(T_NAME != NULL ? T_NAME : term);
|
|
2503 }
|
|
2504
|
|
2505 /*
|
|
2506 * the number of calls to ui_write is reduced by using the buffer "out_buf"
|
|
2507 */
|
|
2508 #ifdef DOS16
|
|
2509 # define OUT_SIZE 255 /* only have 640K total... */
|
|
2510 #else
|
|
2511 # ifdef FEAT_GUI_W16
|
|
2512 # define OUT_SIZE 1023 /* Save precious 1K near data */
|
|
2513 # else
|
|
2514 # define OUT_SIZE 2047
|
|
2515 # endif
|
|
2516 #endif
|
|
2517 /* Add one to allow mch_write() in os_win32.c to append a NUL */
|
|
2518 static char_u out_buf[OUT_SIZE + 1];
|
|
2519 static int out_pos = 0; /* number of chars in out_buf */
|
|
2520
|
|
2521 /*
|
|
2522 * out_flush(): flush the output buffer
|
|
2523 */
|
|
2524 void
|
|
2525 out_flush()
|
|
2526 {
|
|
2527 int len;
|
|
2528
|
|
2529 if (out_pos != 0)
|
|
2530 {
|
|
2531 /* set out_pos to 0 before ui_write, to avoid recursiveness */
|
|
2532 len = out_pos;
|
|
2533 out_pos = 0;
|
|
2534 ui_write(out_buf, len);
|
|
2535 }
|
|
2536 }
|
|
2537
|
|
2538 #if defined(FEAT_MBYTE) || defined(PROTO)
|
|
2539 /*
|
|
2540 * Sometimes a byte out of a multi-byte character is written with out_char().
|
|
2541 * To avoid flushing half of the character, call this function first.
|
|
2542 */
|
|
2543 void
|
|
2544 out_flush_check()
|
|
2545 {
|
|
2546 if (enc_dbcs != 0 && out_pos >= OUT_SIZE - MB_MAXBYTES)
|
|
2547 out_flush();
|
|
2548 }
|
|
2549 #endif
|
|
2550
|
|
2551 #ifdef FEAT_GUI
|
|
2552 /*
|
|
2553 * out_trash(): Throw away the contents of the output buffer
|
|
2554 */
|
|
2555 void
|
|
2556 out_trash()
|
|
2557 {
|
|
2558 out_pos = 0;
|
|
2559 }
|
|
2560 #endif
|
|
2561
|
|
2562 /*
|
|
2563 * out_char(c): put a byte into the output buffer.
|
|
2564 * Flush it if it becomes full.
|
|
2565 * This should not be used for outputting text on the screen (use functions
|
|
2566 * like msg_puts() and screen_putchar() for that).
|
|
2567 */
|
|
2568 void
|
|
2569 out_char(c)
|
|
2570 unsigned c;
|
|
2571 {
|
|
2572 #if defined(UNIX) || defined(VMS) || defined(AMIGA) || defined(MACOS_X_UNIX)
|
|
2573 if (c == '\n') /* turn LF into CR-LF (CRMOD doesn't seem to do this) */
|
|
2574 out_char('\r');
|
|
2575 #endif
|
|
2576
|
|
2577 out_buf[out_pos++] = c;
|
|
2578
|
|
2579 /* For testing we flush each time. */
|
|
2580 if (out_pos >= OUT_SIZE || p_wd)
|
|
2581 out_flush();
|
|
2582 }
|
|
2583
|
|
2584 static void out_char_nf __ARGS((unsigned));
|
|
2585
|
|
2586 /*
|
|
2587 * out_char_nf(c): like out_char(), but don't flush when p_wd is set
|
|
2588 */
|
|
2589 static void
|
|
2590 out_char_nf(c)
|
|
2591 unsigned c;
|
|
2592 {
|
|
2593 #if defined(UNIX) || defined(VMS) || defined(AMIGA) || defined(MACOS_X_UNIX)
|
|
2594 if (c == '\n') /* turn LF into CR-LF (CRMOD doesn't seem to do this) */
|
|
2595 out_char_nf('\r');
|
|
2596 #endif
|
|
2597
|
|
2598 out_buf[out_pos++] = c;
|
|
2599
|
|
2600 if (out_pos >= OUT_SIZE)
|
|
2601 out_flush();
|
|
2602 }
|
|
2603
|
|
2604 /*
|
|
2605 * A never-padding out_str.
|
|
2606 * use this whenever you don't want to run the string through tputs.
|
|
2607 * tputs above is harmless, but tputs from the termcap library
|
|
2608 * is likely to strip off leading digits, that it mistakes for padding
|
|
2609 * information, and "%i", "%d", etc.
|
|
2610 * This should only be used for writing terminal codes, not for outputting
|
|
2611 * normal text (use functions like msg_puts() and screen_putchar() for that).
|
|
2612 */
|
|
2613 void
|
|
2614 out_str_nf(s)
|
|
2615 char_u *s;
|
|
2616 {
|
|
2617 if (out_pos > OUT_SIZE - 20) /* avoid terminal strings being split up */
|
|
2618 out_flush();
|
|
2619 while (*s)
|
|
2620 out_char_nf(*s++);
|
|
2621
|
|
2622 /* For testing we write one string at a time. */
|
|
2623 if (p_wd)
|
|
2624 out_flush();
|
|
2625 }
|
|
2626
|
|
2627 /*
|
|
2628 * out_str(s): Put a character string a byte at a time into the output buffer.
|
|
2629 * If HAVE_TGETENT is defined use the termcap parser. (jw)
|
|
2630 * This should only be used for writing terminal codes, not for outputting
|
|
2631 * normal text (use functions like msg_puts() and screen_putchar() for that).
|
|
2632 */
|
|
2633 void
|
|
2634 out_str(s)
|
|
2635 char_u *s;
|
|
2636 {
|
|
2637 if (s != NULL && *s)
|
|
2638 {
|
|
2639 #ifdef FEAT_GUI
|
|
2640 /* Don't use tputs() when GUI is used, ncurses crashes. */
|
|
2641 if (gui.in_use)
|
|
2642 {
|
|
2643 out_str_nf(s);
|
|
2644 return;
|
|
2645 }
|
|
2646 #endif
|
|
2647 /* avoid terminal strings being split up */
|
|
2648 if (out_pos > OUT_SIZE - 20)
|
|
2649 out_flush();
|
|
2650 #ifdef HAVE_TGETENT
|
|
2651 tputs((char *)s, 1, TPUTSFUNCAST out_char_nf);
|
|
2652 #else
|
|
2653 while (*s)
|
|
2654 out_char_nf(*s++);
|
|
2655 #endif
|
|
2656
|
|
2657 /* For testing we write one string at a time. */
|
|
2658 if (p_wd)
|
|
2659 out_flush();
|
|
2660 }
|
|
2661 }
|
|
2662
|
|
2663 /*
|
|
2664 * cursor positioning using termcap parser. (jw)
|
|
2665 */
|
|
2666 void
|
|
2667 term_windgoto(row, col)
|
|
2668 int row;
|
|
2669 int col;
|
|
2670 {
|
|
2671 OUT_STR(tgoto((char *)T_CM, col, row));
|
|
2672 }
|
|
2673
|
|
2674 void
|
|
2675 term_cursor_right(i)
|
|
2676 int i;
|
|
2677 {
|
|
2678 OUT_STR(tgoto((char *)T_CRI, 0, i));
|
|
2679 }
|
|
2680
|
|
2681 void
|
|
2682 term_append_lines(line_count)
|
|
2683 int line_count;
|
|
2684 {
|
|
2685 OUT_STR(tgoto((char *)T_CAL, 0, line_count));
|
|
2686 }
|
|
2687
|
|
2688 void
|
|
2689 term_delete_lines(line_count)
|
|
2690 int line_count;
|
|
2691 {
|
|
2692 OUT_STR(tgoto((char *)T_CDL, 0, line_count));
|
|
2693 }
|
|
2694
|
|
2695 #if defined(HAVE_TGETENT) || defined(PROTO)
|
|
2696 void
|
|
2697 term_set_winpos(x, y)
|
|
2698 int x;
|
|
2699 int y;
|
|
2700 {
|
|
2701 /* Can't handle a negative value here */
|
|
2702 if (x < 0)
|
|
2703 x = 0;
|
|
2704 if (y < 0)
|
|
2705 y = 0;
|
|
2706 OUT_STR(tgoto((char *)T_CWP, y, x));
|
|
2707 }
|
|
2708
|
|
2709 void
|
|
2710 term_set_winsize(width, height)
|
|
2711 int width;
|
|
2712 int height;
|
|
2713 {
|
|
2714 OUT_STR(tgoto((char *)T_CWS, height, width));
|
|
2715 }
|
|
2716 #endif
|
|
2717
|
|
2718 void
|
|
2719 term_fg_color(n)
|
|
2720 int n;
|
|
2721 {
|
|
2722 /* Use "AF" termcap entry if present, "Sf" entry otherwise */
|
|
2723 if (*T_CAF)
|
|
2724 term_color(T_CAF, n);
|
|
2725 else if (*T_CSF)
|
|
2726 term_color(T_CSF, n);
|
|
2727 }
|
|
2728
|
|
2729 void
|
|
2730 term_bg_color(n)
|
|
2731 int n;
|
|
2732 {
|
|
2733 /* Use "AB" termcap entry if present, "Sb" entry otherwise */
|
|
2734 if (*T_CAB)
|
|
2735 term_color(T_CAB, n);
|
|
2736 else if (*T_CSB)
|
|
2737 term_color(T_CSB, n);
|
|
2738 }
|
|
2739
|
|
2740 static void
|
|
2741 term_color(s, n)
|
|
2742 char_u *s;
|
|
2743 int n;
|
|
2744 {
|
|
2745 char buf[20];
|
|
2746 int i = 2; /* index in s[] just after <Esc>[ or CSI */
|
|
2747
|
|
2748 /* Special handling of 16 colors, because termcap can't handle it */
|
|
2749 /* Also accept "\e[3%dm" for TERMINFO, it is sometimes used */
|
|
2750 /* Also accept CSI instead of <Esc>[ */
|
|
2751 if (n >= 8 && t_colors >= 16
|
|
2752 && ((s[0] == ESC && s[1] == '[') || (s[0] == CSI && (i = 1) == 1))
|
|
2753 && s[i] != NUL
|
|
2754 && (STRCMP(s + i + 1, "%p1%dm") == 0
|
|
2755 || STRCMP(s + i + 1, "%dm") == 0)
|
|
2756 && (s[i] == '3' || s[i] == '4'))
|
|
2757 {
|
|
2758 sprintf(buf,
|
|
2759 #ifdef TERMINFO
|
|
2760 "%s%s%%p1%%dm",
|
|
2761 #else
|
|
2762 "%s%s%%dm",
|
|
2763 #endif
|
|
2764 i == 2 ? IF_EB("\033[", ESC_STR "[") : "\233",
|
|
2765 s[i] == '3' ? (n >= 16 ? "38;5;" : "9")
|
|
2766 : (n >= 16 ? "48;5;" : "10"));
|
|
2767 OUT_STR(tgoto(buf, 0, n >= 16 ? n : n - 8));
|
|
2768 }
|
|
2769 else
|
|
2770 OUT_STR(tgoto((char *)s, 0, n));
|
|
2771 }
|
|
2772
|
|
2773 #if (defined(FEAT_TITLE) && (defined(UNIX) || defined(OS2) || defined(VMS) || defined(MACOS_X))) || defined(PROTO)
|
|
2774 /*
|
|
2775 * Generic function to set window title, using t_ts and t_fs.
|
|
2776 */
|
|
2777 void
|
|
2778 term_settitle(title)
|
|
2779 char_u *title;
|
|
2780 {
|
|
2781 /* t_ts takes one argument: column in status line */
|
|
2782 OUT_STR(tgoto((char *)T_TS, 0, 0)); /* set title start */
|
|
2783 out_str_nf(title);
|
|
2784 out_str(T_FS); /* set title end */
|
|
2785 out_flush();
|
|
2786 }
|
|
2787 #endif
|
|
2788
|
|
2789 /*
|
|
2790 * Make sure we have a valid set or terminal options.
|
|
2791 * Replace all entries that are NULL by empty_option
|
|
2792 */
|
|
2793 void
|
|
2794 ttest(pairs)
|
|
2795 int pairs;
|
|
2796 {
|
|
2797 check_options(); /* make sure no options are NULL */
|
|
2798
|
|
2799 /*
|
|
2800 * MUST have "cm": cursor motion.
|
|
2801 */
|
|
2802 if (*T_CM == NUL)
|
|
2803 EMSG(_("E437: terminal capability \"cm\" required"));
|
|
2804
|
|
2805 /*
|
|
2806 * if "cs" defined, use a scroll region, it's faster.
|
|
2807 */
|
|
2808 if (*T_CS != NUL)
|
|
2809 scroll_region = TRUE;
|
|
2810 else
|
|
2811 scroll_region = FALSE;
|
|
2812
|
|
2813 if (pairs)
|
|
2814 {
|
|
2815 /*
|
|
2816 * optional pairs
|
|
2817 */
|
|
2818 /* TP goes to normal mode for TI (invert) and TB (bold) */
|
|
2819 if (*T_ME == NUL)
|
|
2820 T_ME = T_MR = T_MD = T_MB = empty_option;
|
|
2821 if (*T_SO == NUL || *T_SE == NUL)
|
|
2822 T_SO = T_SE = empty_option;
|
|
2823 if (*T_US == NUL || *T_UE == NUL)
|
|
2824 T_US = T_UE = empty_option;
|
|
2825 if (*T_CZH == NUL || *T_CZR == NUL)
|
|
2826 T_CZH = T_CZR = empty_option;
|
|
2827
|
|
2828 /* T_VE is needed even though T_VI is not defined */
|
|
2829 if (*T_VE == NUL)
|
|
2830 T_VI = empty_option;
|
|
2831
|
|
2832 /* if 'mr' or 'me' is not defined use 'so' and 'se' */
|
|
2833 if (*T_ME == NUL)
|
|
2834 {
|
|
2835 T_ME = T_SE;
|
|
2836 T_MR = T_SO;
|
|
2837 T_MD = T_SO;
|
|
2838 }
|
|
2839
|
|
2840 /* if 'so' or 'se' is not defined use 'mr' and 'me' */
|
|
2841 if (*T_SO == NUL)
|
|
2842 {
|
|
2843 T_SE = T_ME;
|
|
2844 if (*T_MR == NUL)
|
|
2845 T_SO = T_MD;
|
|
2846 else
|
|
2847 T_SO = T_MR;
|
|
2848 }
|
|
2849
|
|
2850 /* if 'ZH' or 'ZR' is not defined use 'mr' and 'me' */
|
|
2851 if (*T_CZH == NUL)
|
|
2852 {
|
|
2853 T_CZR = T_ME;
|
|
2854 if (*T_MR == NUL)
|
|
2855 T_CZH = T_MD;
|
|
2856 else
|
|
2857 T_CZH = T_MR;
|
|
2858 }
|
|
2859
|
|
2860 /* "Sb" and "Sf" come in pairs */
|
|
2861 if (*T_CSB == NUL || *T_CSF == NUL)
|
|
2862 {
|
|
2863 T_CSB = empty_option;
|
|
2864 T_CSF = empty_option;
|
|
2865 }
|
|
2866
|
|
2867 /* "AB" and "AF" come in pairs */
|
|
2868 if (*T_CAB == NUL || *T_CAF == NUL)
|
|
2869 {
|
|
2870 T_CAB = empty_option;
|
|
2871 T_CAF = empty_option;
|
|
2872 }
|
|
2873
|
|
2874 /* if 'Sb' and 'AB' are not defined, reset "Co" */
|
|
2875 if (*T_CSB == NUL && *T_CAB == NUL)
|
|
2876 T_CCO = empty_option;
|
|
2877
|
|
2878 /* Set 'weirdinvert' according to value of 't_xs' */
|
|
2879 p_wiv = (*T_XS != NUL);
|
|
2880 }
|
|
2881 need_gather = TRUE;
|
|
2882
|
|
2883 /* Set t_colors to the value of t_Co. */
|
|
2884 t_colors = atoi((char *)T_CCO);
|
|
2885 }
|
|
2886
|
|
2887 #if (defined(FEAT_GUI) && (defined(FEAT_MENU) || !defined(USE_ON_FLY_SCROLL))) \
|
|
2888 || defined(PROTO)
|
|
2889 /*
|
|
2890 * Represent the given long_u as individual bytes, with the most significant
|
|
2891 * byte first, and store them in dst.
|
|
2892 */
|
|
2893 void
|
|
2894 add_long_to_buf(val, dst)
|
|
2895 long_u val;
|
|
2896 char_u *dst;
|
|
2897 {
|
|
2898 int i;
|
|
2899 int shift;
|
|
2900
|
|
2901 for (i = 1; i <= sizeof(long_u); i++)
|
|
2902 {
|
|
2903 shift = 8 * (sizeof(long_u) - i);
|
|
2904 dst[i - 1] = (char_u) ((val >> shift) & 0xff);
|
|
2905 }
|
|
2906 }
|
|
2907
|
|
2908 static int get_long_from_buf __ARGS((char_u *buf, long_u *val));
|
|
2909
|
|
2910 /*
|
|
2911 * Interpret the next string of bytes in buf as a long integer, with the most
|
|
2912 * significant byte first. Note that it is assumed that buf has been through
|
|
2913 * inchar(), so that NUL and K_SPECIAL will be represented as three bytes each.
|
|
2914 * Puts result in val, and returns the number of bytes read from buf
|
|
2915 * (between sizeof(long_u) and 2 * sizeof(long_u)), or -1 if not enough bytes
|
|
2916 * were present.
|
|
2917 */
|
|
2918 static int
|
|
2919 get_long_from_buf(buf, val)
|
|
2920 char_u *buf;
|
|
2921 long_u *val;
|
|
2922 {
|
|
2923 int len;
|
|
2924 char_u bytes[sizeof(long_u)];
|
|
2925 int i;
|
|
2926 int shift;
|
|
2927
|
|
2928 *val = 0;
|
|
2929 len = get_bytes_from_buf(buf, bytes, (int)sizeof(long_u));
|
|
2930 if (len != -1)
|
|
2931 {
|
|
2932 for (i = 0; i < sizeof(long_u); i++)
|
|
2933 {
|
|
2934 shift = 8 * (sizeof(long_u) - 1 - i);
|
|
2935 *val += (long_u)bytes[i] << shift;
|
|
2936 }
|
|
2937 }
|
|
2938 return len;
|
|
2939 }
|
|
2940 #endif
|
|
2941
|
|
2942 #if defined(FEAT_GUI) \
|
|
2943 || (defined(FEAT_MOUSE) && (!defined(UNIX) || defined(FEAT_MOUSE_XTERM)))
|
|
2944 /*
|
|
2945 * Read the next num_bytes bytes from buf, and store them in bytes. Assume
|
|
2946 * that buf has been through inchar(). Returns the actual number of bytes used
|
|
2947 * from buf (between num_bytes and num_bytes*2), or -1 if not enough bytes were
|
|
2948 * available.
|
|
2949 */
|
|
2950 static int
|
|
2951 get_bytes_from_buf(buf, bytes, num_bytes)
|
|
2952 char_u *buf;
|
|
2953 char_u *bytes;
|
|
2954 int num_bytes;
|
|
2955 {
|
|
2956 int len = 0;
|
|
2957 int i;
|
|
2958 char_u c;
|
|
2959
|
|
2960 for (i = 0; i < num_bytes; i++)
|
|
2961 {
|
|
2962 if ((c = buf[len++]) == NUL)
|
|
2963 return -1;
|
|
2964 if (c == K_SPECIAL)
|
|
2965 {
|
|
2966 if (buf[len] == NUL || buf[len + 1] == NUL) /* cannot happen? */
|
|
2967 return -1;
|
|
2968 if (buf[len++] == (int)KS_ZERO)
|
|
2969 c = NUL;
|
|
2970 ++len; /* skip KE_FILLER */
|
|
2971 /* else it should be KS_SPECIAL, and c already equals K_SPECIAL */
|
|
2972 }
|
|
2973 bytes[i] = c;
|
|
2974 }
|
|
2975 return len;
|
|
2976 }
|
|
2977 #endif
|
|
2978
|
|
2979 /*
|
|
2980 * Check if the new shell size is valid, correct it if it's too small.
|
|
2981 */
|
|
2982 void
|
|
2983 check_shellsize()
|
|
2984 {
|
|
2985 if (Columns < MIN_COLUMNS)
|
|
2986 Columns = MIN_COLUMNS;
|
|
2987 if (Rows < min_rows()) /* need room for one window and command line */
|
|
2988 Rows = min_rows();
|
|
2989 }
|
|
2990
|
41
|
2991 /*
|
|
2992 * Invoked just before the screen structures are going to be (re)allocated.
|
|
2993 */
|
7
|
2994 void
|
|
2995 win_new_shellsize()
|
|
2996 {
|
|
2997 static int old_Rows = 0;
|
|
2998 static int old_Columns = 0;
|
|
2999
|
|
3000 if (old_Rows != Rows || old_Columns != Columns)
|
|
3001 ui_new_shellsize();
|
|
3002 if (old_Rows != Rows)
|
|
3003 {
|
164
|
3004 /* if 'window' uses the whole screen, keep it using that */
|
179
|
3005 if (p_window == old_Rows - 1 || old_Rows == 0)
|
164
|
3006 p_window = Rows - 1;
|
7
|
3007 old_Rows = Rows;
|
|
3008 shell_new_rows(); /* update window sizes */
|
|
3009 }
|
|
3010 if (old_Columns != Columns)
|
|
3011 {
|
|
3012 old_Columns = Columns;
|
|
3013 #ifdef FEAT_VERTSPLIT
|
|
3014 shell_new_columns(); /* update window sizes */
|
|
3015 #endif
|
|
3016 }
|
|
3017 }
|
|
3018
|
|
3019 /*
|
|
3020 * Call this function when the Vim shell has been resized in any way.
|
|
3021 * Will obtain the current size and redraw (also when size didn't change).
|
|
3022 */
|
|
3023 void
|
|
3024 shell_resized()
|
|
3025 {
|
|
3026 set_shellsize(0, 0, FALSE);
|
|
3027 }
|
|
3028
|
|
3029 /*
|
|
3030 * Check if the shell size changed. Handle a resize.
|
|
3031 * When the size didn't change, nothing happens.
|
|
3032 */
|
|
3033 void
|
|
3034 shell_resized_check()
|
|
3035 {
|
|
3036 int old_Rows = Rows;
|
|
3037 int old_Columns = Columns;
|
|
3038
|
|
3039 (void)ui_get_shellsize();
|
|
3040 check_shellsize();
|
|
3041 if (old_Rows != Rows || old_Columns != Columns)
|
|
3042 shell_resized();
|
|
3043 }
|
|
3044
|
|
3045 /*
|
|
3046 * Set size of the Vim shell.
|
|
3047 * If 'mustset' is TRUE, we must set Rows and Columns, do not get the real
|
|
3048 * window size (this is used for the :win command).
|
|
3049 * If 'mustset' is FALSE, we may try to get the real window size and if
|
|
3050 * it fails use 'width' and 'height'.
|
|
3051 */
|
|
3052 void
|
|
3053 set_shellsize(width, height, mustset)
|
|
3054 int width, height;
|
|
3055 int mustset;
|
|
3056 {
|
|
3057 static int busy = FALSE;
|
|
3058
|
|
3059 /*
|
|
3060 * Avoid recursiveness, can happen when setting the window size causes
|
|
3061 * another window-changed signal.
|
|
3062 */
|
|
3063 if (busy)
|
|
3064 return;
|
|
3065
|
|
3066 if (width < 0 || height < 0) /* just checking... */
|
|
3067 return;
|
|
3068
|
|
3069 if (State == HITRETURN || State == SETWSIZE) /* postpone the resizing */
|
|
3070 {
|
|
3071 State = SETWSIZE;
|
|
3072 return;
|
|
3073 }
|
|
3074
|
|
3075 ++busy;
|
|
3076
|
|
3077 #ifdef AMIGA
|
|
3078 out_flush(); /* must do this before mch_get_shellsize() for
|
|
3079 some obscure reason */
|
|
3080 #endif
|
|
3081
|
|
3082 if (mustset || (ui_get_shellsize() == FAIL && height != 0))
|
|
3083 {
|
|
3084 Rows = height;
|
|
3085 Columns = width;
|
|
3086 check_shellsize();
|
|
3087 ui_set_shellsize(mustset);
|
|
3088 }
|
|
3089 else
|
|
3090 check_shellsize();
|
|
3091
|
|
3092 /* The window layout used to be adjusted here, but it now happens in
|
|
3093 * screenalloc() (also invoked from screenclear()). That is because the
|
|
3094 * "busy" check above may skip this, but not screenalloc(). */
|
|
3095
|
|
3096 if (State != ASKMORE && State != EXTERNCMD && State != CONFIRM)
|
|
3097 screenclear();
|
|
3098 else
|
|
3099 screen_start(); /* don't know where cursor is now */
|
|
3100
|
|
3101 if (starting != NO_SCREEN)
|
|
3102 {
|
|
3103 #ifdef FEAT_TITLE
|
|
3104 maketitle();
|
|
3105 #endif
|
|
3106 changed_line_abv_curs();
|
|
3107 invalidate_botline();
|
|
3108
|
|
3109 /*
|
|
3110 * We only redraw when it's needed:
|
|
3111 * - While at the more prompt or executing an external command, don't
|
|
3112 * redraw, but position the cursor.
|
|
3113 * - While editing the command line, only redraw that.
|
|
3114 * - in Ex mode, don't redraw anything.
|
|
3115 * - Otherwise, redraw right now, and position the cursor.
|
|
3116 * Always need to call update_screen() or screenalloc(), to make
|
|
3117 * sure Rows/Columns and the size of ScreenLines[] is correct!
|
|
3118 */
|
|
3119 if (State == ASKMORE || State == EXTERNCMD || State == CONFIRM
|
|
3120 || exmode_active)
|
|
3121 {
|
|
3122 screenalloc(FALSE);
|
|
3123 repeat_message();
|
|
3124 }
|
|
3125 else if (State & CMDLINE)
|
|
3126 {
|
|
3127 update_screen(NOT_VALID);
|
|
3128 redrawcmdline();
|
|
3129 }
|
|
3130 else
|
|
3131 {
|
|
3132 update_topline();
|
|
3133 update_screen(NOT_VALID);
|
|
3134 if (redrawing())
|
|
3135 setcursor();
|
|
3136 }
|
|
3137 cursor_on(); /* redrawing may have switched it off */
|
|
3138 }
|
|
3139 out_flush();
|
|
3140 --busy;
|
|
3141 }
|
|
3142
|
|
3143 /*
|
|
3144 * Set the terminal to TMODE_RAW (for Normal mode) or TMODE_COOK (for external
|
|
3145 * commands and Ex mode).
|
|
3146 */
|
|
3147 void
|
|
3148 settmode(tmode)
|
|
3149 int tmode;
|
|
3150 {
|
|
3151 #ifdef FEAT_GUI
|
|
3152 /* don't set the term where gvim was started to any mode */
|
|
3153 if (gui.in_use)
|
|
3154 return;
|
|
3155 #endif
|
|
3156
|
|
3157 if (full_screen)
|
|
3158 {
|
|
3159 /*
|
|
3160 * When returning after calling a shell we want to really set the
|
|
3161 * terminal to raw mode, even though we think it already is, because
|
|
3162 * the shell program may have reset the terminal mode.
|
|
3163 * When we think the terminal is normal, don't try to set it to
|
|
3164 * normal again, because that causes problems (logout!) on some
|
|
3165 * machines.
|
|
3166 */
|
|
3167 if (tmode != TMODE_COOK || cur_tmode != TMODE_COOK)
|
|
3168 {
|
|
3169 #ifdef FEAT_TERMRESPONSE
|
|
3170 /* May need to check for T_CRV response and termcodes, it doesn't
|
|
3171 * work in Cooked mode, an external program may get them. */
|
|
3172 if (tmode != TMODE_RAW && crv_status == CRV_SENT)
|
|
3173 (void)vpeekc_nomap();
|
|
3174 check_for_codes_from_term();
|
|
3175 #endif
|
|
3176 #ifdef FEAT_MOUSE_TTY
|
|
3177 if (tmode != TMODE_RAW)
|
|
3178 mch_setmouse(FALSE); /* switch mouse off */
|
|
3179 #endif
|
|
3180 out_flush();
|
|
3181 mch_settmode(tmode); /* machine specific function */
|
|
3182 cur_tmode = tmode;
|
|
3183 #ifdef FEAT_MOUSE
|
|
3184 if (tmode == TMODE_RAW)
|
|
3185 setmouse(); /* may switch mouse on */
|
|
3186 #endif
|
|
3187 out_flush();
|
|
3188 }
|
|
3189 #ifdef FEAT_TERMRESPONSE
|
|
3190 may_req_termresponse();
|
|
3191 #endif
|
|
3192 }
|
|
3193 }
|
|
3194
|
|
3195 void
|
|
3196 starttermcap()
|
|
3197 {
|
|
3198 if (full_screen && !termcap_active)
|
|
3199 {
|
|
3200 out_str(T_TI); /* start termcap mode */
|
|
3201 out_str(T_KS); /* start "keypad transmit" mode */
|
|
3202 out_flush();
|
|
3203 termcap_active = TRUE;
|
|
3204 screen_start(); /* don't know where cursor is now */
|
|
3205 #ifdef FEAT_TERMRESPONSE
|
|
3206 may_req_termresponse();
|
|
3207 /* Immediately check for a response. If t_Co changes, we don't want
|
|
3208 * to redraw with wrong colors first. */
|
|
3209 check_for_codes_from_term();
|
|
3210 #endif
|
|
3211 }
|
|
3212 }
|
|
3213
|
|
3214 void
|
|
3215 stoptermcap()
|
|
3216 {
|
|
3217 screen_stop_highlight();
|
|
3218 reset_cterm_colors();
|
|
3219 if (termcap_active)
|
|
3220 {
|
|
3221 #ifdef FEAT_TERMRESPONSE
|
|
3222 /* May need to check for T_CRV response. */
|
|
3223 if (crv_status == CRV_SENT)
|
|
3224 (void)vpeekc_nomap();
|
|
3225 /* Check for termcodes first, otherwise an external program may get
|
|
3226 * them. */
|
|
3227 check_for_codes_from_term();
|
|
3228 #endif
|
|
3229 out_str(T_KE); /* stop "keypad transmit" mode */
|
|
3230 out_flush();
|
|
3231 termcap_active = FALSE;
|
|
3232 cursor_on(); /* just in case it is still off */
|
|
3233 out_str(T_TE); /* stop termcap mode */
|
|
3234 screen_start(); /* don't know where cursor is now */
|
|
3235 out_flush();
|
|
3236 }
|
|
3237 }
|
|
3238
|
|
3239 #ifdef FEAT_TERMRESPONSE
|
|
3240 /*
|
|
3241 * Request version string (for xterm) when needed.
|
|
3242 * Only do this after switching to raw mode, otherwise the result will be
|
|
3243 * echoed.
|
|
3244 * Only do this after termcap mode has been started, otherwise the codes for
|
|
3245 * the cursor keys may be wrong.
|
164
|
3246 * On Unix only do it when both output and input are a tty (avoid writing
|
|
3247 * request to terminal while reading from a file).
|
7
|
3248 * The result is caught in check_termcode().
|
|
3249 */
|
|
3250 static void
|
|
3251 may_req_termresponse()
|
|
3252 {
|
|
3253 if (crv_status == CRV_GET
|
|
3254 && cur_tmode == TMODE_RAW
|
|
3255 && termcap_active
|
|
3256 #ifdef UNIX
|
|
3257 && isatty(1)
|
164
|
3258 && isatty(read_cmd_fd)
|
7
|
3259 #endif
|
|
3260 && *T_CRV != NUL)
|
|
3261 {
|
|
3262 out_str(T_CRV);
|
|
3263 crv_status = CRV_SENT;
|
|
3264 /* check for the characters now, otherwise they might be eaten by
|
|
3265 * get_keystroke() */
|
|
3266 out_flush();
|
|
3267 (void)vpeekc_nomap();
|
|
3268 }
|
|
3269 }
|
|
3270 #endif
|
|
3271
|
|
3272 /*
|
|
3273 * Return TRUE when saving and restoring the screen.
|
|
3274 */
|
|
3275 int
|
|
3276 swapping_screen()
|
|
3277 {
|
|
3278 return (full_screen && *T_TI != NUL);
|
|
3279 }
|
|
3280
|
|
3281 #ifdef FEAT_MOUSE
|
|
3282 /*
|
|
3283 * setmouse() - switch mouse on/off depending on current mode and 'mouse'
|
|
3284 */
|
|
3285 void
|
|
3286 setmouse()
|
|
3287 {
|
|
3288 # ifdef FEAT_MOUSE_TTY
|
|
3289 int checkfor;
|
|
3290 # endif
|
|
3291
|
|
3292 # ifdef FEAT_MOUSESHAPE
|
|
3293 update_mouseshape(-1);
|
|
3294 # endif
|
|
3295
|
|
3296 # ifdef FEAT_MOUSE_TTY /* Should be outside proc, but may break MOUSESHAPE */
|
|
3297 # ifdef FEAT_GUI
|
|
3298 /* In the GUI the mouse is always enabled. */
|
|
3299 if (gui.in_use)
|
|
3300 return;
|
|
3301 # endif
|
|
3302 /* be quick when mouse is off */
|
|
3303 if (*p_mouse == NUL || has_mouse_termcode == 0)
|
|
3304 return;
|
|
3305
|
|
3306 /* don't switch mouse on when not in raw mode (Ex mode) */
|
|
3307 if (cur_tmode != TMODE_RAW)
|
|
3308 {
|
|
3309 mch_setmouse(FALSE);
|
|
3310 return;
|
|
3311 }
|
|
3312
|
|
3313 # ifdef FEAT_VISUAL
|
|
3314 if (VIsual_active)
|
|
3315 checkfor = MOUSE_VISUAL;
|
|
3316 else
|
|
3317 # endif
|
|
3318 if (State == HITRETURN || State == ASKMORE || State == SETWSIZE)
|
|
3319 checkfor = MOUSE_RETURN;
|
|
3320 else if (State & INSERT)
|
|
3321 checkfor = MOUSE_INSERT;
|
|
3322 else if (State & CMDLINE)
|
|
3323 checkfor = MOUSE_COMMAND;
|
|
3324 else if (State == CONFIRM || State == EXTERNCMD)
|
|
3325 checkfor = ' '; /* don't use mouse for ":confirm" or ":!cmd" */
|
|
3326 else
|
|
3327 checkfor = MOUSE_NORMAL; /* assume normal mode */
|
|
3328
|
|
3329 if (mouse_has(checkfor))
|
|
3330 mch_setmouse(TRUE);
|
|
3331 else
|
|
3332 mch_setmouse(FALSE);
|
|
3333 # endif
|
|
3334 }
|
|
3335
|
|
3336 /*
|
|
3337 * Return TRUE if
|
|
3338 * - "c" is in 'mouse', or
|
|
3339 * - 'a' is in 'mouse' and "c" is in MOUSE_A, or
|
|
3340 * - the current buffer is a help file and 'h' is in 'mouse' and we are in a
|
|
3341 * normal editing mode (not at hit-return message).
|
|
3342 */
|
|
3343 int
|
|
3344 mouse_has(c)
|
|
3345 int c;
|
|
3346 {
|
|
3347 char_u *p;
|
|
3348
|
|
3349 for (p = p_mouse; *p; ++p)
|
|
3350 switch (*p)
|
|
3351 {
|
|
3352 case 'a': if (vim_strchr((char_u *)MOUSE_A, c) != NULL)
|
|
3353 return TRUE;
|
|
3354 break;
|
|
3355 case MOUSE_HELP: if (c != MOUSE_RETURN && curbuf->b_help)
|
|
3356 return TRUE;
|
|
3357 break;
|
|
3358 default: if (c == *p) return TRUE; break;
|
|
3359 }
|
|
3360 return FALSE;
|
|
3361 }
|
|
3362
|
|
3363 /*
|
|
3364 * Return TRUE when 'mousemodel' is set to "popup" or "popup_setpos".
|
|
3365 */
|
|
3366 int
|
|
3367 mouse_model_popup()
|
|
3368 {
|
|
3369 return (p_mousem[0] == 'p');
|
|
3370 }
|
|
3371 #endif
|
|
3372
|
|
3373 /*
|
|
3374 * By outputting the 'cursor very visible' termcap code, for some windowed
|
|
3375 * terminals this makes the screen scrolled to the correct position.
|
|
3376 * Used when starting Vim or returning from a shell.
|
|
3377 */
|
|
3378 void
|
|
3379 scroll_start()
|
|
3380 {
|
|
3381 if (*T_VS != NUL)
|
|
3382 {
|
|
3383 out_str(T_VS);
|
|
3384 out_str(T_VE);
|
|
3385 screen_start(); /* don't know where cursor is now */
|
|
3386 }
|
|
3387 }
|
|
3388
|
|
3389 static int cursor_is_off = FALSE;
|
|
3390
|
|
3391 /*
|
|
3392 * Enable the cursor.
|
|
3393 */
|
|
3394 void
|
|
3395 cursor_on()
|
|
3396 {
|
|
3397 if (cursor_is_off)
|
|
3398 {
|
|
3399 out_str(T_VE);
|
|
3400 cursor_is_off = FALSE;
|
|
3401 }
|
|
3402 }
|
|
3403
|
|
3404 /*
|
|
3405 * Disable the cursor.
|
|
3406 */
|
|
3407 void
|
|
3408 cursor_off()
|
|
3409 {
|
|
3410 if (full_screen)
|
|
3411 {
|
|
3412 if (!cursor_is_off)
|
|
3413 out_str(T_VI); /* disable cursor */
|
|
3414 cursor_is_off = TRUE;
|
|
3415 }
|
|
3416 }
|
|
3417
|
39
|
3418 #if defined(CURSOR_SHAPE) || defined(PROTO)
|
7
|
3419 /*
|
36
|
3420 * Set cursor shape to match Insert mode.
|
|
3421 */
|
|
3422 void
|
|
3423 term_cursor_shape()
|
|
3424 {
|
|
3425 static int showing_insert_mode = MAYBE;
|
|
3426
|
|
3427 if (!full_screen || *T_CSI == NUL || *T_CEI == NUL)
|
|
3428 return;
|
|
3429
|
|
3430 if (State & INSERT)
|
|
3431 {
|
|
3432 if (showing_insert_mode != TRUE)
|
|
3433 out_str(T_CSI); /* disable cursor */
|
|
3434 showing_insert_mode = TRUE;
|
|
3435 }
|
|
3436 else
|
|
3437 {
|
|
3438 if (showing_insert_mode != FALSE)
|
|
3439 out_str(T_CEI); /* disable cursor */
|
|
3440 showing_insert_mode = FALSE;
|
|
3441 }
|
|
3442 }
|
39
|
3443 #endif
|
36
|
3444
|
|
3445 /*
|
7
|
3446 * Set scrolling region for window 'wp'.
|
|
3447 * The region starts 'off' lines from the start of the window.
|
|
3448 * Also set the vertical scroll region for a vertically split window. Always
|
|
3449 * the full width of the window, excluding the vertical separator.
|
|
3450 */
|
|
3451 void
|
|
3452 scroll_region_set(wp, off)
|
|
3453 win_T *wp;
|
|
3454 int off;
|
|
3455 {
|
|
3456 OUT_STR(tgoto((char *)T_CS, W_WINROW(wp) + wp->w_height - 1,
|
|
3457 W_WINROW(wp) + off));
|
|
3458 #ifdef FEAT_VERTSPLIT
|
|
3459 if (*T_CSV != NUL && wp->w_width != Columns)
|
|
3460 OUT_STR(tgoto((char *)T_CSV, W_WINCOL(wp) + wp->w_width - 1,
|
|
3461 W_WINCOL(wp)));
|
|
3462 #endif
|
|
3463 screen_start(); /* don't know where cursor is now */
|
|
3464 }
|
|
3465
|
|
3466 /*
|
|
3467 * Reset scrolling region to the whole screen.
|
|
3468 */
|
|
3469 void
|
|
3470 scroll_region_reset()
|
|
3471 {
|
|
3472 OUT_STR(tgoto((char *)T_CS, (int)Rows - 1, 0));
|
|
3473 #ifdef FEAT_VERTSPLIT
|
|
3474 if (*T_CSV != NUL)
|
|
3475 OUT_STR(tgoto((char *)T_CSV, (int)Columns - 1, 0));
|
|
3476 #endif
|
|
3477 screen_start(); /* don't know where cursor is now */
|
|
3478 }
|
|
3479
|
|
3480
|
|
3481 /*
|
|
3482 * List of terminal codes that are currently recognized.
|
|
3483 */
|
|
3484
|
|
3485 struct termcode
|
|
3486 {
|
|
3487 char_u name[2]; /* termcap name of entry */
|
|
3488 char_u *code; /* terminal code (in allocated memory) */
|
|
3489 int len; /* STRLEN(code) */
|
179
|
3490 int modlen; /* length of part before ";*~". */
|
7
|
3491 } *termcodes = NULL;
|
|
3492
|
|
3493 static int tc_max_len = 0; /* number of entries that termcodes[] can hold */
|
|
3494 static int tc_len = 0; /* current number of entries in termcodes[] */
|
|
3495
|
180
|
3496 static int termcode_star __ARGS((char_u *code, int len));
|
|
3497
|
7
|
3498 void
|
|
3499 clear_termcodes()
|
|
3500 {
|
|
3501 while (tc_len > 0)
|
|
3502 vim_free(termcodes[--tc_len].code);
|
|
3503 vim_free(termcodes);
|
|
3504 termcodes = NULL;
|
|
3505 tc_max_len = 0;
|
|
3506
|
|
3507 #ifdef HAVE_TGETENT
|
|
3508 BC = (char *)empty_option;
|
|
3509 UP = (char *)empty_option;
|
|
3510 PC = NUL; /* set pad character to NUL */
|
|
3511 ospeed = 0;
|
|
3512 #endif
|
|
3513
|
|
3514 need_gather = TRUE; /* need to fill termleader[] */
|
|
3515 }
|
|
3516
|
180
|
3517 #define ATC_FROM_TERM 55
|
|
3518
|
7
|
3519 /*
|
|
3520 * Add a new entry to the list of terminal codes.
|
|
3521 * The list is kept alphabetical for ":set termcap"
|
180
|
3522 * "flags" is TRUE when replacing 7-bit by 8-bit controls is desired.
|
|
3523 * "flags" can also be ATC_FROM_TERM for got_code_from_term().
|
7
|
3524 */
|
|
3525 void
|
180
|
3526 add_termcode(name, string, flags)
|
7
|
3527 char_u *name;
|
|
3528 char_u *string;
|
180
|
3529 int flags;
|
7
|
3530 {
|
|
3531 struct termcode *new_tc;
|
|
3532 int i, j;
|
|
3533 char_u *s;
|
179
|
3534 int len;
|
7
|
3535
|
|
3536 if (string == NULL || *string == NUL)
|
|
3537 {
|
|
3538 del_termcode(name);
|
|
3539 return;
|
|
3540 }
|
|
3541
|
|
3542 s = vim_strsave(string);
|
|
3543 if (s == NULL)
|
|
3544 return;
|
|
3545
|
|
3546 /* Change leading <Esc>[ to CSI, change <Esc>O to <M-O>. */
|
180
|
3547 if (flags != 0 && flags != ATC_FROM_TERM && term_7to8bit(string) != 0)
|
7
|
3548 {
|
|
3549 mch_memmove(s, s + 1, STRLEN(s));
|
|
3550 s[0] = term_7to8bit(string);
|
|
3551 }
|
179
|
3552 len = (int)STRLEN(s);
|
7
|
3553
|
|
3554 need_gather = TRUE; /* need to fill termleader[] */
|
|
3555
|
|
3556 /*
|
|
3557 * need to make space for more entries
|
|
3558 */
|
|
3559 if (tc_len == tc_max_len)
|
|
3560 {
|
|
3561 tc_max_len += 20;
|
|
3562 new_tc = (struct termcode *)alloc(
|
|
3563 (unsigned)(tc_max_len * sizeof(struct termcode)));
|
|
3564 if (new_tc == NULL)
|
|
3565 {
|
|
3566 tc_max_len -= 20;
|
|
3567 return;
|
|
3568 }
|
|
3569 for (i = 0; i < tc_len; ++i)
|
|
3570 new_tc[i] = termcodes[i];
|
|
3571 vim_free(termcodes);
|
|
3572 termcodes = new_tc;
|
|
3573 }
|
|
3574
|
|
3575 /*
|
|
3576 * Look for existing entry with the same name, it is replaced.
|
|
3577 * Look for an existing entry that is alphabetical higher, the new entry
|
|
3578 * is inserted in front of it.
|
|
3579 */
|
|
3580 for (i = 0; i < tc_len; ++i)
|
|
3581 {
|
|
3582 if (termcodes[i].name[0] < name[0])
|
|
3583 continue;
|
|
3584 if (termcodes[i].name[0] == name[0])
|
|
3585 {
|
|
3586 if (termcodes[i].name[1] < name[1])
|
|
3587 continue;
|
|
3588 /*
|
180
|
3589 * Exact match: May replace old code.
|
7
|
3590 */
|
|
3591 if (termcodes[i].name[1] == name[1])
|
|
3592 {
|
180
|
3593 if (flags == ATC_FROM_TERM && (j = termcode_star(
|
|
3594 termcodes[i].code, termcodes[i].len)) > 0)
|
179
|
3595 {
|
180
|
3596 /* Don't replace ESC[123;*X or ESC O*X with another when
|
|
3597 * invoked from got_code_from_term(). */
|
|
3598 if (len == termcodes[i].len - j
|
179
|
3599 && STRNCMP(s, termcodes[i].code, len - 1) == 0
|
180
|
3600 && s[len - 1]
|
|
3601 == termcodes[i].code[termcodes[i].len - 1])
|
179
|
3602 {
|
180
|
3603 /* They are equal but for the ";*": don't add it. */
|
179
|
3604 vim_free(s);
|
|
3605 return;
|
|
3606 }
|
|
3607 }
|
|
3608 else
|
|
3609 {
|
180
|
3610 /* Replace old code. */
|
179
|
3611 vim_free(termcodes[i].code);
|
|
3612 --tc_len;
|
|
3613 break;
|
|
3614 }
|
7
|
3615 }
|
|
3616 }
|
|
3617 /*
|
|
3618 * Found alphabetical larger entry, move rest to insert new entry
|
|
3619 */
|
|
3620 for (j = tc_len; j > i; --j)
|
|
3621 termcodes[j] = termcodes[j - 1];
|
|
3622 break;
|
|
3623 }
|
|
3624
|
|
3625 termcodes[i].name[0] = name[0];
|
|
3626 termcodes[i].name[1] = name[1];
|
|
3627 termcodes[i].code = s;
|
179
|
3628 termcodes[i].len = len;
|
180
|
3629
|
|
3630 /* For xterm we recognize special codes like "ESC[42;*X" and "ESC O*X" that
|
|
3631 * accept modifiers. */
|
|
3632 termcodes[i].modlen = 0;
|
|
3633 j = termcode_star(s, len);
|
|
3634 if (j > 0)
|
|
3635 termcodes[i].modlen = len - 1 - j;
|
7
|
3636 ++tc_len;
|
|
3637 }
|
|
3638
|
180
|
3639 /*
|
|
3640 * Check termcode "code[len]" for ending in ;*X, <Esc>O*X or <M-O>*X.
|
|
3641 * The "X" can be any character.
|
|
3642 * Return 0 if not found, 2 for ;*X and 1 for O*X and <M-O>*X.
|
|
3643 */
|
|
3644 static int
|
|
3645 termcode_star(code, len)
|
|
3646 char_u *code;
|
|
3647 int len;
|
|
3648 {
|
|
3649 /* Shortest is <M-O>*X. With ; shortest is <CSI>1;*X */
|
|
3650 if (len >= 3 && code[len - 2] == '*')
|
|
3651 {
|
|
3652 if (len >= 5 && code[len - 3] == ';')
|
|
3653 return 2;
|
|
3654 if ((len >= 4 && code[len - 3] == 'O') || code[len - 3] == 'O' + 128)
|
|
3655 return 1;
|
|
3656 }
|
|
3657 return 0;
|
|
3658 }
|
|
3659
|
7
|
3660 char_u *
|
|
3661 find_termcode(name)
|
|
3662 char_u *name;
|
|
3663 {
|
|
3664 int i;
|
|
3665
|
|
3666 for (i = 0; i < tc_len; ++i)
|
|
3667 if (termcodes[i].name[0] == name[0] && termcodes[i].name[1] == name[1])
|
|
3668 return termcodes[i].code;
|
|
3669 return NULL;
|
|
3670 }
|
|
3671
|
|
3672 #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
|
|
3673 char_u *
|
|
3674 get_termcode(i)
|
|
3675 int i;
|
|
3676 {
|
|
3677 if (i >= tc_len)
|
|
3678 return NULL;
|
|
3679 return &termcodes[i].name[0];
|
|
3680 }
|
|
3681 #endif
|
|
3682
|
|
3683 void
|
|
3684 del_termcode(name)
|
|
3685 char_u *name;
|
|
3686 {
|
|
3687 int i;
|
|
3688
|
|
3689 if (termcodes == NULL) /* nothing there yet */
|
|
3690 return;
|
|
3691
|
|
3692 need_gather = TRUE; /* need to fill termleader[] */
|
|
3693
|
|
3694 for (i = 0; i < tc_len; ++i)
|
|
3695 if (termcodes[i].name[0] == name[0] && termcodes[i].name[1] == name[1])
|
|
3696 {
|
|
3697 del_termcode_idx(i);
|
|
3698 return;
|
|
3699 }
|
|
3700 /* not found. Give error message? */
|
|
3701 }
|
|
3702
|
|
3703 static void
|
|
3704 del_termcode_idx(idx)
|
|
3705 int idx;
|
|
3706 {
|
|
3707 int i;
|
|
3708
|
|
3709 vim_free(termcodes[idx].code);
|
|
3710 --tc_len;
|
|
3711 for (i = idx; i < tc_len; ++i)
|
|
3712 termcodes[i] = termcodes[i + 1];
|
|
3713 }
|
|
3714
|
|
3715 #ifdef FEAT_TERMRESPONSE
|
|
3716 /*
|
|
3717 * Called when detected that the terminal sends 8-bit codes.
|
|
3718 * Convert all 7-bit codes to their 8-bit equivalent.
|
|
3719 */
|
|
3720 static void
|
|
3721 switch_to_8bit()
|
|
3722 {
|
|
3723 int i;
|
|
3724 int c;
|
|
3725
|
|
3726 /* Only need to do something when not already using 8-bit codes. */
|
|
3727 if (!term_is_8bit(T_NAME))
|
|
3728 {
|
|
3729 for (i = 0; i < tc_len; ++i)
|
|
3730 {
|
|
3731 c = term_7to8bit(termcodes[i].code);
|
|
3732 if (c != 0)
|
|
3733 {
|
|
3734 mch_memmove(termcodes[i].code + 1, termcodes[i].code + 2,
|
|
3735 STRLEN(termcodes[i].code + 1));
|
|
3736 termcodes[i].code[0] = c;
|
|
3737 }
|
|
3738 }
|
|
3739 need_gather = TRUE; /* need to fill termleader[] */
|
|
3740 }
|
|
3741 detected_8bit = TRUE;
|
|
3742 }
|
|
3743 #endif
|
|
3744
|
|
3745 #ifdef CHECK_DOUBLE_CLICK
|
|
3746 static linenr_T orig_topline = 0;
|
|
3747 # ifdef FEAT_DIFF
|
|
3748 static int orig_topfill = 0;
|
|
3749 # endif
|
|
3750 #endif
|
|
3751 #if (defined(FEAT_WINDOWS) && defined(CHECK_DOUBLE_CLICK)) || defined(PROTO)
|
|
3752 /*
|
|
3753 * Checking for double clicks ourselves.
|
|
3754 * "orig_topline" is used to avoid detecting a double-click when the window
|
|
3755 * contents scrolled (e.g., when 'scrolloff' is non-zero).
|
|
3756 */
|
|
3757 /*
|
|
3758 * Set orig_topline. Used when jumping to another window, so that a double
|
|
3759 * click still works.
|
|
3760 */
|
|
3761 void
|
|
3762 set_mouse_topline(wp)
|
|
3763 win_T *wp;
|
|
3764 {
|
|
3765 orig_topline = wp->w_topline;
|
|
3766 # ifdef FEAT_DIFF
|
|
3767 orig_topfill = wp->w_topfill;
|
|
3768 # endif
|
|
3769 }
|
|
3770 #endif
|
|
3771
|
|
3772 /*
|
|
3773 * Check if typebuf.tb_buf[] contains a terminal key code.
|
|
3774 * Check from typebuf.tb_buf[typebuf.tb_off] to typebuf.tb_buf[typebuf.tb_off
|
|
3775 * + max_offset].
|
|
3776 * Return 0 for no match, -1 for partial match, > 0 for full match.
|
|
3777 * With a match, the match is removed, the replacement code is inserted in
|
|
3778 * typebuf.tb_buf[] and the number of characters in typebuf.tb_buf[] is
|
|
3779 * returned.
|
|
3780 * When "buf" is not NULL, it is used instead of typebuf.tb_buf[]. "buflen" is
|
|
3781 * then the length of the string in buf[].
|
|
3782 */
|
|
3783 int
|
|
3784 check_termcode(max_offset, buf, buflen)
|
|
3785 int max_offset;
|
|
3786 char_u *buf;
|
|
3787 int buflen;
|
|
3788 {
|
|
3789 char_u *tp;
|
|
3790 char_u *p;
|
|
3791 int slen = 0; /* init for GCC */
|
180
|
3792 int modslen;
|
7
|
3793 int len;
|
|
3794 int offset;
|
|
3795 char_u key_name[2];
|
180
|
3796 int modifiers;
|
|
3797 int key;
|
7
|
3798 int new_slen;
|
|
3799 int extra;
|
|
3800 char_u string[MAX_KEY_CODE_LEN + 1];
|
|
3801 int i, j;
|
|
3802 int idx = 0;
|
|
3803 #ifdef FEAT_MOUSE
|
|
3804 # if !defined(UNIX) || defined(FEAT_MOUSE_XTERM) || defined(FEAT_GUI)
|
|
3805 char_u bytes[6];
|
|
3806 int num_bytes;
|
|
3807 # endif
|
|
3808 int mouse_code = 0; /* init for GCC */
|
|
3809 int is_click, is_drag;
|
|
3810 int wheel_code = 0;
|
|
3811 int current_button;
|
|
3812 static int held_button = MOUSE_RELEASE;
|
|
3813 static int orig_num_clicks = 1;
|
|
3814 static int orig_mouse_code = 0x0;
|
|
3815 # ifdef CHECK_DOUBLE_CLICK
|
|
3816 static int orig_mouse_col = 0;
|
|
3817 static int orig_mouse_row = 0;
|
|
3818 static struct timeval orig_mouse_time = {0, 0};
|
|
3819 /* time of previous mouse click */
|
|
3820 struct timeval mouse_time; /* time of current mouse click */
|
|
3821 long timediff; /* elapsed time in msec */
|
|
3822 # endif
|
|
3823 #endif
|
|
3824 int cpo_koffset;
|
|
3825 #ifdef FEAT_MOUSE_GPM
|
|
3826 extern int gpm_flag; /* gpm library variable */
|
|
3827 #endif
|
|
3828
|
|
3829 cpo_koffset = (vim_strchr(p_cpo, CPO_KOFFSET) != NULL);
|
|
3830
|
|
3831 /*
|
|
3832 * Speed up the checks for terminal codes by gathering all first bytes
|
|
3833 * used in termleader[]. Often this is just a single <Esc>.
|
|
3834 */
|
|
3835 if (need_gather)
|
|
3836 gather_termleader();
|
|
3837
|
|
3838 /*
|
|
3839 * Check at several positions in typebuf.tb_buf[], to catch something like
|
|
3840 * "x<Up>" that can be mapped. Stop at max_offset, because characters
|
|
3841 * after that cannot be used for mapping, and with @r commands
|
|
3842 * typebuf.tb_buf[]
|
|
3843 * can become very long.
|
|
3844 * This is used often, KEEP IT FAST!
|
|
3845 */
|
|
3846 for (offset = 0; offset < max_offset; ++offset)
|
|
3847 {
|
|
3848 if (buf == NULL)
|
|
3849 {
|
|
3850 if (offset >= typebuf.tb_len)
|
|
3851 break;
|
|
3852 tp = typebuf.tb_buf + typebuf.tb_off + offset;
|
|
3853 len = typebuf.tb_len - offset; /* length of the input */
|
|
3854 }
|
|
3855 else
|
|
3856 {
|
|
3857 if (offset >= buflen)
|
|
3858 break;
|
|
3859 tp = buf + offset;
|
|
3860 len = buflen - offset;
|
|
3861 }
|
|
3862
|
|
3863 /*
|
|
3864 * Don't check characters after K_SPECIAL, those are already
|
|
3865 * translated terminal chars (avoid translating ~@^Hx).
|
|
3866 */
|
|
3867 if (*tp == K_SPECIAL)
|
|
3868 {
|
|
3869 offset += 2; /* there are always 2 extra characters */
|
|
3870 continue;
|
|
3871 }
|
|
3872
|
|
3873 /*
|
|
3874 * Skip this position if the character does not appear as the first
|
|
3875 * character in term_strings. This speeds up a lot, since most
|
|
3876 * termcodes start with the same character (ESC or CSI).
|
|
3877 */
|
|
3878 i = *tp;
|
|
3879 for (p = termleader; *p && *p != i; ++p)
|
|
3880 ;
|
|
3881 if (*p == NUL)
|
|
3882 continue;
|
|
3883
|
|
3884 /*
|
|
3885 * Skip this position if p_ek is not set and tp[0] is an ESC and we
|
|
3886 * are in Insert mode.
|
|
3887 */
|
|
3888 if (*tp == ESC && !p_ek && (State & INSERT))
|
|
3889 continue;
|
|
3890
|
|
3891 key_name[0] = NUL; /* no key name found yet */
|
180
|
3892 modifiers = 0; /* no modifiers yet */
|
7
|
3893
|
|
3894 #ifdef FEAT_GUI
|
|
3895 if (gui.in_use)
|
|
3896 {
|
|
3897 /*
|
|
3898 * GUI special key codes are all of the form [CSI xx].
|
|
3899 */
|
|
3900 if (*tp == CSI) /* Special key from GUI */
|
|
3901 {
|
|
3902 if (len < 3)
|
|
3903 return -1; /* Shouldn't happen */
|
|
3904 slen = 3;
|
|
3905 key_name[0] = tp[1];
|
|
3906 key_name[1] = tp[2];
|
|
3907 }
|
|
3908 }
|
|
3909 else
|
|
3910 #endif /* FEAT_GUI */
|
|
3911 {
|
|
3912 for (idx = 0; idx < tc_len; ++idx)
|
|
3913 {
|
|
3914 /*
|
|
3915 * Ignore the entry if we are not at the start of
|
|
3916 * typebuf.tb_buf[]
|
|
3917 * and there are not enough characters to make a match.
|
|
3918 * But only when the 'K' flag is in 'cpoptions'.
|
|
3919 */
|
|
3920 slen = termcodes[idx].len;
|
|
3921 if (cpo_koffset && offset && len < slen)
|
|
3922 continue;
|
|
3923 if (STRNCMP(termcodes[idx].code, tp,
|
|
3924 (size_t)(slen > len ? len : slen)) == 0)
|
|
3925 {
|
|
3926 if (len < slen) /* got a partial sequence */
|
|
3927 return -1; /* need to get more chars */
|
|
3928
|
|
3929 /*
|
|
3930 * When found a keypad key, check if there is another key
|
|
3931 * that matches and use that one. This makes <Home> to be
|
|
3932 * found instead of <kHome> when they produce the same
|
|
3933 * key code.
|
|
3934 */
|
|
3935 if (termcodes[idx].name[0] == 'K'
|
|
3936 && VIM_ISDIGIT(termcodes[idx].name[1]))
|
|
3937 {
|
|
3938 for (j = idx + 1; j < tc_len; ++j)
|
|
3939 if (termcodes[j].len == slen &&
|
|
3940 STRNCMP(termcodes[idx].code,
|
|
3941 termcodes[j].code, slen) == 0)
|
|
3942 {
|
|
3943 idx = j;
|
|
3944 break;
|
|
3945 }
|
|
3946 }
|
|
3947
|
|
3948 key_name[0] = termcodes[idx].name[0];
|
|
3949 key_name[1] = termcodes[idx].name[1];
|
|
3950 break;
|
|
3951 }
|
179
|
3952
|
|
3953 /*
|
|
3954 * Check for code with modifier, like xterm uses:
|
180
|
3955 * <Esc>[123;*X (modslen == slen - 3)
|
|
3956 * Also <Esc>O*X and <M-O>*X (modslen == slen - 2).
|
|
3957 * When there is a modifier the * matches a number.
|
|
3958 * When there is no modifier the ;* or * is omitted.
|
179
|
3959 */
|
|
3960 if (termcodes[idx].modlen > 0)
|
|
3961 {
|
180
|
3962 modslen = termcodes[idx].modlen;
|
|
3963 if (cpo_koffset && offset && len < modslen)
|
179
|
3964 continue;
|
|
3965 if (STRNCMP(termcodes[idx].code, tp,
|
180
|
3966 (size_t)(modslen > len ? len : modslen)) == 0)
|
179
|
3967 {
|
|
3968 int n;
|
180
|
3969
|
|
3970 if (len <= modslen) /* got a partial sequence */
|
179
|
3971 return -1; /* need to get more chars */
|
|
3972
|
180
|
3973 if (tp[modslen] == termcodes[idx].code[slen - 1])
|
|
3974 slen = modslen + 1; /* no modifiers */
|
|
3975 else if (tp[modslen] != ';' && modslen == slen - 3)
|
179
|
3976 continue; /* no match */
|
|
3977 else
|
|
3978 {
|
|
3979 /* Skip over the digits, the final char must
|
|
3980 * follow. */
|
180
|
3981 for (j = slen - 2; j < len && isdigit(tp[j]); ++j)
|
179
|
3982 ;
|
|
3983 ++j;
|
|
3984 if (len < j) /* got a partial sequence */
|
|
3985 return -1; /* need to get more chars */
|
180
|
3986 if (tp[j - 1] != termcodes[idx].code[slen - 1])
|
|
3987 continue; /* no match */
|
179
|
3988
|
|
3989 /* Match! Convert modifier bits. */
|
180
|
3990 n = atoi((char *)tp + slen - 2) - 1;
|
179
|
3991 if (n & 1)
|
180
|
3992 modifiers |= MOD_MASK_SHIFT;
|
179
|
3993 if (n & 2)
|
180
|
3994 modifiers |= MOD_MASK_ALT;
|
179
|
3995 if (n & 4)
|
180
|
3996 modifiers |= MOD_MASK_CTRL;
|
179
|
3997 if (n & 8)
|
180
|
3998 modifiers |= MOD_MASK_META;
|
179
|
3999
|
|
4000 slen = j;
|
|
4001 }
|
|
4002 key_name[0] = termcodes[idx].name[0];
|
|
4003 key_name[1] = termcodes[idx].name[1];
|
|
4004 break;
|
|
4005 }
|
|
4006 }
|
7
|
4007 }
|
|
4008 }
|
|
4009
|
|
4010 #ifdef FEAT_TERMRESPONSE
|
|
4011 if (key_name[0] == NUL)
|
|
4012 {
|
|
4013 /* Check for xterm version string: "<Esc>[>{x};{vers};{y}c". Also
|
|
4014 * eat other possible responses to t_RV, rxvt returns
|
|
4015 * "<Esc>[?1;2c". Also accept CSI instead of <Esc>[. */
|
|
4016 if (*T_CRV != NUL && ((tp[0] == ESC && tp[1] == '[' && len >= 3)
|
|
4017 || (tp[0] == CSI && len >= 2)))
|
|
4018 {
|
|
4019 j = 0;
|
|
4020 extra = 0;
|
|
4021 for (i = 2 + (tp[0] != CSI);
|
|
4022 i < len && (VIM_ISDIGIT(tp[i])
|
|
4023 || tp[i] == ';' || tp[i] == '.'); ++i)
|
|
4024 if (tp[i] == ';' && ++j == 1)
|
|
4025 extra = atoi((char *)tp + i + 1);
|
|
4026 if (i == len)
|
|
4027 return -1; /* not enough characters */
|
|
4028
|
|
4029 /* eat it when at least one digit and ending in 'c' */
|
|
4030 if (i > 2 + (tp[0] != CSI) && tp[i] == 'c')
|
|
4031 {
|
|
4032 crv_status = CRV_GOT;
|
|
4033
|
|
4034 /* If this code starts with CSI, you can bet that the
|
|
4035 * terminal uses 8-bit codes. */
|
|
4036 if (tp[0] == CSI)
|
|
4037 switch_to_8bit();
|
|
4038
|
|
4039 /* rxvt sends its version number: "20703" is 2.7.3.
|
|
4040 * Ignore it for when the user has set 'term' to xterm,
|
|
4041 * even though it's an rxvt. */
|
|
4042 if (extra > 20000)
|
|
4043 extra = 0;
|
|
4044
|
|
4045 if (tp[1 + (tp[0] != CSI)] == '>' && j == 2)
|
|
4046 {
|
|
4047 /* if xterm version >= 95 use mouse dragging */
|
|
4048 if (extra >= 95)
|
|
4049 set_option_value((char_u *)"ttym", 0L,
|
|
4050 (char_u *)"xterm2", 0);
|
|
4051 /* if xterm version >= 141 try to get termcap codes */
|
|
4052 if (extra >= 141)
|
|
4053 {
|
|
4054 check_for_codes = TRUE;
|
|
4055 need_gather = TRUE;
|
|
4056 req_codes_from_term();
|
|
4057 }
|
|
4058 }
|
|
4059 # ifdef FEAT_EVAL
|
|
4060 set_vim_var_string(VV_TERMRESPONSE, tp, i + 1);
|
|
4061 # endif
|
|
4062 # ifdef FEAT_AUTOCMD
|
|
4063 apply_autocmds(EVENT_TERMRESPONSE,
|
|
4064 NULL, NULL, FALSE, curbuf);
|
|
4065 # endif
|
|
4066 key_name[0] = (int)KS_EXTRA;
|
|
4067 key_name[1] = (int)KE_IGNORE;
|
|
4068 slen = i + 1;
|
|
4069 }
|
|
4070 }
|
|
4071
|
|
4072 /* Check for '<Esc>P1+r<hex bytes><Esc>\'. A "0" instead of the
|
|
4073 * "1" means an invalid request. */
|
|
4074 else if (check_for_codes
|
|
4075 && ((tp[0] == ESC && tp[1] == 'P' && len >= 2)
|
|
4076 || tp[0] == DCS))
|
|
4077 {
|
|
4078 j = 1 + (tp[0] != DCS);
|
|
4079 for (i = j; i < len; ++i)
|
|
4080 if ((tp[i] == ESC && tp[i + 1] == '\\' && i + 1 < len)
|
|
4081 || tp[i] == STERM)
|
|
4082 {
|
|
4083 if (i - j >= 3 && tp[j + 1] == '+' && tp[j + 2] == 'r')
|
|
4084 got_code_from_term(tp + j, i);
|
|
4085 key_name[0] = (int)KS_EXTRA;
|
|
4086 key_name[1] = (int)KE_IGNORE;
|
|
4087 slen = i + 1 + (tp[i] == ESC);
|
|
4088 break;
|
|
4089 }
|
|
4090
|
|
4091 if (i == len)
|
|
4092 return -1; /* not enough characters */
|
|
4093 }
|
|
4094 }
|
|
4095 #endif
|
|
4096
|
|
4097 if (key_name[0] == NUL)
|
|
4098 continue; /* No match at this position, try next one */
|
|
4099
|
|
4100 /* We only get here when we have a complete termcode match */
|
|
4101
|
|
4102 #ifdef FEAT_MOUSE
|
|
4103 # ifdef FEAT_GUI
|
|
4104 /*
|
|
4105 * Only in the GUI: Fetch the pointer coordinates of the scroll event
|
|
4106 * so that we know which window to scroll later.
|
|
4107 */
|
|
4108 if (gui.in_use
|
|
4109 && key_name[0] == (int)KS_EXTRA
|
|
4110 && (key_name[1] == (int)KE_X1MOUSE
|
|
4111 || key_name[1] == (int)KE_X2MOUSE
|
|
4112 || key_name[1] == (int)KE_MOUSEDOWN
|
|
4113 || key_name[1] == (int)KE_MOUSEUP))
|
|
4114 {
|
|
4115 num_bytes = get_bytes_from_buf(tp + slen, bytes, 4);
|
|
4116 if (num_bytes == -1) /* not enough coordinates */
|
|
4117 return -1;
|
|
4118 mouse_col = 128 * (bytes[0] - ' ' - 1) + bytes[1] - ' ' - 1;
|
|
4119 mouse_row = 128 * (bytes[2] - ' ' - 1) + bytes[3] - ' ' - 1;
|
|
4120 slen += num_bytes;
|
|
4121 }
|
|
4122 else
|
|
4123 # endif
|
|
4124 /*
|
|
4125 * If it is a mouse click, get the coordinates.
|
|
4126 */
|
|
4127 if (key_name[0] == (int)KS_MOUSE
|
|
4128 # ifdef FEAT_MOUSE_JSB
|
|
4129 || key_name[0] == (int)KS_JSBTERM_MOUSE
|
|
4130 # endif
|
|
4131 # ifdef FEAT_MOUSE_NET
|
|
4132 || key_name[0] == (int)KS_NETTERM_MOUSE
|
|
4133 # endif
|
|
4134 # ifdef FEAT_MOUSE_DEC
|
|
4135 || key_name[0] == (int)KS_DEC_MOUSE
|
|
4136 # endif
|
|
4137 # ifdef FEAT_MOUSE_PTERM
|
|
4138 || key_name[0] == (int)KS_PTERM_MOUSE
|
|
4139 # endif
|
|
4140 )
|
|
4141 {
|
|
4142 is_click = is_drag = FALSE;
|
|
4143
|
|
4144 # if !defined(UNIX) || defined(FEAT_MOUSE_XTERM) || defined(FEAT_GUI)
|
|
4145 if (key_name[0] == (int)KS_MOUSE)
|
|
4146 {
|
|
4147 /*
|
|
4148 * For xterm and MSDOS we get "<t_mouse>scr", where
|
|
4149 * s == encoded button state:
|
|
4150 * 0x20 = left button down
|
|
4151 * 0x21 = middle button down
|
|
4152 * 0x22 = right button down
|
|
4153 * 0x23 = any button release
|
|
4154 * 0x60 = button 4 down (scroll wheel down)
|
|
4155 * 0x61 = button 5 down (scroll wheel up)
|
|
4156 * add 0x04 for SHIFT
|
|
4157 * add 0x08 for ALT
|
|
4158 * add 0x10 for CTRL
|
|
4159 * add 0x20 for mouse drag (0x40 is drag with left button)
|
|
4160 * c == column + ' ' + 1 == column + 33
|
|
4161 * r == row + ' ' + 1 == row + 33
|
|
4162 *
|
|
4163 * The coordinates are passed on through global variables.
|
|
4164 * Ugly, but this avoids trouble with mouse clicks at an
|
|
4165 * unexpected moment and allows for mapping them.
|
|
4166 */
|
|
4167 for (;;)
|
|
4168 {
|
|
4169 #ifdef FEAT_GUI
|
|
4170 if (gui.in_use)
|
|
4171 {
|
|
4172 /* GUI uses more bits for columns > 223 */
|
|
4173 num_bytes = get_bytes_from_buf(tp + slen, bytes, 5);
|
|
4174 if (num_bytes == -1) /* not enough coordinates */
|
|
4175 return -1;
|
|
4176 mouse_code = bytes[0];
|
|
4177 mouse_col = 128 * (bytes[1] - ' ' - 1)
|
|
4178 + bytes[2] - ' ' - 1;
|
|
4179 mouse_row = 128 * (bytes[3] - ' ' - 1)
|
|
4180 + bytes[4] - ' ' - 1;
|
|
4181 }
|
|
4182 else
|
|
4183 #endif
|
|
4184 {
|
|
4185 num_bytes = get_bytes_from_buf(tp + slen, bytes, 3);
|
|
4186 if (num_bytes == -1) /* not enough coordinates */
|
|
4187 return -1;
|
|
4188 mouse_code = bytes[0];
|
|
4189 mouse_col = bytes[1] - ' ' - 1;
|
|
4190 mouse_row = bytes[2] - ' ' - 1;
|
|
4191 }
|
|
4192 slen += num_bytes;
|
|
4193
|
|
4194 /* If the following bytes is also a mouse code and it has
|
|
4195 * the same code, dump this one and get the next. This
|
|
4196 * makes dragging a whole lot faster. */
|
|
4197 #ifdef FEAT_GUI
|
|
4198 if (gui.in_use)
|
|
4199 j = 3;
|
|
4200 else
|
|
4201 #endif
|
|
4202 j = termcodes[idx].len;
|
|
4203 if (STRNCMP(tp, tp + slen, (size_t)j) == 0
|
|
4204 && tp[slen + j] == mouse_code
|
|
4205 && tp[slen + j + 1] != NUL
|
|
4206 && tp[slen + j + 2] != NUL
|
|
4207 #ifdef FEAT_GUI
|
|
4208 && (!gui.in_use
|
|
4209 || (tp[slen + j + 3] != NUL
|
|
4210 && tp[slen + j + 4] != NUL))
|
|
4211 #endif
|
|
4212 )
|
|
4213 slen += j;
|
|
4214 else
|
|
4215 break;
|
|
4216 }
|
|
4217
|
|
4218 # if !defined(MSWIN) && !defined(MSDOS)
|
|
4219 /*
|
|
4220 * Handle mouse events.
|
|
4221 * Recognize the xterm mouse wheel, but not in the GUI, the
|
|
4222 * Linux console with GPM and the MS-DOS or Win32 console
|
|
4223 * (multi-clicks use >= 0x60).
|
|
4224 */
|
|
4225 if (mouse_code >= MOUSEWHEEL_LOW
|
|
4226 # ifdef FEAT_GUI
|
|
4227 && !gui.in_use
|
|
4228 # endif
|
|
4229 # ifdef FEAT_MOUSE_GPM
|
|
4230 && gpm_flag == 0
|
|
4231 # endif
|
|
4232 )
|
|
4233 {
|
|
4234 /* Keep the mouse_code before it's changed, so that we
|
|
4235 * remember that it was a mouse wheel click. */
|
|
4236 wheel_code = mouse_code;
|
|
4237 }
|
|
4238 # ifdef FEAT_MOUSE_XTERM
|
|
4239 else if (held_button == MOUSE_RELEASE
|
|
4240 # ifdef FEAT_GUI
|
|
4241 && !gui.in_use
|
|
4242 # endif
|
|
4243 && (mouse_code == 0x23 || mouse_code == 0x24))
|
|
4244 {
|
|
4245 /* Apparently used by rxvt scroll wheel. */
|
|
4246 wheel_code = mouse_code - 0x23 + MOUSEWHEEL_LOW;
|
|
4247 }
|
|
4248 # endif
|
|
4249
|
|
4250 # if defined(UNIX) && defined(FEAT_MOUSE_TTY)
|
|
4251 else if (use_xterm_mouse() > 1)
|
|
4252 {
|
|
4253 if (mouse_code & MOUSE_DRAG_XTERM)
|
|
4254 mouse_code |= MOUSE_DRAG;
|
|
4255 }
|
|
4256 # endif
|
|
4257 # ifdef FEAT_XCLIPBOARD
|
|
4258 else if (!(mouse_code & MOUSE_DRAG & ~MOUSE_CLICK_MASK))
|
|
4259 {
|
|
4260 if ((mouse_code & MOUSE_RELEASE) == MOUSE_RELEASE)
|
|
4261 stop_xterm_trace();
|
|
4262 else
|
|
4263 start_xterm_trace(mouse_code);
|
|
4264 }
|
|
4265 # endif
|
|
4266 # endif
|
|
4267 }
|
|
4268 # endif /* !UNIX || FEAT_MOUSE_XTERM */
|
|
4269 # ifdef FEAT_MOUSE_NET
|
|
4270 if (key_name[0] == (int)KS_NETTERM_MOUSE)
|
|
4271 {
|
|
4272 int mc, mr;
|
|
4273
|
|
4274 /* expect a rather limited sequence like: balancing {
|
|
4275 * \033}6,45\r
|
|
4276 * '6' is the row, 45 is the column
|
|
4277 */
|
|
4278 p = tp + slen;
|
|
4279 mr = getdigits(&p);
|
|
4280 if (*p++ != ',')
|
|
4281 return -1;
|
|
4282 mc = getdigits(&p);
|
|
4283 if (*p++ != '\r')
|
|
4284 return -1;
|
|
4285
|
|
4286 mouse_col = mc - 1;
|
|
4287 mouse_row = mr - 1;
|
|
4288 mouse_code = MOUSE_LEFT;
|
|
4289 slen += (int)(p - (tp + slen));
|
|
4290 }
|
|
4291 # endif /* FEAT_MOUSE_NET */
|
|
4292 # ifdef FEAT_MOUSE_JSB
|
|
4293 if (key_name[0] == (int)KS_JSBTERM_MOUSE)
|
|
4294 {
|
|
4295 int mult, val, iter, button, status;
|
|
4296
|
|
4297 /* JSBTERM Input Model
|
|
4298 * \033[0~zw uniq escape sequence
|
|
4299 * (L-x) Left button pressed - not pressed x not reporting
|
|
4300 * (M-x) Middle button pressed - not pressed x not reporting
|
|
4301 * (R-x) Right button pressed - not pressed x not reporting
|
|
4302 * (SDmdu) Single , Double click, m mouse move d button down
|
|
4303 * u button up
|
|
4304 * ### X cursor position padded to 3 digits
|
|
4305 * ### Y cursor position padded to 3 digits
|
|
4306 * (s-x) SHIFT key pressed - not pressed x not reporting
|
|
4307 * (c-x) CTRL key pressed - not pressed x not reporting
|
|
4308 * \033\\ terminateing sequence
|
|
4309 */
|
|
4310
|
|
4311 p = tp + slen;
|
|
4312 button = mouse_code = 0;
|
|
4313 switch (*p++)
|
|
4314 {
|
|
4315 case 'L': button = 1; break;
|
|
4316 case '-': break;
|
|
4317 case 'x': break; /* ignore sequence */
|
|
4318 default: return -1; /* Unknown Result */
|
|
4319 }
|
|
4320 switch (*p++)
|
|
4321 {
|
|
4322 case 'M': button |= 2; break;
|
|
4323 case '-': break;
|
|
4324 case 'x': break; /* ignore sequence */
|
|
4325 default: return -1; /* Unknown Result */
|
|
4326 }
|
|
4327 switch (*p++)
|
|
4328 {
|
|
4329 case 'R': button |= 4; break;
|
|
4330 case '-': break;
|
|
4331 case 'x': break; /* ignore sequence */
|
|
4332 default: return -1; /* Unknown Result */
|
|
4333 }
|
|
4334 status = *p++;
|
|
4335 for (val = 0, mult = 100, iter = 0; iter < 3; iter++,
|
|
4336 mult /= 10, p++)
|
|
4337 if (*p >= '0' && *p <= '9')
|
|
4338 val += (*p - '0') * mult;
|
|
4339 else
|
|
4340 return -1;
|
|
4341 mouse_col = val;
|
|
4342 for (val = 0, mult = 100, iter = 0; iter < 3; iter++,
|
|
4343 mult /= 10, p++)
|
|
4344 if (*p >= '0' && *p <= '9')
|
|
4345 val += (*p - '0') * mult;
|
|
4346 else
|
|
4347 return -1;
|
|
4348 mouse_row = val;
|
|
4349 switch (*p++)
|
|
4350 {
|
|
4351 case 's': button |= 8; break; /* SHIFT key Pressed */
|
|
4352 case '-': break; /* Not Pressed */
|
|
4353 case 'x': break; /* Not Reporting */
|
|
4354 default: return -1; /* Unknown Result */
|
|
4355 }
|
|
4356 switch (*p++)
|
|
4357 {
|
|
4358 case 'c': button |= 16; break; /* CTRL key Pressed */
|
|
4359 case '-': break; /* Not Pressed */
|
|
4360 case 'x': break; /* Not Reporting */
|
|
4361 default: return -1; /* Unknown Result */
|
|
4362 }
|
|
4363 if (*p++ != '\033')
|
|
4364 return -1;
|
|
4365 if (*p++ != '\\')
|
|
4366 return -1;
|
|
4367 switch (status)
|
|
4368 {
|
|
4369 case 'D': /* Double Click */
|
|
4370 case 'S': /* Single Click */
|
|
4371 if (button & 1) mouse_code |= MOUSE_LEFT;
|
|
4372 if (button & 2) mouse_code |= MOUSE_MIDDLE;
|
|
4373 if (button & 4) mouse_code |= MOUSE_RIGHT;
|
|
4374 if (button & 8) mouse_code |= MOUSE_SHIFT;
|
|
4375 if (button & 16) mouse_code |= MOUSE_CTRL;
|
|
4376 break;
|
|
4377 case 'm': /* Mouse move */
|
|
4378 if (button & 1) mouse_code |= MOUSE_LEFT;
|
|
4379 if (button & 2) mouse_code |= MOUSE_MIDDLE;
|
|
4380 if (button & 4) mouse_code |= MOUSE_RIGHT;
|
|
4381 if (button & 8) mouse_code |= MOUSE_SHIFT;
|
|
4382 if (button & 16) mouse_code |= MOUSE_CTRL;
|
|
4383 if ((button & 7) != 0)
|
|
4384 {
|
|
4385 held_button = mouse_code;
|
|
4386 mouse_code |= MOUSE_DRAG;
|
|
4387 }
|
|
4388 is_drag = TRUE;
|
|
4389 showmode();
|
|
4390 break;
|
|
4391 case 'd': /* Button Down */
|
|
4392 if (button & 1) mouse_code |= MOUSE_LEFT;
|
|
4393 if (button & 2) mouse_code |= MOUSE_MIDDLE;
|
|
4394 if (button & 4) mouse_code |= MOUSE_RIGHT;
|
|
4395 if (button & 8) mouse_code |= MOUSE_SHIFT;
|
|
4396 if (button & 16) mouse_code |= MOUSE_CTRL;
|
|
4397 break;
|
|
4398 case 'u': /* Button Up */
|
|
4399 if (button & 1)
|
|
4400 mouse_code |= MOUSE_LEFT | MOUSE_RELEASE;
|
|
4401 if (button & 2)
|
|
4402 mouse_code |= MOUSE_MIDDLE | MOUSE_RELEASE;
|
|
4403 if (button & 4)
|
|
4404 mouse_code |= MOUSE_RIGHT | MOUSE_RELEASE;
|
|
4405 if (button & 8)
|
|
4406 mouse_code |= MOUSE_SHIFT;
|
|
4407 if (button & 16)
|
|
4408 mouse_code |= MOUSE_CTRL;
|
|
4409 break;
|
|
4410 default: return -1; /* Unknown Result */
|
|
4411 }
|
|
4412
|
|
4413 slen += (p - (tp + slen));
|
|
4414 }
|
|
4415 # endif /* FEAT_MOUSE_JSB */
|
|
4416 # ifdef FEAT_MOUSE_DEC
|
|
4417 if (key_name[0] == (int)KS_DEC_MOUSE)
|
|
4418 {
|
|
4419 /* The DEC Locator Input Model
|
|
4420 * Netterm delivers the code sequence:
|
|
4421 * \033[2;4;24;80&w (left button down)
|
|
4422 * \033[3;0;24;80&w (left button up)
|
|
4423 * \033[6;1;24;80&w (right button down)
|
|
4424 * \033[7;0;24;80&w (right button up)
|
|
4425 * CSI Pe ; Pb ; Pr ; Pc ; Pp & w
|
|
4426 * Pe is the event code
|
|
4427 * Pb is the button code
|
|
4428 * Pr is the row coordinate
|
|
4429 * Pc is the column coordinate
|
|
4430 * Pp is the third coordinate (page number)
|
|
4431 * Pe, the event code indicates what event caused this report
|
|
4432 * The following event codes are defined:
|
|
4433 * 0 - request, the terminal received an explicit request
|
|
4434 * for a locator report, but the locator is unavailable
|
|
4435 * 1 - request, the terminal received an explicit request
|
|
4436 * for a locator report
|
|
4437 * 2 - left button down
|
|
4438 * 3 - left button up
|
|
4439 * 4 - middle button down
|
|
4440 * 5 - middle button up
|
|
4441 * 6 - right button down
|
|
4442 * 7 - right button up
|
|
4443 * 8 - fourth button down
|
|
4444 * 9 - fourth button up
|
|
4445 * 10 - locator outside filter rectangle
|
|
4446 * Pb, the button code, ASCII decimal 0-15 indicating which
|
|
4447 * buttons are down if any. The state of the four buttons
|
|
4448 * on the locator correspond to the low four bits of the
|
|
4449 * decimal value,
|
|
4450 * "1" means button depressed
|
|
4451 * 0 - no buttons down,
|
|
4452 * 1 - right,
|
|
4453 * 2 - middle,
|
|
4454 * 4 - left,
|
|
4455 * 8 - fourth
|
|
4456 * Pr is the row coordinate of the locator position in the page,
|
|
4457 * encoded as an ASCII decimal value.
|
|
4458 * If Pr is omitted, the locator position is undefined
|
|
4459 * (outside the terminal window for example).
|
|
4460 * Pc is the column coordinate of the locator position in the
|
|
4461 * page, encoded as an ASCII decimal value.
|
|
4462 * If Pc is omitted, the locator position is undefined
|
|
4463 * (outside the terminal window for example).
|
|
4464 * Pp is the page coordinate of the locator position
|
|
4465 * encoded as an ASCII decimal value.
|
|
4466 * The page coordinate may be omitted if the locator is on
|
|
4467 * page one (the default). We ignore it anyway.
|
|
4468 */
|
|
4469 int Pe, Pb, Pr, Pc;
|
|
4470
|
|
4471 p = tp + slen;
|
|
4472
|
|
4473 /* get event status */
|
|
4474 Pe = getdigits(&p);
|
|
4475 if (*p++ != ';')
|
|
4476 return -1;
|
|
4477
|
|
4478 /* get button status */
|
|
4479 Pb = getdigits(&p);
|
|
4480 if (*p++ != ';')
|
|
4481 return -1;
|
|
4482
|
|
4483 /* get row status */
|
|
4484 Pr = getdigits(&p);
|
|
4485 if (*p++ != ';')
|
|
4486 return -1;
|
|
4487
|
|
4488 /* get column status */
|
|
4489 Pc = getdigits(&p);
|
|
4490
|
|
4491 /* the page parameter is optional */
|
|
4492 if (*p == ';')
|
|
4493 {
|
|
4494 p++;
|
|
4495 (void)getdigits(&p);
|
|
4496 }
|
|
4497 if (*p++ != '&')
|
|
4498 return -1;
|
|
4499 if (*p++ != 'w')
|
|
4500 return -1;
|
|
4501
|
|
4502 mouse_code = 0;
|
|
4503 switch (Pe)
|
|
4504 {
|
|
4505 case 0: return -1; /* position request while unavailable */
|
|
4506 case 1: /* a response to a locator position request includes
|
|
4507 the status of all buttons */
|
|
4508 Pb &= 7; /* mask off and ignore fourth button */
|
|
4509 if (Pb & 4)
|
|
4510 mouse_code = MOUSE_LEFT;
|
|
4511 if (Pb & 2)
|
|
4512 mouse_code = MOUSE_MIDDLE;
|
|
4513 if (Pb & 1)
|
|
4514 mouse_code = MOUSE_RIGHT;
|
|
4515 if (Pb)
|
|
4516 {
|
|
4517 held_button = mouse_code;
|
|
4518 mouse_code |= MOUSE_DRAG;
|
|
4519 WantQueryMouse = 1;
|
|
4520 }
|
|
4521 is_drag = TRUE;
|
|
4522 showmode();
|
|
4523 break;
|
|
4524 case 2: mouse_code = MOUSE_LEFT;
|
|
4525 WantQueryMouse = 1;
|
|
4526 break;
|
|
4527 case 3: mouse_code = MOUSE_RELEASE | MOUSE_LEFT;
|
|
4528 break;
|
|
4529 case 4: mouse_code = MOUSE_MIDDLE;
|
|
4530 WantQueryMouse = 1;
|
|
4531 break;
|
|
4532 case 5: mouse_code = MOUSE_RELEASE | MOUSE_MIDDLE;
|
|
4533 break;
|
|
4534 case 6: mouse_code = MOUSE_RIGHT;
|
|
4535 WantQueryMouse = 1;
|
|
4536 break;
|
|
4537 case 7: mouse_code = MOUSE_RELEASE | MOUSE_RIGHT;
|
|
4538 break;
|
|
4539 case 8: return -1; /* fourth button down */
|
|
4540 case 9: return -1; /* fourth button up */
|
|
4541 case 10: return -1; /* mouse outside of filter rectangle */
|
|
4542 default: return -1; /* should never occur */
|
|
4543 }
|
|
4544
|
|
4545 mouse_col = Pc - 1;
|
|
4546 mouse_row = Pr - 1;
|
|
4547
|
|
4548 slen += (int)(p - (tp + slen));
|
|
4549 }
|
|
4550 # endif /* FEAT_MOUSE_DEC */
|
|
4551 # ifdef FEAT_MOUSE_PTERM
|
|
4552 if (key_name[0] == (int)KS_PTERM_MOUSE)
|
|
4553 {
|
|
4554 int button, num_clicks, action, mc, mr;
|
|
4555
|
|
4556 p = tp + slen;
|
|
4557
|
|
4558 action = getdigits(&p);
|
|
4559 if (*p++ != ';')
|
|
4560 return -1;
|
|
4561
|
|
4562 mouse_row = getdigits(&p);
|
|
4563 if (*p++ != ';')
|
|
4564 return -1;
|
|
4565 mouse_col = getdigits(&p);
|
|
4566 if (*p++ != ';')
|
|
4567 return -1;
|
|
4568
|
|
4569 button = getdigits(&p);
|
|
4570 mouse_code = 0;
|
|
4571
|
|
4572 switch( button )
|
|
4573 {
|
|
4574 case 4: mouse_code = MOUSE_LEFT; break;
|
|
4575 case 1: mouse_code = MOUSE_RIGHT; break;
|
|
4576 case 2: mouse_code = MOUSE_MIDDLE; break;
|
|
4577 default: return -1;
|
|
4578 }
|
|
4579
|
|
4580 switch( action )
|
|
4581 {
|
|
4582 case 31: /* Initial press */
|
|
4583 if (*p++ != ';')
|
|
4584 return -1;
|
|
4585
|
|
4586 num_clicks = getdigits(&p); /* Not used */
|
|
4587 break;
|
|
4588
|
|
4589 case 32: /* Release */
|
|
4590 mouse_code |= MOUSE_RELEASE;
|
|
4591 break;
|
|
4592
|
|
4593 case 33: /* Drag */
|
|
4594 held_button = mouse_code;
|
|
4595 mouse_code |= MOUSE_DRAG;
|
|
4596 break;
|
|
4597
|
|
4598 default:
|
|
4599 return -1;
|
|
4600 }
|
|
4601
|
|
4602 if (*p++ != 't')
|
|
4603 return -1;
|
|
4604
|
|
4605 slen += (p - (tp + slen));
|
|
4606 }
|
|
4607 # endif /* FEAT_MOUSE_PTERM */
|
|
4608
|
|
4609 /* Interpret the mouse code */
|
|
4610 current_button = (mouse_code & MOUSE_CLICK_MASK);
|
|
4611 if (current_button == MOUSE_RELEASE
|
|
4612 # ifdef FEAT_MOUSE_XTERM
|
|
4613 && wheel_code == 0
|
|
4614 # endif
|
|
4615 )
|
|
4616 {
|
|
4617 /*
|
|
4618 * If we get a mouse drag or release event when
|
|
4619 * there is no mouse button held down (held_button ==
|
|
4620 * MOUSE_RELEASE), produce a K_IGNORE below.
|
|
4621 * (can happen when you hold down two buttons
|
|
4622 * and then let them go, or click in the menu bar, but not
|
|
4623 * on a menu, and drag into the text).
|
|
4624 */
|
|
4625 if ((mouse_code & MOUSE_DRAG) == MOUSE_DRAG)
|
|
4626 is_drag = TRUE;
|
|
4627 current_button = held_button;
|
|
4628 }
|
|
4629 else if (wheel_code == 0)
|
|
4630 {
|
|
4631 # ifdef CHECK_DOUBLE_CLICK
|
|
4632 # ifdef FEAT_MOUSE_GPM
|
|
4633 # ifdef FEAT_GUI
|
|
4634 /*
|
|
4635 * Only for Unix, when GUI or gpm is not active, we handle
|
|
4636 * multi-clicks here.
|
|
4637 */
|
|
4638 if (gpm_flag == 0 && !gui.in_use)
|
|
4639 # else
|
|
4640 if (gpm_flag == 0)
|
|
4641 # endif
|
|
4642 # else
|
|
4643 # ifdef FEAT_GUI
|
|
4644 if (!gui.in_use)
|
|
4645 # endif
|
|
4646 # endif
|
|
4647 {
|
|
4648 /*
|
|
4649 * Compute the time elapsed since the previous mouse click.
|
|
4650 */
|
|
4651 gettimeofday(&mouse_time, NULL);
|
|
4652 timediff = (mouse_time.tv_usec
|
|
4653 - orig_mouse_time.tv_usec) / 1000;
|
|
4654 if (timediff < 0)
|
|
4655 --orig_mouse_time.tv_sec;
|
|
4656 timediff += (mouse_time.tv_sec
|
|
4657 - orig_mouse_time.tv_sec) * 1000;
|
|
4658 orig_mouse_time = mouse_time;
|
|
4659 if (mouse_code == orig_mouse_code
|
|
4660 && timediff < p_mouset
|
|
4661 && orig_num_clicks != 4
|
|
4662 && orig_mouse_col == mouse_col
|
|
4663 && orig_mouse_row == mouse_row
|
|
4664 #ifdef FEAT_DIFF
|
|
4665 && orig_topfill == curwin->w_topfill
|
|
4666 #endif
|
|
4667 && orig_topline == curwin->w_topline)
|
|
4668 ++orig_num_clicks;
|
|
4669 else
|
|
4670 orig_num_clicks = 1;
|
|
4671 orig_mouse_col = mouse_col;
|
|
4672 orig_mouse_row = mouse_row;
|
|
4673 orig_topline = curwin->w_topline;
|
|
4674 #ifdef FEAT_DIFF
|
|
4675 orig_topfill = curwin->w_topfill;
|
|
4676 #endif
|
|
4677 }
|
|
4678 # if defined(FEAT_GUI) || defined(FEAT_MOUSE_GPM)
|
|
4679 else
|
|
4680 orig_num_clicks = NUM_MOUSE_CLICKS(mouse_code);
|
|
4681 # endif
|
|
4682 # else
|
|
4683 orig_num_clicks = NUM_MOUSE_CLICKS(mouse_code);
|
|
4684 # endif
|
|
4685 is_click = TRUE;
|
|
4686 orig_mouse_code = mouse_code;
|
|
4687 }
|
|
4688 if (!is_drag)
|
|
4689 held_button = mouse_code & MOUSE_CLICK_MASK;
|
|
4690
|
|
4691 /*
|
|
4692 * Translate the actual mouse event into a pseudo mouse event.
|
|
4693 * First work out what modifiers are to be used.
|
|
4694 */
|
|
4695 if (orig_mouse_code & MOUSE_SHIFT)
|
|
4696 modifiers |= MOD_MASK_SHIFT;
|
|
4697 if (orig_mouse_code & MOUSE_CTRL)
|
|
4698 modifiers |= MOD_MASK_CTRL;
|
|
4699 if (orig_mouse_code & MOUSE_ALT)
|
|
4700 modifiers |= MOD_MASK_ALT;
|
|
4701 if (orig_num_clicks == 2)
|
|
4702 modifiers |= MOD_MASK_2CLICK;
|
|
4703 else if (orig_num_clicks == 3)
|
|
4704 modifiers |= MOD_MASK_3CLICK;
|
|
4705 else if (orig_num_clicks == 4)
|
|
4706 modifiers |= MOD_MASK_4CLICK;
|
|
4707
|
|
4708 /* Work out our pseudo mouse event */
|
|
4709 key_name[0] = (int)KS_EXTRA;
|
|
4710 if (wheel_code != 0)
|
|
4711 key_name[1] = (wheel_code & 1)
|
|
4712 ? (int)KE_MOUSEUP : (int)KE_MOUSEDOWN;
|
|
4713 else
|
|
4714 key_name[1] = get_pseudo_mouse_code(current_button,
|
|
4715 is_click, is_drag);
|
|
4716 }
|
|
4717 #endif /* FEAT_MOUSE */
|
|
4718
|
|
4719 #ifdef FEAT_GUI
|
|
4720 /*
|
|
4721 * If using the GUI, then we get menu and scrollbar events.
|
|
4722 *
|
|
4723 * A menu event is encoded as K_SPECIAL, KS_MENU, KE_FILLER followed by
|
|
4724 * four bytes which are to be taken as a pointer to the vimmenu_T
|
|
4725 * structure.
|
|
4726 *
|
|
4727 * A scrollbar event is K_SPECIAL, KS_VER_SCROLLBAR, KE_FILLER followed
|
|
4728 * by one byte representing the scrollbar number, and then four bytes
|
|
4729 * representing a long_u which is the new value of the scrollbar.
|
|
4730 *
|
|
4731 * A horizontal scrollbar event is K_SPECIAL, KS_HOR_SCROLLBAR,
|
|
4732 * KE_FILLER followed by four bytes representing a long_u which is the
|
|
4733 * new value of the scrollbar.
|
|
4734 */
|
|
4735 # ifdef FEAT_MENU
|
|
4736 else if (key_name[0] == (int)KS_MENU)
|
|
4737 {
|
|
4738 long_u val;
|
|
4739
|
|
4740 num_bytes = get_long_from_buf(tp + slen, &val);
|
|
4741 if (num_bytes == -1)
|
|
4742 return -1;
|
|
4743 current_menu = (vimmenu_T *)val;
|
|
4744 slen += num_bytes;
|
|
4745 }
|
|
4746 # endif
|
|
4747 # ifndef USE_ON_FLY_SCROLL
|
|
4748 else if (key_name[0] == (int)KS_VER_SCROLLBAR)
|
|
4749 {
|
|
4750 long_u val;
|
|
4751
|
|
4752 /* Get the last scrollbar event in the queue of the same type */
|
|
4753 j = 0;
|
|
4754 for (i = 0; tp[j] == CSI && tp[j + 1] == KS_VER_SCROLLBAR
|
|
4755 && tp[j + 2] != NUL; ++i)
|
|
4756 {
|
|
4757 j += 3;
|
|
4758 num_bytes = get_bytes_from_buf(tp + j, bytes, 1);
|
|
4759 if (num_bytes == -1)
|
|
4760 break;
|
|
4761 if (i == 0)
|
|
4762 current_scrollbar = (int)bytes[0];
|
|
4763 else if (current_scrollbar != (int)bytes[0])
|
|
4764 break;
|
|
4765 j += num_bytes;
|
|
4766 num_bytes = get_long_from_buf(tp + j, &val);
|
|
4767 if (num_bytes == -1)
|
|
4768 break;
|
|
4769 scrollbar_value = val;
|
|
4770 j += num_bytes;
|
|
4771 slen = j;
|
|
4772 }
|
|
4773 if (i == 0) /* not enough characters to make one */
|
|
4774 return -1;
|
|
4775 }
|
|
4776 else if (key_name[0] == (int)KS_HOR_SCROLLBAR)
|
|
4777 {
|
|
4778 long_u val;
|
|
4779
|
|
4780 /* Get the last horiz. scrollbar event in the queue */
|
|
4781 j = 0;
|
|
4782 for (i = 0; tp[j] == CSI && tp[j + 1] == KS_HOR_SCROLLBAR
|
|
4783 && tp[j + 2] != NUL; ++i)
|
|
4784 {
|
|
4785 j += 3;
|
|
4786 num_bytes = get_long_from_buf(tp + j, &val);
|
|
4787 if (num_bytes == -1)
|
|
4788 break;
|
|
4789 scrollbar_value = val;
|
|
4790 j += num_bytes;
|
|
4791 slen = j;
|
|
4792 }
|
|
4793 if (i == 0) /* not enough characters to make one */
|
|
4794 return -1;
|
|
4795 }
|
|
4796 # endif /* !USE_ON_FLY_SCROLL */
|
|
4797 #endif /* FEAT_GUI */
|
|
4798
|
180
|
4799 /*
|
|
4800 * Change <xHome> to <Home>, <xUp> to <Up>, etc.
|
|
4801 */
|
|
4802 key = handle_x_keys(TERMCAP2KEY(key_name[0], key_name[1]));
|
|
4803
|
|
4804 /*
|
|
4805 * Add any modifier codes to our string.
|
|
4806 */
|
|
4807 new_slen = 0; /* Length of what will replace the termcode */
|
|
4808 if (modifiers != 0)
|
|
4809 {
|
|
4810 /* Some keys have the modifier included. Need to handle that here
|
|
4811 * to make mappings work. */
|
|
4812 key = simplify_key(key, &modifiers);
|
|
4813 if (modifiers != 0)
|
|
4814 {
|
|
4815 string[new_slen++] = K_SPECIAL;
|
|
4816 string[new_slen++] = (int)KS_MODIFIER;
|
|
4817 string[new_slen++] = modifiers;
|
|
4818 }
|
|
4819 }
|
|
4820
|
7
|
4821 /* Finally, add the special key code to our string */
|
180
|
4822 key_name[0] = KEY2TERMCAP0(key);
|
|
4823 key_name[1] = KEY2TERMCAP1(key);
|
7
|
4824 if (key_name[0] == KS_KEY)
|
|
4825 string[new_slen++] = key_name[1]; /* from ":set <M-b>=xx" */
|
|
4826 else
|
|
4827 {
|
|
4828 string[new_slen++] = K_SPECIAL;
|
|
4829 string[new_slen++] = key_name[0];
|
|
4830 string[new_slen++] = key_name[1];
|
|
4831 }
|
|
4832 string[new_slen] = NUL;
|
|
4833 extra = new_slen - slen;
|
|
4834 if (buf == NULL)
|
|
4835 {
|
|
4836 if (extra < 0)
|
|
4837 /* remove matched chars, taking care of noremap */
|
|
4838 del_typebuf(-extra, offset);
|
|
4839 else if (extra > 0)
|
|
4840 /* insert the extra space we need */
|
|
4841 ins_typebuf(string + slen, REMAP_YES, offset, FALSE, FALSE);
|
|
4842
|
|
4843 /*
|
|
4844 * Careful: del_typebuf() and ins_typebuf() may have reallocated
|
|
4845 * typebuf.tb_buf[]!
|
|
4846 */
|
|
4847 mch_memmove(typebuf.tb_buf + typebuf.tb_off + offset, string,
|
|
4848 (size_t)new_slen);
|
|
4849 }
|
|
4850 else
|
|
4851 {
|
|
4852 if (extra < 0)
|
|
4853 /* remove matched characters */
|
|
4854 mch_memmove(buf + offset, buf + offset - extra,
|
|
4855 (size_t)(buflen + offset + extra));
|
|
4856 else if (extra > 0)
|
|
4857 /* insert the extra space we need */
|
|
4858 mch_memmove(buf + offset + extra, buf + offset,
|
|
4859 (size_t)(buflen - offset));
|
|
4860 mch_memmove(buf + offset, string, (size_t)new_slen);
|
|
4861 }
|
|
4862 return (len + extra + offset);
|
|
4863 }
|
|
4864
|
|
4865 return 0; /* no match found */
|
|
4866 }
|
|
4867
|
|
4868 /*
|
|
4869 * Replace any terminal code strings in from[] with the equivalent internal
|
|
4870 * vim representation. This is used for the "from" and "to" part of a
|
|
4871 * mapping, and the "to" part of a menu command.
|
|
4872 * Any strings like "<C-UP>" are also replaced, unless 'cpoptions' contains
|
|
4873 * '<'.
|
|
4874 * K_SPECIAL by itself is replaced by K_SPECIAL KS_SPECIAL KE_FILLER.
|
|
4875 *
|
|
4876 * The replacement is done in result[] and finally copied into allocated
|
|
4877 * memory. If this all works well *bufp is set to the allocated memory and a
|
|
4878 * pointer to it is returned. If something fails *bufp is set to NULL and from
|
|
4879 * is returned.
|
|
4880 *
|
|
4881 * CTRL-V characters are removed. When "from_part" is TRUE, a trailing CTRL-V
|
|
4882 * is included, otherwise it is removed (for ":map xx ^V", maps xx to
|
|
4883 * nothing). When 'cpoptions' does not contain 'B', a backslash can be used
|
|
4884 * instead of a CTRL-V.
|
|
4885 */
|
|
4886 char_u *
|
|
4887 replace_termcodes(from, bufp, from_part, do_lt)
|
|
4888 char_u *from;
|
|
4889 char_u **bufp;
|
|
4890 int from_part;
|
|
4891 int do_lt; /* also translate <lt> */
|
|
4892 {
|
|
4893 int i;
|
|
4894 int slen;
|
|
4895 int key;
|
|
4896 int dlen = 0;
|
|
4897 char_u *src;
|
|
4898 int do_backslash; /* backslash is a special character */
|
|
4899 int do_special; /* recognize <> key codes */
|
|
4900 int do_key_code; /* recognize raw key codes */
|
|
4901 char_u *result; /* buffer for resulting string */
|
|
4902
|
|
4903 do_backslash = (vim_strchr(p_cpo, CPO_BSLASH) == NULL);
|
|
4904 do_special = (vim_strchr(p_cpo, CPO_SPECI) == NULL);
|
|
4905 do_key_code = (vim_strchr(p_cpo, CPO_KEYCODE) == NULL);
|
|
4906
|
|
4907 /*
|
|
4908 * Allocate space for the translation. Worst case a single character is
|
|
4909 * replaced by 6 bytes (shifted special key), plus a NUL at the end.
|
|
4910 */
|
|
4911 result = alloc((unsigned)STRLEN(from) * 6 + 1);
|
|
4912 if (result == NULL) /* out of memory */
|
|
4913 {
|
|
4914 *bufp = NULL;
|
|
4915 return from;
|
|
4916 }
|
|
4917
|
|
4918 src = from;
|
|
4919
|
|
4920 /*
|
|
4921 * Check for #n at start only: function key n
|
|
4922 */
|
|
4923 if (from_part && src[0] == '#' && VIM_ISDIGIT(src[1])) /* function key */
|
|
4924 {
|
|
4925 result[dlen++] = K_SPECIAL;
|
|
4926 result[dlen++] = 'k';
|
|
4927 if (src[1] == '0')
|
|
4928 result[dlen++] = ';'; /* #0 is F10 is "k;" */
|
|
4929 else
|
|
4930 result[dlen++] = src[1]; /* #3 is F3 is "k3" */
|
|
4931 src += 2;
|
|
4932 }
|
|
4933
|
|
4934 /*
|
|
4935 * Copy each byte from *from to result[dlen]
|
|
4936 */
|
|
4937 while (*src != NUL)
|
|
4938 {
|
|
4939 /*
|
|
4940 * If 'cpoptions' does not contain '<', check for special key codes,
|
|
4941 * like "<C-S-MouseLeft>"
|
|
4942 */
|
|
4943 if (do_special && (do_lt || STRNCMP(src, "<lt>", 4) != 0))
|
|
4944 {
|
|
4945 #ifdef FEAT_EVAL
|
|
4946 /*
|
|
4947 * Replace <SID> by K_SNR <script-nr> _.
|
|
4948 * (room: 5 * 6 = 30 bytes; needed: 3 + <nr> + 1 <= 14)
|
|
4949 */
|
|
4950 if (STRNICMP(src, "<SID>", 5) == 0)
|
|
4951 {
|
|
4952 if (current_SID <= 0)
|
|
4953 EMSG(_(e_usingsid));
|
|
4954 else
|
|
4955 {
|
|
4956 src += 5;
|
|
4957 result[dlen++] = K_SPECIAL;
|
|
4958 result[dlen++] = (int)KS_EXTRA;
|
|
4959 result[dlen++] = (int)KE_SNR;
|
|
4960 sprintf((char *)result + dlen, "%ld", (long)current_SID);
|
|
4961 dlen += (int)STRLEN(result + dlen);
|
|
4962 result[dlen++] = '_';
|
|
4963 continue;
|
|
4964 }
|
|
4965 }
|
|
4966 #endif
|
|
4967
|
|
4968 slen = trans_special(&src, result + dlen, TRUE);
|
|
4969 if (slen)
|
|
4970 {
|
|
4971 dlen += slen;
|
|
4972 continue;
|
|
4973 }
|
|
4974 }
|
|
4975
|
|
4976 /*
|
|
4977 * If 'cpoptions' does not contain 'k', see if it's an actual key-code.
|
|
4978 * Note that this is also checked after replacing the <> form.
|
|
4979 * Single character codes are NOT replaced (e.g. ^H or DEL), because
|
|
4980 * it could be a character in the file.
|
|
4981 */
|
|
4982 if (do_key_code)
|
|
4983 {
|
|
4984 i = find_term_bykeys(src);
|
|
4985 if (i >= 0)
|
|
4986 {
|
|
4987 result[dlen++] = K_SPECIAL;
|
|
4988 result[dlen++] = termcodes[i].name[0];
|
|
4989 result[dlen++] = termcodes[i].name[1];
|
|
4990 src += termcodes[i].len;
|
|
4991 /* If terminal code matched, continue after it. */
|
|
4992 continue;
|
|
4993 }
|
|
4994 }
|
|
4995
|
|
4996 #ifdef FEAT_EVAL
|
|
4997 if (do_special)
|
|
4998 {
|
|
4999 char_u *p, *s, len;
|
|
5000
|
|
5001 /*
|
|
5002 * Replace <Leader> by the value of "mapleader".
|
|
5003 * Replace <LocalLeader> by the value of "maplocalleader".
|
|
5004 * If "mapleader" or "maplocalleader" isn't set use a backslash.
|
|
5005 */
|
|
5006 if (STRNICMP(src, "<Leader>", 8) == 0)
|
|
5007 {
|
|
5008 len = 8;
|
|
5009 p = get_var_value((char_u *)"g:mapleader");
|
|
5010 }
|
|
5011 else if (STRNICMP(src, "<LocalLeader>", 13) == 0)
|
|
5012 {
|
|
5013 len = 13;
|
|
5014 p = get_var_value((char_u *)"g:maplocalleader");
|
|
5015 }
|
|
5016 else
|
|
5017 {
|
|
5018 len = 0;
|
|
5019 p = NULL;
|
|
5020 }
|
|
5021 if (len != 0)
|
|
5022 {
|
|
5023 /* Allow up to 8 * 6 characters for "mapleader". */
|
|
5024 if (p == NULL || *p == NUL || STRLEN(p) > 8 * 6)
|
|
5025 s = (char_u *)"\\";
|
|
5026 else
|
|
5027 s = p;
|
|
5028 while (*s != NUL)
|
|
5029 result[dlen++] = *s++;
|
|
5030 src += len;
|
|
5031 continue;
|
|
5032 }
|
|
5033 }
|
|
5034 #endif
|
|
5035
|
|
5036 /*
|
|
5037 * Remove CTRL-V and ignore the next character.
|
|
5038 * For "from" side the CTRL-V at the end is included, for the "to"
|
|
5039 * part it is removed.
|
|
5040 * If 'cpoptions' does not contain 'B', also accept a backslash.
|
|
5041 */
|
|
5042 key = *src;
|
|
5043 if (key == Ctrl_V || (do_backslash && key == '\\'))
|
|
5044 {
|
|
5045 ++src; /* skip CTRL-V or backslash */
|
|
5046 if (*src == NUL)
|
|
5047 {
|
|
5048 if (from_part)
|
|
5049 result[dlen++] = key;
|
|
5050 break;
|
|
5051 }
|
|
5052 }
|
|
5053
|
|
5054 #ifdef FEAT_MBYTE
|
|
5055 /* skip multibyte char correctly */
|
|
5056 for (i = (*mb_ptr2len_check)(src); i > 0; --i)
|
|
5057 #endif
|
|
5058 {
|
|
5059 /*
|
|
5060 * If the character is K_SPECIAL, replace it with K_SPECIAL
|
|
5061 * KS_SPECIAL KE_FILLER.
|
|
5062 * If compiled with the GUI replace CSI with K_CSI.
|
|
5063 */
|
|
5064 if (*src == K_SPECIAL)
|
|
5065 {
|
|
5066 result[dlen++] = K_SPECIAL;
|
|
5067 result[dlen++] = KS_SPECIAL;
|
|
5068 result[dlen++] = KE_FILLER;
|
|
5069 }
|
|
5070 # ifdef FEAT_GUI
|
|
5071 else if (*src == CSI)
|
|
5072 {
|
|
5073 result[dlen++] = K_SPECIAL;
|
|
5074 result[dlen++] = KS_EXTRA;
|
|
5075 result[dlen++] = (int)KE_CSI;
|
|
5076 }
|
|
5077 # endif
|
|
5078 else
|
|
5079 result[dlen++] = *src;
|
|
5080 ++src;
|
|
5081 }
|
|
5082 }
|
|
5083 result[dlen] = NUL;
|
|
5084
|
|
5085 /*
|
|
5086 * Copy the new string to allocated memory.
|
|
5087 * If this fails, just return from.
|
|
5088 */
|
|
5089 if ((*bufp = vim_strsave(result)) != NULL)
|
|
5090 from = *bufp;
|
|
5091 vim_free(result);
|
|
5092 return from;
|
|
5093 }
|
|
5094
|
|
5095 /*
|
|
5096 * Find a termcode with keys 'src' (must be NUL terminated).
|
|
5097 * Return the index in termcodes[], or -1 if not found.
|
|
5098 */
|
|
5099 int
|
|
5100 find_term_bykeys(src)
|
|
5101 char_u *src;
|
|
5102 {
|
|
5103 int i;
|
|
5104 int slen;
|
|
5105
|
|
5106 for (i = 0; i < tc_len; ++i)
|
|
5107 {
|
|
5108 slen = termcodes[i].len;
|
|
5109 if (slen > 1 && STRNCMP(termcodes[i].code, src, (size_t)slen) == 0)
|
|
5110 return i;
|
|
5111 }
|
|
5112 return -1;
|
|
5113 }
|
|
5114
|
|
5115 /*
|
|
5116 * Gather the first characters in the terminal key codes into a string.
|
|
5117 * Used to speed up check_termcode().
|
|
5118 */
|
|
5119 static void
|
|
5120 gather_termleader()
|
|
5121 {
|
|
5122 int i;
|
|
5123 int len = 0;
|
|
5124
|
|
5125 #ifdef FEAT_GUI
|
|
5126 if (gui.in_use)
|
|
5127 termleader[len++] = CSI; /* the GUI codes are not in termcodes[] */
|
|
5128 #endif
|
|
5129 #ifdef FEAT_TERMRESPONSE
|
|
5130 if (check_for_codes)
|
|
5131 termleader[len++] = DCS; /* the termcode response starts with DCS
|
|
5132 in 8-bit mode */
|
|
5133 #endif
|
|
5134 termleader[len] = NUL;
|
|
5135
|
|
5136 for (i = 0; i < tc_len; ++i)
|
|
5137 if (vim_strchr(termleader, termcodes[i].code[0]) == NULL)
|
|
5138 {
|
|
5139 termleader[len++] = termcodes[i].code[0];
|
|
5140 termleader[len] = NUL;
|
|
5141 }
|
|
5142
|
|
5143 need_gather = FALSE;
|
|
5144 }
|
|
5145
|
|
5146 /*
|
|
5147 * Show all termcodes (for ":set termcap")
|
|
5148 * This code looks a lot like showoptions(), but is different.
|
|
5149 */
|
|
5150 void
|
|
5151 show_termcodes()
|
|
5152 {
|
|
5153 int col;
|
|
5154 int *items;
|
|
5155 int item_count;
|
|
5156 int run;
|
|
5157 int row, rows;
|
|
5158 int cols;
|
|
5159 int i;
|
|
5160 int len;
|
|
5161
|
180
|
5162 #define INC3 27 /* try to make three columns */
|
|
5163 #define INC2 40 /* try to make two columns */
|
7
|
5164 #define GAP 2 /* spaces between columns */
|
|
5165
|
|
5166 if (tc_len == 0) /* no terminal codes (must be GUI) */
|
|
5167 return;
|
|
5168 items = (int *)alloc((unsigned)(sizeof(int) * tc_len));
|
|
5169 if (items == NULL)
|
|
5170 return;
|
|
5171
|
|
5172 /* Highlight title */
|
|
5173 MSG_PUTS_TITLE(_("\n--- Terminal keys ---"));
|
|
5174
|
|
5175 /*
|
|
5176 * do the loop two times:
|
|
5177 * 1. display the short items (non-strings and short strings)
|
180
|
5178 * 2. display the medium items (medium length strings)
|
|
5179 * 3. display the long items (remaining strings)
|
7
|
5180 */
|
180
|
5181 for (run = 1; run <= 3 && !got_int; ++run)
|
7
|
5182 {
|
|
5183 /*
|
|
5184 * collect the items in items[]
|
|
5185 */
|
|
5186 item_count = 0;
|
|
5187 for (i = 0; i < tc_len; i++)
|
|
5188 {
|
|
5189 len = show_one_termcode(termcodes[i].name,
|
|
5190 termcodes[i].code, FALSE);
|
180
|
5191 if (len <= INC3 - GAP ? run == 1
|
|
5192 : len <= INC2 - GAP ? run == 2
|
|
5193 : run == 3)
|
7
|
5194 items[item_count++] = i;
|
|
5195 }
|
|
5196
|
|
5197 /*
|
|
5198 * display the items
|
|
5199 */
|
180
|
5200 if (run <= 2)
|
7
|
5201 {
|
180
|
5202 cols = (Columns + GAP) / (run == 1 ? INC3 : INC2);
|
7
|
5203 if (cols == 0)
|
|
5204 cols = 1;
|
|
5205 rows = (item_count + cols - 1) / cols;
|
|
5206 }
|
180
|
5207 else /* run == 3 */
|
7
|
5208 rows = item_count;
|
|
5209 for (row = 0; row < rows && !got_int; ++row)
|
|
5210 {
|
|
5211 msg_putchar('\n'); /* go to next line */
|
|
5212 if (got_int) /* 'q' typed in more */
|
|
5213 break;
|
|
5214 col = 0;
|
|
5215 for (i = row; i < item_count; i += rows)
|
|
5216 {
|
|
5217 msg_col = col; /* make columns */
|
|
5218 show_one_termcode(termcodes[items[i]].name,
|
|
5219 termcodes[items[i]].code, TRUE);
|
180
|
5220 if (run == 2)
|
|
5221 col += INC2;
|
|
5222 else
|
|
5223 col += INC3;
|
7
|
5224 }
|
|
5225 out_flush();
|
|
5226 ui_breakcheck();
|
|
5227 }
|
|
5228 }
|
|
5229 vim_free(items);
|
|
5230 }
|
|
5231
|
|
5232 /*
|
|
5233 * Show one termcode entry.
|
|
5234 * Output goes into IObuff[]
|
|
5235 */
|
|
5236 int
|
|
5237 show_one_termcode(name, code, printit)
|
|
5238 char_u *name;
|
|
5239 char_u *code;
|
|
5240 int printit;
|
|
5241 {
|
|
5242 char_u *p;
|
|
5243 int len;
|
|
5244
|
|
5245 if (name[0] > '~')
|
|
5246 {
|
|
5247 IObuff[0] = ' ';
|
|
5248 IObuff[1] = ' ';
|
|
5249 IObuff[2] = ' ';
|
|
5250 IObuff[3] = ' ';
|
|
5251 }
|
|
5252 else
|
|
5253 {
|
|
5254 IObuff[0] = 't';
|
|
5255 IObuff[1] = '_';
|
|
5256 IObuff[2] = name[0];
|
|
5257 IObuff[3] = name[1];
|
|
5258 }
|
|
5259 IObuff[4] = ' ';
|
|
5260
|
|
5261 p = get_special_key_name(TERMCAP2KEY(name[0], name[1]), 0);
|
|
5262 if (p[1] != 't')
|
|
5263 STRCPY(IObuff + 5, p);
|
|
5264 else
|
|
5265 IObuff[5] = NUL;
|
|
5266 len = (int)STRLEN(IObuff);
|
|
5267 do
|
|
5268 IObuff[len++] = ' ';
|
|
5269 while (len < 17);
|
|
5270 IObuff[len] = NUL;
|
|
5271 if (code == NULL)
|
|
5272 len += 4;
|
|
5273 else
|
|
5274 len += vim_strsize(code);
|
|
5275
|
|
5276 if (printit)
|
|
5277 {
|
|
5278 msg_puts(IObuff);
|
|
5279 if (code == NULL)
|
|
5280 msg_puts((char_u *)"NULL");
|
|
5281 else
|
|
5282 msg_outtrans(code);
|
|
5283 }
|
|
5284 return len;
|
|
5285 }
|
|
5286
|
|
5287 #if defined(FEAT_TERMRESPONSE) || defined(PROTO)
|
|
5288 /*
|
|
5289 * For Xterm >= 140 compiled with OPT_TCAP_QUERY: Obtain the actually used
|
|
5290 * termcap codes from the terminal itself.
|
|
5291 * We get them one by one to avoid a very long response string.
|
|
5292 */
|
|
5293 static int xt_index_in = 0;
|
|
5294 static int xt_index_out = 0;
|
|
5295
|
|
5296 static void
|
|
5297 req_codes_from_term()
|
|
5298 {
|
|
5299 xt_index_out = 0;
|
|
5300 xt_index_in = 0;
|
|
5301 req_more_codes_from_term();
|
|
5302 }
|
|
5303
|
|
5304 static void
|
|
5305 req_more_codes_from_term()
|
|
5306 {
|
|
5307 char buf[11];
|
|
5308 int old_idx = xt_index_out;
|
|
5309
|
|
5310 /* Don't do anything when going to exit. */
|
|
5311 if (exiting)
|
|
5312 return;
|
|
5313
|
|
5314 /* Send up to 10 more requests out than we received. Avoid sending too
|
|
5315 * many, there can be a buffer overflow somewhere. */
|
|
5316 while (xt_index_out < xt_index_in + 10 && key_names[xt_index_out] != NULL)
|
|
5317 {
|
|
5318 sprintf(buf, "\033P+q%02x%02x\033\\",
|
|
5319 key_names[xt_index_out][0], key_names[xt_index_out][1]);
|
|
5320 out_str_nf((char_u *)buf);
|
|
5321 ++xt_index_out;
|
|
5322 }
|
|
5323
|
|
5324 /* Send the codes out right away. */
|
|
5325 if (xt_index_out != old_idx)
|
|
5326 out_flush();
|
|
5327 }
|
|
5328
|
|
5329 /*
|
|
5330 * Decode key code response from xterm: '<Esc>P1+r<name>=<string><Esc>\'.
|
|
5331 * A "0" instead of the "1" indicates a code that isn't supported.
|
|
5332 * Both <name> and <string> are encoded in hex.
|
|
5333 * "code" points to the "0" or "1".
|
|
5334 */
|
|
5335 static void
|
|
5336 got_code_from_term(code, len)
|
|
5337 char_u *code;
|
|
5338 int len;
|
|
5339 {
|
|
5340 #define XT_LEN 100
|
|
5341 char_u name[3];
|
|
5342 char_u str[XT_LEN];
|
|
5343 int i;
|
|
5344 int j = 0;
|
|
5345 int c;
|
|
5346
|
|
5347 /* A '1' means the code is supported, a '0' means it isn't.
|
|
5348 * When half the length is > XT_LEN we can't use it.
|
|
5349 * Our names are currently all 2 characters. */
|
|
5350 if (code[0] == '1' && code[7] == '=' && len / 2 < XT_LEN)
|
|
5351 {
|
|
5352 /* Get the name from the response and find it in the table. */
|
|
5353 name[0] = hexhex2nr(code + 3);
|
|
5354 name[1] = hexhex2nr(code + 5);
|
|
5355 name[2] = NUL;
|
|
5356 for (i = 0; key_names[i] != NULL; ++i)
|
|
5357 {
|
|
5358 if (STRCMP(key_names[i], name) == 0)
|
|
5359 {
|
|
5360 xt_index_in = i;
|
|
5361 break;
|
|
5362 }
|
|
5363 }
|
|
5364 if (key_names[i] != NULL)
|
|
5365 {
|
|
5366 for (i = 8; (c = hexhex2nr(code + i)) >= 0; i += 2)
|
|
5367 str[j++] = c;
|
|
5368 str[j] = NUL;
|
|
5369 if (name[0] == 'C' && name[1] == 'o')
|
|
5370 {
|
|
5371 /* Color count is not a key code. */
|
|
5372 i = atoi((char *)str);
|
|
5373 if (i != t_colors)
|
|
5374 {
|
|
5375 /* Nr of colors changed, initialize highlighting and
|
|
5376 * redraw everything. */
|
|
5377 set_color_count(i);
|
|
5378 init_highlight(TRUE, FALSE);
|
|
5379 redraw_later(CLEAR);
|
|
5380 }
|
|
5381 }
|
|
5382 else
|
|
5383 {
|
|
5384 /* First delete any existing entry with the same code. */
|
|
5385 i = find_term_bykeys(str);
|
|
5386 if (i >= 0)
|
|
5387 del_termcode_idx(i);
|
180
|
5388 add_termcode(name, str, ATC_FROM_TERM);
|
7
|
5389 }
|
|
5390 }
|
|
5391 }
|
|
5392
|
|
5393 /* May request more codes now that we received one. */
|
|
5394 ++xt_index_in;
|
|
5395 req_more_codes_from_term();
|
|
5396 }
|
|
5397
|
|
5398 /*
|
|
5399 * Check if there are any unanswered requests and deal with them.
|
|
5400 * This is called before starting an external program or getting direct
|
|
5401 * keyboard input. We don't want responses to be send to that program or
|
|
5402 * handled as typed text.
|
|
5403 */
|
|
5404 static void
|
|
5405 check_for_codes_from_term()
|
|
5406 {
|
|
5407 int c;
|
|
5408
|
|
5409 /* If no codes requested or all are answered, no need to wait. */
|
|
5410 if (xt_index_out == 0 || xt_index_out == xt_index_in)
|
|
5411 return;
|
|
5412
|
|
5413 /* Vgetc() will check for and handle any response.
|
|
5414 * Keep calling vpeekc() until we don't get any responses. */
|
|
5415 ++no_mapping;
|
|
5416 ++allow_keys;
|
|
5417 for (;;)
|
|
5418 {
|
|
5419 c = vpeekc();
|
|
5420 if (c == NUL) /* nothing available */
|
|
5421 break;
|
|
5422
|
|
5423 /* If a response is recognized it's replaced with K_IGNORE, must read
|
|
5424 * it from the input stream. If there is no K_IGNORE we can't do
|
|
5425 * anything, break here (there might be some responses further on, but
|
|
5426 * we don't want to throw away any typed chars). */
|
|
5427 if (c != K_SPECIAL && c != K_IGNORE)
|
|
5428 break;
|
|
5429 c = vgetc();
|
|
5430 if (c != K_IGNORE)
|
|
5431 {
|
|
5432 vungetc(c);
|
|
5433 break;
|
|
5434 }
|
|
5435 }
|
|
5436 --no_mapping;
|
|
5437 --allow_keys;
|
|
5438 }
|
|
5439 #endif
|
|
5440
|
|
5441 #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
|
|
5442 /*
|
|
5443 * Translate an internal mapping/abbreviation representation into the
|
|
5444 * corresponding external one recognized by :map/:abbrev commands;
|
|
5445 * respects the current B/k/< settings of 'cpoption'.
|
|
5446 *
|
|
5447 * This function is called when expanding mappings/abbreviations on the
|
|
5448 * command-line, and for building the "Ambiguous mapping..." error messæge.
|
|
5449 *
|
|
5450 * It uses a growarray to build the translation string since the
|
|
5451 * latter can be wider than the original description. The caller has to
|
|
5452 * free the string afterwards.
|
|
5453 *
|
|
5454 * Returns NULL when there is a problem.
|
|
5455 */
|
|
5456 char_u *
|
|
5457 translate_mapping(str, expmap)
|
|
5458 char_u *str;
|
|
5459 int expmap; /* TRUE when expanding mappings on command-line */
|
|
5460 {
|
|
5461 garray_T ga;
|
|
5462 int c;
|
|
5463 int modifiers;
|
|
5464 int cpo_bslash;
|
|
5465 int cpo_special;
|
|
5466 int cpo_keycode;
|
|
5467
|
|
5468 ga_init(&ga);
|
|
5469 ga.ga_itemsize = 1;
|
|
5470 ga.ga_growsize = 40;
|
|
5471
|
|
5472 cpo_bslash = (vim_strchr(p_cpo, CPO_BSLASH) != NULL);
|
|
5473 cpo_special = (vim_strchr(p_cpo, CPO_SPECI) != NULL);
|
|
5474 cpo_keycode = (vim_strchr(p_cpo, CPO_KEYCODE) == NULL);
|
|
5475
|
|
5476 for (; *str; ++str)
|
|
5477 {
|
|
5478 c = *str;
|
|
5479 if (c == K_SPECIAL && str[1] != NUL && str[2] != NUL)
|
|
5480 {
|
|
5481 modifiers = 0;
|
|
5482 if (str[1] == KS_MODIFIER)
|
|
5483 {
|
|
5484 str++;
|
|
5485 modifiers = *++str;
|
|
5486 c = *++str;
|
|
5487 }
|
|
5488 if (cpo_special && cpo_keycode && c == K_SPECIAL && !modifiers)
|
|
5489 {
|
|
5490 int i;
|
|
5491
|
|
5492 /* try to find special key in termcodes */
|
|
5493 for (i = 0; i < tc_len; ++i)
|
|
5494 if (termcodes[i].name[0] == str[1]
|
|
5495 && termcodes[i].name[1] == str[2])
|
|
5496 break;
|
|
5497 if (i < tc_len)
|
|
5498 {
|
|
5499 ga_concat(&ga, termcodes[i].code);
|
|
5500 str += 2;
|
|
5501 continue; /* for (str) */
|
|
5502 }
|
|
5503 }
|
|
5504 if (c == K_SPECIAL && str[1] != NUL && str[2] != NUL)
|
|
5505 {
|
|
5506 if (expmap && cpo_special)
|
|
5507 {
|
|
5508 ga_clear(&ga);
|
|
5509 return NULL;
|
|
5510 }
|
|
5511 c = TO_SPECIAL(str[1], str[2]);
|
|
5512 if (c == K_ZERO) /* display <Nul> as ^@ */
|
|
5513 c = NUL;
|
|
5514 str += 2;
|
|
5515 }
|
|
5516 if (IS_SPECIAL(c) || modifiers) /* special key */
|
|
5517 {
|
|
5518 if (expmap && cpo_special)
|
|
5519 {
|
|
5520 ga_clear(&ga);
|
|
5521 return NULL;
|
|
5522 }
|
|
5523 ga_concat(&ga, get_special_key_name(c, modifiers));
|
|
5524 continue; /* for (str) */
|
|
5525 }
|
|
5526 }
|
|
5527 if (c == ' ' || c == '\t' || c == Ctrl_J || c == Ctrl_V
|
|
5528 || (c == '<' && !cpo_special) || (c == '\\' && !cpo_bslash))
|
|
5529 ga_append(&ga, cpo_bslash ? Ctrl_V : '\\');
|
|
5530 if (c)
|
|
5531 ga_append(&ga, c);
|
|
5532 }
|
|
5533 ga_append(&ga, NUL);
|
|
5534 return (char_u *)(ga.ga_data);
|
|
5535 }
|
|
5536 #endif
|
|
5537
|
|
5538 #if (defined(WIN3264) && !defined(FEAT_GUI)) || defined(PROTO)
|
|
5539 static char ksme_str[20];
|
|
5540 static char ksmr_str[20];
|
|
5541 static char ksmd_str[20];
|
|
5542
|
|
5543 /*
|
|
5544 * For Win32 console: update termcap codes for existing console attributes.
|
|
5545 */
|
|
5546 void
|
|
5547 update_tcap(attr)
|
|
5548 int attr;
|
|
5549 {
|
|
5550 struct builtin_term *p;
|
|
5551
|
|
5552 p = find_builtin_term(DEFAULT_TERM);
|
|
5553 sprintf(ksme_str, IF_EB("\033|%dm", ESC_STR "|%dm"), attr);
|
|
5554 sprintf(ksmd_str, IF_EB("\033|%dm", ESC_STR "|%dm"),
|
|
5555 attr | 0x08); /* FOREGROUND_INTENSITY */
|
|
5556 sprintf(ksmr_str, IF_EB("\033|%dm", ESC_STR "|%dm"),
|
|
5557 ((attr & 0x0F) << 4) | ((attr & 0xF0) >> 4));
|
|
5558
|
|
5559 while (p->bt_string != NULL)
|
|
5560 {
|
|
5561 if (p->bt_entry == (int)KS_ME)
|
|
5562 p->bt_string = &ksme_str[0];
|
|
5563 else if (p->bt_entry == (int)KS_MR)
|
|
5564 p->bt_string = &ksmr_str[0];
|
|
5565 else if (p->bt_entry == (int)KS_MD)
|
|
5566 p->bt_string = &ksmd_str[0];
|
|
5567 ++p;
|
|
5568 }
|
|
5569 }
|
|
5570 #endif
|