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