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