-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathterm.c
7517 lines (6885 loc) · 195 KB
/
term.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* vi:set ts=8 sts=4 sw=4 noet:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/
/*
*
* term.c: functions for controlling the terminal
*
* primitive termcap support for Amiga and Win32 included
*
* NOTE: padding and variable substitution is not performed,
* when compiling without HAVE_TGETENT, we use tputs() and tgoto() dummies.
*/
/*
* Some systems have a prototype for tgetstr() with (char *) instead of
* (char **). This define removes that prototype. We include our own prototype
* below.
*/
#define tgetstr tgetstr_defined_wrong
#include "vim.h"
#ifdef HAVE_TGETENT
# ifdef HAVE_TERMIOS_H
# include <termios.h> // seems to be required for some Linux
# endif
# ifdef HAVE_TERMCAP_H
# include <termcap.h>
# endif
/*
* A few linux systems define outfuntype in termcap.h to be used as the third
* argument for tputs().
*/
# if defined(VMS) || defined(AMIGA)
# define TPUTSFUNCAST (void (*)(unsigned int))
# else
# ifdef HAVE_OUTFUNTYPE
# define TPUTSFUNCAST (outfuntype)
# else
# define TPUTSFUNCAST (int (*)(int))
# endif
# endif
#endif
#undef tgetstr
// start of keys that are not directly used by Vim but can be mapped
#define BT_EXTRA_KEYS 0x101
static void parse_builtin_tcap(char_u *s);
static void gather_termleader(void);
#ifdef FEAT_TERMRESPONSE
static void req_codes_from_term(void);
static void req_more_codes_from_term(void);
static void got_code_from_term(char_u *code, int len);
static void check_for_codes_from_term(void);
#endif
static void del_termcode_idx(int idx);
static int find_term_bykeys(char_u *src);
static int term_is_builtin(char_u *name);
static int term_7to8bit(char_u *p);
static void accept_modifiers_for_function_keys(void);
// Change this to "if 1" to debug what happens with termresponse.
# if 0
# define DEBUG_TERMRESPONSE
static void log_tr(const char *fmt, ...) ATTRIBUTE_FORMAT_PRINTF(1, 2);
# define LOG_TR(msg) log_tr msg
# else
# define LOG_TR(msg) do { /**/ } while (0)
# endif
#ifdef HAVE_TGETENT
static char *invoke_tgetent(char_u *, char_u *);
/*
* Here is our own prototype for tgetstr(), any prototypes from the include
* files have been disabled by the define at the start of this file.
*/
char *tgetstr(char *, char **);
#endif
typedef enum {
STATUS_GET, // send request when switching to RAW mode
STATUS_SENT, // did send request, checking for response
STATUS_GOT, // received response
STATUS_FAIL // timed out
} request_progress_T;
typedef struct {
request_progress_T tr_progress;
time_t tr_start; // when request was sent, -1 for never
} termrequest_T;
# define TERMREQUEST_INIT {STATUS_GET, -1}
// Request Terminal Version status:
static termrequest_T crv_status = TERMREQUEST_INIT;
// Request Cursor position report:
static termrequest_T u7_status = TERMREQUEST_INIT;
// Request xterm compatibility check:
static termrequest_T xcc_status = TERMREQUEST_INIT;
#ifdef FEAT_TERMRESPONSE
# ifdef FEAT_TERMINAL
// Request foreground color report:
static termrequest_T rfg_status = TERMREQUEST_INIT;
static int fg_r = 0;
static int fg_g = 0;
static int fg_b = 0;
static int bg_r = 255;
static int bg_g = 255;
static int bg_b = 255;
# endif
// Request background color report:
static termrequest_T rbg_status = TERMREQUEST_INIT;
// Request cursor blinking mode report:
static termrequest_T rbm_status = TERMREQUEST_INIT;
// Request cursor style report:
static termrequest_T rcs_status = TERMREQUEST_INIT;
// Request window's position report:
static termrequest_T winpos_status = TERMREQUEST_INIT;
static termrequest_T *all_termrequests[] = {
&crv_status,
&u7_status,
&xcc_status,
# ifdef FEAT_TERMINAL
&rfg_status,
# endif
&rbg_status,
&rbm_status,
&rcs_status,
&winpos_status,
NULL
};
// The t_8u code may default to a value but get reset when the term response is
// received. To avoid redrawing too often, only redraw when t_8u is not reset
// and it was supposed to be written. Unless t_8u was set explicitly.
// FALSE -> don't output t_8u yet
// MAYBE -> tried outputting t_8u while FALSE
// OK -> can write t_8u
int write_t_8u_state = FALSE;
#endif
#ifdef HAVE_TGETENT
/*
* Don't declare these variables if termcap.h contains them.
* Autoconf checks if these variables should be declared extern (not all
* systems have them).
* Some versions define ospeed to be speed_t, but that is incompatible with
* BSD, where ospeed is short and speed_t is long.
*/
# ifndef HAVE_OSPEED
# ifdef OSPEED_EXTERN
extern short ospeed;
# else
short ospeed;
# endif
# endif
# ifndef HAVE_UP_BC_PC
# ifdef UP_BC_PC_EXTERN
extern char *UP, *BC, PC;
# else
char *UP, *BC, PC;
# endif
# endif
# define TGETSTR(s, p) vim_tgetstr((s), (p))
# define TGETENT(b, t) tgetent((char *)(b), (char *)(t))
static char_u *vim_tgetstr(char *s, char_u **pp);
#endif // HAVE_TGETENT
static int detected_8bit = FALSE; // detected 8-bit terminal
#if (defined(UNIX) || defined(VMS))
static int focus_state = MAYBE; // TRUE if the Vim window has focus
#endif
#ifdef FEAT_TERMRESPONSE
// When the cursor shape was detected these values are used:
// 1: block, 2: underline, 3: vertical bar
static int initial_cursor_shape = 0;
// The blink flag from the style response may be inverted from the actual
// blinking state, xterm XORs the flags.
static int initial_cursor_shape_blink = FALSE;
// The blink flag from the blinking-cursor mode response
static int initial_cursor_blink = FALSE;
#endif
/*
* The builtin termcap entries.
*
* The entries are also included when HAVE_TGETENT is defined, the system
* termcap may be incomplete and a few Vim-specific entries are added.
*
* When HAVE_TGETENT is defined, the builtin entries can be accessed with
* "builtin_amiga", "builtin_ansi", "builtin_debug", etc.
*
* Each termcap is a list of tcap_entry_T. See parse_builtin_tcap() for all
* details.
*
* Entries marked with "guessed" may be wrong.
*/
typedef struct
{
int bt_entry; // either a KS_xxx code (>= 0), or a K_xxx code.
char *bt_string; // value
} tcap_entry_T;
/*
* Standard ANSI terminal, default for Unix.
*/
static tcap_entry_T builtin_ansi[] = {
{(int)KS_CE, "\033[K"},
{(int)KS_AL, "\033[L"},
# ifdef TERMINFO
{(int)KS_CAL, "\033[%p1%dL"},
# else
{(int)KS_CAL, "\033[%dL"},
# endif
{(int)KS_DL, "\033[M"},
# ifdef TERMINFO
{(int)KS_CDL, "\033[%p1%dM"},
# else
{(int)KS_CDL, "\033[%dM"},
# endif
{(int)KS_CL, "\033[H\033[2J"},
{(int)KS_ME, "\033[0m"},
{(int)KS_MR, "\033[7m"},
{(int)KS_MS, "y"},
{(int)KS_UT, "y"}, // guessed
{(int)KS_LE, "\b"},
# ifdef TERMINFO
{(int)KS_CM, "\033[%i%p1%d;%p2%dH"},
# else
{(int)KS_CM, "\033[%i%d;%dH"},
# endif
# ifdef TERMINFO
{(int)KS_CRI, "\033[%p1%dC"},
# else
{(int)KS_CRI, "\033[%dC"},
# endif
{(int)KS_NAME, NULL} // end marker
};
/*
* VT320 is working as an ANSI terminal compatible DEC terminal.
* (it covers VT1x0, VT2x0 and VT3x0 up to VT320 on VMS as well)
* TODO:- rewrite ESC[ codes to CSI
* - keyboard languages (CSI ? 26 n)
*/
static tcap_entry_T builtin_vt320[] = {
{(int)KS_CE, "\033[K"},
{(int)KS_AL, "\033[L"},
# ifdef TERMINFO
{(int)KS_CAL, "\033[%p1%dL"},
# else
{(int)KS_CAL, "\033[%dL"},
# endif
{(int)KS_DL, "\033[M"},
# ifdef TERMINFO
{(int)KS_CDL, "\033[%p1%dM"},
# else
{(int)KS_CDL, "\033[%dM"},
# endif
{(int)KS_CL, "\033[H\033[2J"},
{(int)KS_CD, "\033[J"},
{(int)KS_CCO, "8"}, // allow 8 colors
{(int)KS_ME, "\033[0m"},
{(int)KS_MR, "\033[7m"},
{(int)KS_MD, "\033[1m"}, // bold mode
{(int)KS_SE, "\033[22m"},// normal mode
{(int)KS_UE, "\033[24m"},// exit underscore mode
{(int)KS_US, "\033[4m"}, // underscore mode
{(int)KS_CZH, "\033[34;43m"}, // italic mode: blue text on yellow
{(int)KS_CZR, "\033[0m"}, // italic mode end
{(int)KS_CAB, "\033[4%dm"}, // set background color (ANSI)
{(int)KS_CAF, "\033[3%dm"}, // set foreground color (ANSI)
{(int)KS_CSB, "\033[102;%dm"}, // set screen background color
{(int)KS_CSF, "\033[101;%dm"}, // set screen foreground color
{(int)KS_MS, "y"},
{(int)KS_UT, "y"},
{(int)KS_XN, "y"},
{(int)KS_LE, "\b"},
# ifdef TERMINFO
{(int)KS_CM, "\033[%i%p1%d;%p2%dH"},
# else
{(int)KS_CM, "\033[%i%d;%dH"},
# endif
# ifdef TERMINFO
{(int)KS_CRI, "\033[%p1%dC"},
# else
{(int)KS_CRI, "\033[%dC"},
# endif
{K_UP, "\033[A"},
{K_DOWN, "\033[B"},
{K_RIGHT, "\033[C"},
{K_LEFT, "\033[D"},
// Note: cursor key sequences for application cursor mode are omitted,
// because they interfere with typed commands: <Esc>OA.
{K_F1, "\033[11~"},
{K_F2, "\033[12~"},
{K_F3, "\033[13~"},
{K_F4, "\033[14~"},
{K_F5, "\033[15~"},
{K_F6, "\033[17~"},
{K_F7, "\033[18~"},
{K_F8, "\033[19~"},
{K_F9, "\033[20~"},
{K_F10, "\033[21~"},
{K_F11, "\033[23~"},
{K_F12, "\033[24~"},
{K_F13, "\033[25~"},
{K_F14, "\033[26~"},
{K_F15, "\033[28~"}, // Help
{K_F16, "\033[29~"}, // Select
{K_F17, "\033[31~"},
{K_F18, "\033[32~"},
{K_F19, "\033[33~"},
{K_F20, "\033[34~"},
{K_INS, "\033[2~"},
{K_DEL, "\033[3~"},
{K_HOME, "\033[1~"},
{K_END, "\033[4~"},
{K_PAGEUP, "\033[5~"},
{K_PAGEDOWN, "\033[6~"},
// These sequences starting with <Esc> O may interfere with what the user
// is typing. Remove these if that bothers you.
{K_KPLUS, "\033Ok"}, // keypad plus
{K_KMINUS, "\033Om"}, // keypad minus
{K_KDIVIDE, "\033Oo"}, // keypad /
{K_KMULTIPLY, "\033Oj"}, // keypad *
{K_KENTER, "\033OM"}, // keypad Enter
{K_K0, "\033Op"}, // keypad 0
{K_K1, "\033Oq"}, // keypad 1
{K_K2, "\033Or"}, // keypad 2
{K_K3, "\033Os"}, // keypad 3
{K_K4, "\033Ot"}, // keypad 4
{K_K5, "\033Ou"}, // keypad 5
{K_K6, "\033Ov"}, // keypad 6
{K_K7, "\033Ow"}, // keypad 7
{K_K8, "\033Ox"}, // keypad 8
{K_K9, "\033Oy"}, // keypad 9
{K_BS, "\x7f"}, // for some reason 0177 doesn't work
{(int)KS_NAME, NULL} // end marker
};
/*
* Ordinary vt52
*/
static tcap_entry_T builtin_vt52[] = {
{(int)KS_CE, "\033K"},
{(int)KS_CD, "\033J"},
# ifdef TERMINFO
{(int)KS_CM, "\033Y%p1%' '%+%c%p2%' '%+%c"},
# else
{(int)KS_CM, "\033Y%+ %+ "},
# endif
{(int)KS_LE, "\b"},
{(int)KS_SR, "\033I"},
{(int)KS_AL, "\033L"},
{(int)KS_DL, "\033M"},
{K_UP, "\033A"},
{K_DOWN, "\033B"},
{K_LEFT, "\033D"},
{K_RIGHT, "\033C"},
{K_F1, "\033P"},
{K_F2, "\033Q"},
{K_F3, "\033R"},
{(int)KS_CL, "\033H\033J"},
{(int)KS_MS, "y"},
{(int)KS_NAME, NULL} // end marker
};
/*
* Builtin xterm with Vim-specific entries.
*/
static tcap_entry_T builtin_xterm[] = {
{(int)KS_CE, "\033[K"},
{(int)KS_AL, "\033[L"},
# ifdef TERMINFO
{(int)KS_CAL, "\033[%p1%dL"},
# else
{(int)KS_CAL, "\033[%dL"},
# endif
{(int)KS_DL, "\033[M"},
# ifdef TERMINFO
{(int)KS_CDL, "\033[%p1%dM"},
# else
{(int)KS_CDL, "\033[%dM"},
# endif
# ifdef TERMINFO
{(int)KS_CS, "\033[%i%p1%d;%p2%dr"},
# else
{(int)KS_CS, "\033[%i%d;%dr"},
# endif
{(int)KS_CL, "\033[H\033[2J"},
{(int)KS_CD, "\033[J"},
{(int)KS_ME, "\033[m"},
{(int)KS_MR, "\033[7m"},
{(int)KS_MD, "\033[1m"},
{(int)KS_UE, "\033[m"},
{(int)KS_US, "\033[4m"},
{(int)KS_STE, "\033[29m"},
{(int)KS_STS, "\033[9m"},
{(int)KS_MS, "y"},
{(int)KS_UT, "y"},
{(int)KS_LE, "\b"},
{(int)KS_VI, "\033[?25l"},
{(int)KS_VE, "\033[?25h"},
{(int)KS_VS, "\033[?12h"},
{(int)KS_CVS, "\033[?12l"},
# ifdef TERMINFO
{(int)KS_CSH, "\033[%p1%d q"},
# else
{(int)KS_CSH, "\033[%d q"},
# endif
{(int)KS_CRC, "\033[?12$p"},
{(int)KS_CRS, "\033P$q q\033\\"},
# ifdef TERMINFO
{(int)KS_CM, "\033[%i%p1%d;%p2%dH"},
# else
{(int)KS_CM, "\033[%i%d;%dH"},
# endif
{(int)KS_SR, "\033M"},
# ifdef TERMINFO
{(int)KS_CRI, "\033[%p1%dC"},
# else
{(int)KS_CRI, "\033[%dC"},
# endif
{(int)KS_KS, "\033[?1h\033="},
{(int)KS_KE, "\033[?1l\033>"},
# ifdef FEAT_XTERM_SAVE
{(int)KS_TI, "\0337\033[?47h"},
{(int)KS_TE, "\033[?47l\0338"},
# endif
// These are now under control of the 'keyprotocol' option, see
// "builtin_mok2".
// {(int)KS_CTI, "\033[>4;2m"},
// {(int)KS_CRK, "\033[?4m"},
// {(int)KS_CTE, "\033[>4;m"},
{(int)KS_CIS, "\033]1;"},
{(int)KS_CIE, "\007"},
{(int)KS_TS, "\033]2;"},
{(int)KS_FS, "\007"},
{(int)KS_CSC, "\033]12;"},
{(int)KS_CEC, "\007"},
# ifdef TERMINFO
{(int)KS_CWS, "\033[8;%p1%d;%p2%dt"},
{(int)KS_CWP, "\033[3;%p1%d;%p2%dt"},
{(int)KS_CGP, "\033[13t"},
# else
{(int)KS_CWS, "\033[8;%d;%dt"},
{(int)KS_CWP, "\033[3;%d;%dt"},
{(int)KS_CGP, "\033[13t"},
# endif
{(int)KS_CRV, "\033[>c"},
{(int)KS_CXM, "\033[?1006;1000%?%p1%{1}%=%th%el%;"},
{(int)KS_RFG, "\033]10;?\007"},
{(int)KS_RBG, "\033]11;?\007"},
{(int)KS_U7, "\033[6n"},
{(int)KS_CAU, "\033[58;5;%dm"},
{(int)KS_CBE, "\033[?2004h"},
{(int)KS_CBD, "\033[?2004l"},
{(int)KS_CST, "\033[22;2t"},
{(int)KS_CRT, "\033[23;2t"},
{(int)KS_SSI, "\033[22;1t"},
{(int)KS_SRI, "\033[23;1t"},
# if (defined(UNIX) || defined(VMS))
{(int)KS_FD, "\033[?1004l"},
{(int)KS_FE, "\033[?1004h"},
# endif
{K_UP, "\033O*A"},
{K_DOWN, "\033O*B"},
{K_RIGHT, "\033O*C"},
{K_LEFT, "\033O*D"},
// An extra set of cursor keys for vt100 mode
{K_XUP, "\033[@;*A"}, // Esc [ A or Esc [ 1 ; A
{K_XDOWN, "\033[@;*B"}, // Esc [ B or Esc [ 1 ; B
{K_XRIGHT, "\033[@;*C"}, // Esc [ C or Esc [ 1 ; C
{K_XLEFT, "\033[@;*D"}, // Esc [ D or Esc [ 1 ; D
// An extra set of function keys for vt100 mode
{K_XF1, "\033O*P"},
{K_XF2, "\033O*Q"},
{K_XF3, "\033O*R"},
{K_XF4, "\033O*S"},
{K_F1, "\033[11;*~"},
{K_F2, "\033[12;*~"},
{K_F3, "\033[13;*~"},
{K_F4, "\033[14;*~"},
{K_F5, "\033[15;*~"},
{K_F6, "\033[17;*~"},
{K_F7, "\033[18;*~"},
{K_F8, "\033[19;*~"},
{K_F9, "\033[20;*~"},
{K_F10, "\033[21;*~"},
{K_F11, "\033[23;*~"},
{K_F12, "\033[24;*~"},
{K_S_TAB, "\033[Z"},
{K_HELP, "\033[28;*~"},
{K_UNDO, "\033[26;*~"},
{K_INS, "\033[2;*~"},
{K_HOME, "\033[@;*H"}, // Esc [ H or Esc 1 ; H
// {K_S_HOME, "\033O2H"},
// {K_C_HOME, "\033O5H"},
{K_KHOME, "\033[1;*~"},
{K_XHOME, "\033O*H"}, // other Home
{K_ZHOME, "\033[7;*~"}, // other Home
{K_END, "\033[@;*F"}, // Esc [ F or Esc 1 ; F
// {K_S_END, "\033O2F"},
// {K_C_END, "\033O5F"},
{K_KEND, "\033[4;*~"},
{K_XEND, "\033O*F"}, // other End
{K_ZEND, "\033[8;*~"},
{K_PAGEUP, "\033[5;*~"},
{K_PAGEDOWN, "\033[6;*~"},
{K_KPLUS, "\033O*k"}, // keypad plus
{K_KMINUS, "\033O*m"}, // keypad minus
{K_KDIVIDE, "\033O*o"}, // keypad /
{K_KMULTIPLY, "\033O*j"}, // keypad *
{K_KENTER, "\033O*M"}, // keypad Enter
{K_KPOINT, "\033O*n"}, // keypad .
{K_K0, "\033O*p"}, // keypad 0
{K_K1, "\033O*q"}, // keypad 1
{K_K2, "\033O*r"}, // keypad 2
{K_K3, "\033O*s"}, // keypad 3
{K_K4, "\033O*t"}, // keypad 4
{K_K5, "\033O*u"}, // keypad 5
{K_K6, "\033O*v"}, // keypad 6
{K_K7, "\033O*w"}, // keypad 7
{K_K8, "\033O*x"}, // keypad 8
{K_K9, "\033O*y"}, // keypad 9
{K_KDEL, "\033[3;*~"}, // keypad Del
{K_PS, "\033[200~"}, // paste start
{K_PE, "\033[201~"}, // paste end
{BT_EXTRA_KEYS, ""},
{TERMCAP2KEY('k', '0'), "\033[10;*~"}, // F0
{TERMCAP2KEY('F', '3'), "\033[25;*~"}, // F13
// F14 and F15 are missing, because they send the same codes as the undo
// and help key, although they don't work on all keyboards.
{TERMCAP2KEY('F', '6'), "\033[29;*~"}, // F16
{TERMCAP2KEY('F', '7'), "\033[31;*~"}, // F17
{TERMCAP2KEY('F', '8'), "\033[32;*~"}, // F18
{TERMCAP2KEY('F', '9'), "\033[33;*~"}, // F19
{TERMCAP2KEY('F', 'A'), "\033[34;*~"}, // F20
{TERMCAP2KEY('F', 'B'), "\033[42;*~"}, // F21
{TERMCAP2KEY('F', 'C'), "\033[43;*~"}, // F22
{TERMCAP2KEY('F', 'D'), "\033[44;*~"}, // F23
{TERMCAP2KEY('F', 'E'), "\033[45;*~"}, // F24
{TERMCAP2KEY('F', 'F'), "\033[46;*~"}, // F25
{TERMCAP2KEY('F', 'G'), "\033[47;*~"}, // F26
{TERMCAP2KEY('F', 'H'), "\033[48;*~"}, // F27
{TERMCAP2KEY('F', 'I'), "\033[49;*~"}, // F28
{TERMCAP2KEY('F', 'J'), "\033[50;*~"}, // F29
{TERMCAP2KEY('F', 'K'), "\033[51;*~"}, // F30
{TERMCAP2KEY('F', 'L'), "\033[52;*~"}, // F31
{TERMCAP2KEY('F', 'M'), "\033[53;*~"}, // F32
{TERMCAP2KEY('F', 'N'), "\033[54;*~"}, // F33
{TERMCAP2KEY('F', 'O'), "\033[55;*~"}, // F34
{TERMCAP2KEY('F', 'P'), "\033[56;*~"}, // F35
{TERMCAP2KEY('F', 'Q'), "\033[57;*~"}, // F36
{TERMCAP2KEY('F', 'R'), "\033[58;*~"}, // F37
{(int)KS_NAME, NULL} // end marker
};
/*
* Additions for using modifyOtherKeys level 2. Same as what is used for
* xterm.
*/
static tcap_entry_T builtin_mok2[] = {
// t_TI enables modifyOtherKeys level 2
{(int)KS_CTI, "\033[>4;2m"},
// XTQMODKEYS was added in xterm version 377: "CSI ? 4 m" which should
// return "{lead} > 4 ; Pv m". Before version 377 we expect it to have no
// effect.
{(int)KS_CRK, "\033[?4m"},
// t_TE disables modifyOtherKeys
{(int)KS_CTE, "\033[>4;m"},
{(int)KS_NAME, NULL} // end marker
};
/*
* Additions for using the Kitty keyboard protocol.
*/
static tcap_entry_T builtin_kitty[] = {
// t_TI enables the kitty keyboard protocol.
{(int)KS_CTI, "\033[=1;1u"},
// t_RK requests the kitty keyboard protocol state
{(int)KS_CRK, "\033[?u"},
// t_TE also disables modifyOtherKeys, because t_TI from xterm may already
// have been used.
{(int)KS_CTE, "\033[>4;m\033[=0;1u"},
{(int)KS_NAME, NULL} // end marker
};
#ifdef FEAT_TERMGUICOLORS
/*
* Additions for using the RGB colors
*/
static tcap_entry_T builtin_rgb[] = {
// These are printf strings, not terminal codes.
{(int)KS_8F, "\033[38;2;%lu;%lu;%lum"},
{(int)KS_8B, "\033[48;2;%lu;%lu;%lum"},
{(int)KS_8U, "\033[58;2;%lu;%lu;%lum"},
{(int)KS_NAME, NULL} // end marker
};
#endif
/*
* iris-ansi for Silicon Graphics machines.
*/
static tcap_entry_T builtin_iris_ansi[] = {
{(int)KS_CE, "\033[K"},
{(int)KS_CD, "\033[J"},
{(int)KS_AL, "\033[L"},
# ifdef TERMINFO
{(int)KS_CAL, "\033[%p1%dL"},
# else
{(int)KS_CAL, "\033[%dL"},
# endif
{(int)KS_DL, "\033[M"},
# ifdef TERMINFO
{(int)KS_CDL, "\033[%p1%dM"},
# else
{(int)KS_CDL, "\033[%dM"},
# endif
#if 0 // The scroll region is not working as Vim expects.
# ifdef TERMINFO
{(int)KS_CS, "\033[%i%p1%d;%p2%dr"},
# else
{(int)KS_CS, "\033[%i%d;%dr"},
# endif
#endif
{(int)KS_CL, "\033[H\033[2J"},
{(int)KS_VE, "\033[9/y\033[12/y"}, // These aren't documented
{(int)KS_VS, "\033[10/y\033[=1h\033[=2l"}, // These aren't documented
{(int)KS_TI, "\033[=6h"},
{(int)KS_TE, "\033[=6l"},
{(int)KS_SE, "\033[21;27m"},
{(int)KS_SO, "\033[1;7m"},
{(int)KS_ME, "\033[m"},
{(int)KS_MR, "\033[7m"},
{(int)KS_MD, "\033[1m"},
{(int)KS_CCO, "8"}, // allow 8 colors
{(int)KS_CZH, "\033[3m"}, // italic mode on
{(int)KS_CZR, "\033[23m"}, // italic mode off
{(int)KS_US, "\033[4m"}, // underline on
{(int)KS_UE, "\033[24m"}, // underline off
# ifdef TERMINFO
{(int)KS_CAB, "\033[4%p1%dm"}, // set background color (ANSI)
{(int)KS_CAF, "\033[3%p1%dm"}, // set foreground color (ANSI)
{(int)KS_CSB, "\033[102;%p1%dm"}, // set screen background color
{(int)KS_CSF, "\033[101;%p1%dm"}, // set screen foreground color
# else
{(int)KS_CAB, "\033[4%dm"}, // set background color (ANSI)
{(int)KS_CAF, "\033[3%dm"}, // set foreground color (ANSI)
{(int)KS_CSB, "\033[102;%dm"}, // set screen background color
{(int)KS_CSF, "\033[101;%dm"}, // set screen foreground color
# endif
{(int)KS_MS, "y"}, // guessed
{(int)KS_UT, "y"}, // guessed
{(int)KS_LE, "\b"},
# ifdef TERMINFO
{(int)KS_CM, "\033[%i%p1%d;%p2%dH"},
# else
{(int)KS_CM, "\033[%i%d;%dH"},
# endif
{(int)KS_SR, "\033M"},
# ifdef TERMINFO
{(int)KS_CRI, "\033[%p1%dC"},
# else
{(int)KS_CRI, "\033[%dC"},
# endif
{(int)KS_CIS, "\033P3.y"},
{(int)KS_CIE, "\234"}, // ST "String Terminator"
{(int)KS_TS, "\033P1.y"},
{(int)KS_FS, "\234"}, // ST "String Terminator"
# ifdef TERMINFO
{(int)KS_CWS, "\033[203;%p1%d;%p2%d/y"},
{(int)KS_CWP, "\033[205;%p1%d;%p2%d/y"},
# else
{(int)KS_CWS, "\033[203;%d;%d/y"},
{(int)KS_CWP, "\033[205;%d;%d/y"},
# endif
{K_UP, "\033[A"},
{K_DOWN, "\033[B"},
{K_LEFT, "\033[D"},
{K_RIGHT, "\033[C"},
{K_S_UP, "\033[161q"},
{K_S_DOWN, "\033[164q"},
{K_S_LEFT, "\033[158q"},
{K_S_RIGHT, "\033[167q"},
{K_F1, "\033[001q"},
{K_F2, "\033[002q"},
{K_F3, "\033[003q"},
{K_F4, "\033[004q"},
{K_F5, "\033[005q"},
{K_F6, "\033[006q"},
{K_F7, "\033[007q"},
{K_F8, "\033[008q"},
{K_F9, "\033[009q"},
{K_F10, "\033[010q"},
{K_F11, "\033[011q"},
{K_F12, "\033[012q"},
{K_S_F1, "\033[013q"},
{K_S_F2, "\033[014q"},
{K_S_F3, "\033[015q"},
{K_S_F4, "\033[016q"},
{K_S_F5, "\033[017q"},
{K_S_F6, "\033[018q"},
{K_S_F7, "\033[019q"},
{K_S_F8, "\033[020q"},
{K_S_F9, "\033[021q"},
{K_S_F10, "\033[022q"},
{K_S_F11, "\033[023q"},
{K_S_F12, "\033[024q"},
{K_INS, "\033[139q"},
{K_HOME, "\033[H"},
{K_END, "\033[146q"},
{K_PAGEUP, "\033[150q"},
{K_PAGEDOWN, "\033[154q"},
{(int)KS_NAME, NULL} // end marker
};
/*
* These codes are valid when nansi.sys or equivalent has been installed.
* Function keys on a PC are preceded with a NUL. These are converted into
* K_NUL '\316' in mch_inchar(), because we cannot handle NULs in key codes.
* CTRL-arrow is used instead of SHIFT-arrow.
*/
static tcap_entry_T builtin_pcansi[] = {
{(int)KS_DL, "\033[M"},
{(int)KS_AL, "\033[L"},
{(int)KS_CE, "\033[K"},
{(int)KS_CL, "\033[2J"},
{(int)KS_ME, "\033[0m"},
{(int)KS_MR, "\033[5m"}, // reverse: black on lightgrey
{(int)KS_MD, "\033[1m"}, // bold: white text
{(int)KS_SE, "\033[0m"}, // standout end
{(int)KS_SO, "\033[31m"}, // standout: white on blue
{(int)KS_CZH, "\033[34;43m"}, // italic mode: blue text on yellow
{(int)KS_CZR, "\033[0m"}, // italic mode end
{(int)KS_US, "\033[36;41m"}, // underscore mode: cyan text on red
{(int)KS_UE, "\033[0m"}, // underscore mode end
{(int)KS_CCO, "8"}, // allow 8 colors
# ifdef TERMINFO
{(int)KS_CAB, "\033[4%p1%dm"},// set background color
{(int)KS_CAF, "\033[3%p1%dm"},// set foreground color
# else
{(int)KS_CAB, "\033[4%dm"}, // set background color
{(int)KS_CAF, "\033[3%dm"}, // set foreground color
# endif
{(int)KS_OP, "\033[0m"}, // reset colors
{(int)KS_MS, "y"},
{(int)KS_UT, "y"}, // guessed
{(int)KS_LE, "\b"},
# ifdef TERMINFO
{(int)KS_CM, "\033[%i%p1%d;%p2%dH"},
# else
{(int)KS_CM, "\033[%i%d;%dH"},
# endif
# ifdef TERMINFO
{(int)KS_CRI, "\033[%p1%dC"},
# else
{(int)KS_CRI, "\033[%dC"},
# endif
{K_UP, "\316H"},
{K_DOWN, "\316P"},
{K_LEFT, "\316K"},
{K_RIGHT, "\316M"},
{K_S_LEFT, "\316s"},
{K_S_RIGHT, "\316t"},
{K_F1, "\316;"},
{K_F2, "\316<"},
{K_F3, "\316="},
{K_F4, "\316>"},
{K_F5, "\316?"},
{K_F6, "\316@"},
{K_F7, "\316A"},
{K_F8, "\316B"},
{K_F9, "\316C"},
{K_F10, "\316D"},
{K_F11, "\316\205"}, // guessed
{K_F12, "\316\206"}, // guessed
{K_S_F1, "\316T"},
{K_S_F2, "\316U"},
{K_S_F3, "\316V"},
{K_S_F4, "\316W"},
{K_S_F5, "\316X"},
{K_S_F6, "\316Y"},
{K_S_F7, "\316Z"},
{K_S_F8, "\316["},
{K_S_F9, "\316\\"},
{K_S_F10, "\316]"},
{K_S_F11, "\316\207"}, // guessed
{K_S_F12, "\316\210"}, // guessed
{K_INS, "\316R"},
{K_DEL, "\316S"},
{K_HOME, "\316G"},
{K_END, "\316O"},
{K_PAGEDOWN, "\316Q"},
{K_PAGEUP, "\316I"},
{(int)KS_NAME, NULL} // end marker
};
/*
* These codes are valid for the Win32 Console. The entries that start with
* ESC | are translated into console calls in os_win32.c. The function keys
* are also translated in os_win32.c.
*/
static tcap_entry_T builtin_win32[] = {
{(int)KS_CE, "\033|K"}, // clear to end of line
{(int)KS_AL, "\033|L"}, // add new blank line
# ifdef TERMINFO
{(int)KS_CAL, "\033|%p1%dL"}, // add number of new blank lines
# else
{(int)KS_CAL, "\033|%dL"}, // add number of new blank lines
# endif
{(int)KS_DL, "\033|M"}, // delete line
# ifdef TERMINFO
{(int)KS_CDL, "\033|%p1%dM"}, // delete number of lines
{(int)KS_CSV, "\033|%p1%d;%p2%dV"},
# else
{(int)KS_CDL, "\033|%dM"}, // delete number of lines
{(int)KS_CSV, "\033|%d;%dV"},
# endif
{(int)KS_CL, "\033|J"}, // clear screen
{(int)KS_CD, "\033|j"}, // clear to end of display
{(int)KS_VI, "\033|v"}, // cursor invisible
{(int)KS_VE, "\033|V"}, // cursor visible
{(int)KS_ME, "\033|0m"}, // normal
{(int)KS_MR, "\033|112m"}, // reverse: black on lightgray
{(int)KS_MD, "\033|15m"}, // bold: white on black
#if 1
{(int)KS_SO, "\033|31m"}, // standout: white on blue
{(int)KS_SE, "\033|0m"}, // standout end
#else
{(int)KS_SO, "\033|F"}, // standout: high intensity
{(int)KS_SE, "\033|f"}, // standout end
#endif
{(int)KS_CZH, "\033|225m"}, // italic: blue text on yellow
{(int)KS_CZR, "\033|0m"}, // italic end
{(int)KS_US, "\033|67m"}, // underscore: cyan text on red
{(int)KS_UE, "\033|0m"}, // underscore end
{(int)KS_CCO, "16"}, // allow 16 colors
# ifdef TERMINFO
{(int)KS_CAB, "\033|%p1%db"}, // set background color
{(int)KS_CAF, "\033|%p1%df"}, // set foreground color
# else
{(int)KS_CAB, "\033|%db"}, // set background color
{(int)KS_CAF, "\033|%df"}, // set foreground color
# endif
{(int)KS_MS, "y"}, // save to move cur in reverse mode
{(int)KS_UT, "y"},
{(int)KS_XN, "y"},
{(int)KS_LE, "\b"},
# ifdef TERMINFO
{(int)KS_CM, "\033|%i%p1%d;%p2%dH"}, // cursor motion
# else
{(int)KS_CM, "\033|%i%d;%dH"}, // cursor motion
# endif
{(int)KS_VB, "\033|B"}, // visual bell
{(int)KS_TI, "\033|S"}, // put terminal in termcap mode
{(int)KS_TE, "\033|E"}, // out of termcap mode
# ifdef TERMINFO
{(int)KS_CS, "\033|%i%p1%d;%p2%dr"}, // scroll region
# else
{(int)KS_CS, "\033|%i%d;%dr"}, // scroll region
# endif
{K_UP, "\316H"},
{K_DOWN, "\316P"},
{K_LEFT, "\316K"},
{K_RIGHT, "\316M"},
{K_S_UP, "\316\304"},
{K_S_DOWN, "\316\317"},
{K_S_LEFT, "\316\311"},
{K_C_LEFT, "\316s"},
{K_S_RIGHT, "\316\313"},
{K_C_RIGHT, "\316t"},
{K_S_TAB, "\316\017"},
{K_F1, "\316;"},
{K_F2, "\316<"},
{K_F3, "\316="},
{K_F4, "\316>"},
{K_F5, "\316?"},
{K_F6, "\316@"},
{K_F7, "\316A"},
{K_F8, "\316B"},
{K_F9, "\316C"},
{K_F10, "\316D"},
{K_F11, "\316\205"},
{K_F12, "\316\206"},
{K_S_F1, "\316T"},
{K_S_F2, "\316U"},
{K_S_F3, "\316V"},
{K_S_F4, "\316W"},
{K_S_F5, "\316X"},
{K_S_F6, "\316Y"},
{K_S_F7, "\316Z"},
{K_S_F8, "\316["},
{K_S_F9, "\316\\"},
{K_S_F10, "\316]"},
{K_S_F11, "\316\207"},
{K_S_F12, "\316\210"},
{K_INS, "\316R"},
{K_DEL, "\316S"},
{K_HOME, "\316G"},
{K_S_HOME, "\316\302"},
{K_C_HOME, "\316w"},
{K_END, "\316O"},
{K_S_END, "\316\315"},
{K_C_END, "\316u"},
{K_PAGEDOWN, "\316Q"},
{K_PAGEUP, "\316I"},
{K_KPLUS, "\316N"},
{K_KMINUS, "\316J"},
{K_KMULTIPLY, "\316\067"},
{K_K0, "\316\332"},
{K_K1, "\316\336"},
{K_K2, "\316\342"},
{K_K3, "\316\346"},
{K_K4, "\316\352"},
{K_K5, "\316\356"},
{K_K6, "\316\362"},
{K_K7, "\316\366"},
{K_K8, "\316\372"},
{K_K9, "\316\376"},
{K_BS, "\316x"},
{K_S_BS, "\316y"},
{(int)KS_NAME, NULL} // end marker
};
#if defined(FEAT_GUI)
/*
* GUI uses made-up codes, only used inside Vim.
*/
static tcap_entry_T builtin_gui[] = {
{(int)KS_CE, "\033|$"},
{(int)KS_AL, "\033|i"},
# ifdef TERMINFO
{(int)KS_CAL, "\033|%p1%dI"},
# else
{(int)KS_CAL, "\033|%dI"},
# endif
{(int)KS_DL, "\033|d"},
# ifdef TERMINFO
{(int)KS_CDL, "\033|%p1%dD"},
{(int)KS_CS, "\033|%p1%d;%p2%dR"},
{(int)KS_CSV, "\033|%p1%d;%p2%dV"},
# else
{(int)KS_CDL, "\033|%dD"},
{(int)KS_CS, "\033|%d;%dR"},
{(int)KS_CSV, "\033|%d;%dV"},
# endif
{(int)KS_CL, "\033|C"},
// attributes switched on with 'h', off with * 'H'
{(int)KS_ME, "\033|31H"}, // HL_ALL
{(int)KS_MR, "\033|1h"}, // HL_INVERSE
{(int)KS_MD, "\033|2h"}, // HL_BOLD
{(int)KS_SE, "\033|16H"}, // HL_STANDOUT
{(int)KS_SO, "\033|16h"}, // HL_STANDOUT
{(int)KS_UE, "\033|8H"}, // HL_UNDERLINE
{(int)KS_US, "\033|8h"}, // HL_UNDERLINE