annotate src/libvterm/src/keyboard.c @ 13972:255967236075 v8.1.0004

patch 8.1.0004: test for :compiler command sometimes fails commit https://github.com/vim/vim/commit/54651f74948650bc68d6ac5b20376f2f985e80c5 Author: Bram Moolenaar <Bram@vim.org> Date: Sat May 19 15:52:11 2018 +0200 patch 8.1.0004: test for :compiler command sometimes fails Problem: Test for :compiler command sometimes fails. Solution: Be less strict about the error message. (Dominique Pelle)
author Christian Brabandt <cb@256bit.org>
date Sat, 19 May 2018 16:00:07 +0200
parents 2449b6ce1456
children 811a12a78164
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 #include "vterm_internal.h"
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 #include <stdio.h>
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 #include "utf8.h"
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 void vterm_keyboard_unichar(VTerm *vt, uint32_t c, VTermModifier mod)
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 {
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 int needs_CSIu;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 /* The shift modifier is never important for Unicode characters
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 * apart from Space
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 */
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 if(c != ' ')
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 mod &= ~VTERM_MOD_SHIFT;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 if(mod == 0) {
13770
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
18 // Normal text - ignore just shift
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 char str[6];
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 int seqlen = fill_utf8(c, str);
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 vterm_push_output_bytes(vt, str, seqlen);
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 return;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 }
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 switch(c) {
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 /* Special Ctrl- letters that can't be represented elsewise */
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 case 'i': case 'j': case 'm': case '[':
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 needs_CSIu = 1;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 break;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 /* Ctrl-\ ] ^ _ don't need CSUu */
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 case '\\': case ']': case '^': case '_':
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 needs_CSIu = 0;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 break;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 /* Shift-space needs CSIu */
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 case ' ':
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 needs_CSIu = !!(mod & VTERM_MOD_SHIFT);
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 break;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 /* All other characters needs CSIu except for letters a-z */
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 default:
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 needs_CSIu = (c < 'a' || c > 'z');
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 }
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 /* ALT we can just prefix with ESC; anything else requires CSI u */
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 if(needs_CSIu && (mod & ~VTERM_MOD_ALT)) {
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 vterm_push_output_sprintf_ctrl(vt, C1_CSI, "%d;%du", c, mod+1);
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 return;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 }
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 if(mod & VTERM_MOD_CTRL)
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 c &= 0x1f;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 vterm_push_output_sprintf(vt, "%s%c", mod & VTERM_MOD_ALT ? ESC_S : "", c);
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 }
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 typedef struct {
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56 enum {
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 KEYCODE_NONE,
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58 KEYCODE_LITERAL,
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59 KEYCODE_TAB,
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60 KEYCODE_ENTER,
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61 KEYCODE_SS3,
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 KEYCODE_CSI,
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63 KEYCODE_CSI_CURSOR,
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 KEYCODE_CSINUM,
13770
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
65 KEYCODE_KEYPAD,
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66 } type;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67 char literal;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68 int csinum;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69 } keycodes_s;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70
11761
7846efd291d7 patch 8.0.0763: libvterm can be improved
Christian Brabandt <cb@256bit.org>
parents: 11621
diff changeset
71 /* Order here must be exactly the same as VTermKey enum! */
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72 static keycodes_s keycodes[] = {
13770
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
73 { KEYCODE_NONE, 0, 0 }, // NONE
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
74
13770
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
75 { KEYCODE_ENTER, '\r', 0 }, // ENTER
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
76 { KEYCODE_TAB, '\t', 0 }, // TAB
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
77 { KEYCODE_LITERAL, '\x7f', 0 }, // BACKSPACE == ASCII DEL
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
78 { KEYCODE_LITERAL, '\x1b', 0 }, // ESCAPE
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79
13770
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
80 { KEYCODE_CSI_CURSOR, 'A', 0 }, // UP
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
81 { KEYCODE_CSI_CURSOR, 'B', 0 }, // DOWN
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
82 { KEYCODE_CSI_CURSOR, 'D', 0 }, // LEFT
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
83 { KEYCODE_CSI_CURSOR, 'C', 0 }, // RIGHT
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
84
13770
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
85 { KEYCODE_CSINUM, '~', 2 }, // INS
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
86 { KEYCODE_CSINUM, '~', 3 }, // DEL
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
87 { KEYCODE_CSI_CURSOR, 'H', 0 }, // HOME
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
88 { KEYCODE_CSI_CURSOR, 'F', 0 }, // END
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
89 { KEYCODE_CSINUM, '~', 5 }, // PAGEUP
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
90 { KEYCODE_CSINUM, '~', 6 }, // PAGEDOWN
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91 };
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
93 static keycodes_s keycodes_fn[] = {
13770
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
94 { KEYCODE_NONE, 0, 0 }, // F0 - shouldn't happen
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
95 { KEYCODE_CSI_CURSOR, 'P', 0 }, // F1
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
96 { KEYCODE_CSI_CURSOR, 'Q', 0 }, // F2
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
97 { KEYCODE_CSI_CURSOR, 'R', 0 }, // F3
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
98 { KEYCODE_CSI_CURSOR, 'S', 0 }, // F4
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
99 { KEYCODE_CSINUM, '~', 15 }, // F5
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
100 { KEYCODE_CSINUM, '~', 17 }, // F6
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
101 { KEYCODE_CSINUM, '~', 18 }, // F7
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
102 { KEYCODE_CSINUM, '~', 19 }, // F8
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
103 { KEYCODE_CSINUM, '~', 20 }, // F9
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
104 { KEYCODE_CSINUM, '~', 21 }, // F10
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
105 { KEYCODE_CSINUM, '~', 23 }, // F11
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
106 { KEYCODE_CSINUM, '~', 24 }, // F12
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
107 };
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
108
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
109 static keycodes_s keycodes_kp[] = {
13770
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
110 { KEYCODE_KEYPAD, '0', 'p' }, // KP_0
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
111 { KEYCODE_KEYPAD, '1', 'q' }, // KP_1
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
112 { KEYCODE_KEYPAD, '2', 'r' }, // KP_2
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
113 { KEYCODE_KEYPAD, '3', 's' }, // KP_3
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
114 { KEYCODE_KEYPAD, '4', 't' }, // KP_4
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
115 { KEYCODE_KEYPAD, '5', 'u' }, // KP_5
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
116 { KEYCODE_KEYPAD, '6', 'v' }, // KP_6
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
117 { KEYCODE_KEYPAD, '7', 'w' }, // KP_7
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
118 { KEYCODE_KEYPAD, '8', 'x' }, // KP_8
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
119 { KEYCODE_KEYPAD, '9', 'y' }, // KP_9
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
120 { KEYCODE_KEYPAD, '*', 'j' }, // KP_MULT
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
121 { KEYCODE_KEYPAD, '+', 'k' }, // KP_PLUS
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
122 { KEYCODE_KEYPAD, ',', 'l' }, // KP_COMMA
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
123 { KEYCODE_KEYPAD, '-', 'm' }, // KP_MINUS
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
124 { KEYCODE_KEYPAD, '.', 'n' }, // KP_PERIOD
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
125 { KEYCODE_KEYPAD, '/', 'o' }, // KP_DIVIDE
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
126 { KEYCODE_KEYPAD, '\n', 'M' }, // KP_ENTER
2449b6ce1456 patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents: 11761
diff changeset
127 { KEYCODE_KEYPAD, '=', 'X' }, // KP_EQUAL
11621
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
128 };
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
129
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
130 void vterm_keyboard_key(VTerm *vt, VTermKey key, VTermModifier mod)
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
131 {
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
132 keycodes_s k;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
133
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
134 if(key == VTERM_KEY_NONE)
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
135 return;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
136
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
137 if(key < VTERM_KEY_FUNCTION_0) {
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
138 if(key >= sizeof(keycodes)/sizeof(keycodes[0]))
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
139 return;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
140 k = keycodes[key];
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
141 }
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
142 else if(key >= VTERM_KEY_FUNCTION_0 && key <= VTERM_KEY_FUNCTION_MAX) {
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
143 if((key - VTERM_KEY_FUNCTION_0) >= sizeof(keycodes_fn)/sizeof(keycodes_fn[0]))
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
144 return;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
145 k = keycodes_fn[key - VTERM_KEY_FUNCTION_0];
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
146 }
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
147 else if(key >= VTERM_KEY_KP_0) {
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
148 if((key - VTERM_KEY_KP_0) >= sizeof(keycodes_kp)/sizeof(keycodes_kp[0]))
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
149 return;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
150 k = keycodes_kp[key - VTERM_KEY_KP_0];
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
151 }
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
152
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
153 switch(k.type) {
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
154 case KEYCODE_NONE:
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
155 break;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
156
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
157 case KEYCODE_TAB:
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
158 /* Shift-Tab is CSI Z but plain Tab is 0x09 */
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
159 if(mod == VTERM_MOD_SHIFT)
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
160 vterm_push_output_sprintf_ctrl(vt, C1_CSI, "Z");
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
161 else if(mod & VTERM_MOD_SHIFT)
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
162 vterm_push_output_sprintf_ctrl(vt, C1_CSI, "1;%dZ", mod+1);
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
163 else
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
164 goto case_LITERAL;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
165 break;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
166
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
167 case KEYCODE_ENTER:
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
168 /* Enter is CRLF in newline mode, but just LF in linefeed */
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
169 if(vt->state->mode.newline)
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
170 vterm_push_output_sprintf(vt, "\r\n");
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
171 else
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
172 goto case_LITERAL;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
173 break;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
174
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
175 case KEYCODE_LITERAL: case_LITERAL:
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
176 if(mod & (VTERM_MOD_SHIFT|VTERM_MOD_CTRL))
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
177 vterm_push_output_sprintf_ctrl(vt, C1_CSI, "%d;%du", k.literal, mod+1);
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
178 else
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
179 vterm_push_output_sprintf(vt, mod & VTERM_MOD_ALT ? ESC_S "%c" : "%c", k.literal);
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
180 break;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
181
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
182 case KEYCODE_SS3: case_SS3:
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
183 if(mod == 0)
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
184 vterm_push_output_sprintf_ctrl(vt, C1_SS3, "%c", k.literal);
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
185 else
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
186 goto case_CSI;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
187 break;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
188
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
189 case KEYCODE_CSI: case_CSI:
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
190 if(mod == 0)
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
191 vterm_push_output_sprintf_ctrl(vt, C1_CSI, "%c", k.literal);
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
192 else
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
193 vterm_push_output_sprintf_ctrl(vt, C1_CSI, "1;%d%c", mod + 1, k.literal);
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
194 break;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
195
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
196 case KEYCODE_CSINUM:
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
197 if(mod == 0)
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
198 vterm_push_output_sprintf_ctrl(vt, C1_CSI, "%d%c", k.csinum, k.literal);
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
199 else
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
200 vterm_push_output_sprintf_ctrl(vt, C1_CSI, "%d;%d%c", k.csinum, mod + 1, k.literal);
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
201 break;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
202
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
203 case KEYCODE_CSI_CURSOR:
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
204 if(vt->state->mode.cursor)
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
205 goto case_SS3;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
206 else
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
207 goto case_CSI;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
208
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
209 case KEYCODE_KEYPAD:
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
210 if(vt->state->mode.keypad) {
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
211 k.literal = k.csinum;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
212 goto case_SS3;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
213 }
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
214 else
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
215 goto case_LITERAL;
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
216 }
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
217 }
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
218
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
219 void vterm_keyboard_start_paste(VTerm *vt)
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
220 {
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
221 if(vt->state->mode.bracketpaste)
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
222 vterm_push_output_sprintf_ctrl(vt, C1_CSI, "200~");
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
223 }
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
224
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
225 void vterm_keyboard_end_paste(VTerm *vt)
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
226 {
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
227 if(vt->state->mode.bracketpaste)
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
228 vterm_push_output_sprintf_ctrl(vt, C1_CSI, "201~");
b8299e742f41 patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
229 }