@@ -85,15 +85,15 @@ struct VirtualKey {
85
85
#define S (s ) W(s "\0\0")
86
86
#define W (s ) (s[3] << 24 | s[2] << 16 | s[1] << 8 | s[0])
87
87
88
- static const struct VirtualKey kVirtualKey [] = {
89
- {kNtVkUp , S ("A" ), S ("1;2A" ), S ("1;5A" ), S ("1;6A" )},
90
- {kNtVkDown , S ("B" ), S ("1;2B" ), S ("1;5B" ), S ("1;6B" )},
91
- {kNtVkRight , S ("C" ), S ("1;2C" ), S ("1;5C" ), S ("1;6C" )},
92
- {kNtVkLeft , S ("D" ), S ("1;2D" ), S ("1;5D" ), S ("1;6D" )},
88
+ static struct VirtualKey kVirtualKey [] = {
89
+ {kNtVkUp , S ("A" ), S ("1;2A" ), S ("1;5A" ), S ("1;6A" )}, // order matters
90
+ {kNtVkDown , S ("B" ), S ("1;2B" ), S ("1;5B" ), S ("1;6B" )}, // order matters
91
+ {kNtVkRight , S ("C" ), S ("1;2C" ), S ("1;5C" ), S ("1;6C" )}, // order matters
92
+ {kNtVkLeft , S ("D" ), S ("1;2D" ), S ("1;5D" ), S ("1;6D" )}, // order matters
93
+ {kNtVkEnd , S ("F" ), S ("1;2F" ), S ("1;5F" ), S ("1;6F" )}, // order matters
94
+ {kNtVkHome , S ("H" ), S ("1;2H" ), S ("1;5H" ), S ("1;6H" )}, // order matters
93
95
{kNtVkInsert , S ("2~" ), S ("2;2~" ), S ("2;5~" ), S ("2;6~" )},
94
96
{kNtVkDelete , S ("3~" ), S ("3;2~" ), S ("3;5~" ), S ("3;6~" )},
95
- {kNtVkHome , S ("H" ), S ("1;2H" ), S ("1;5H" ), S ("1;6H" )},
96
- {kNtVkEnd , S ("F" ), S ("1;2F" ), S ("1;5F" ), S ("1;6F" )},
97
97
{kNtVkPrior , S ("5~" ), S ("5;2~" ), S ("5;5~" ), S ("5;6~" )},
98
98
{kNtVkNext , S ("6~" ), S ("6;2~" ), S ("6;5~" ), S ("6;6~" )},
99
99
{kNtVkF1 , - S ("OP" ), S ("1;2P" ), S ("11^" ), S ("1;6P" )},
@@ -111,17 +111,6 @@ static const struct VirtualKey kVirtualKey[] = {
111
111
{0 },
112
112
};
113
113
114
- // TODO: How can we configure `less` to not need this bloat?
115
- static const struct VirtualKey kDecckm [] = {
116
- {kNtVkUp , - S ("OA" ), - S ("OA" ), S ("A" ), S ("A" )},
117
- {kNtVkDown , - S ("OB" ), - S ("OB" ), S ("B" ), S ("B" )},
118
- {kNtVkRight , - S ("OC" ), - S ("OC" ), S ("C" ), S ("C" )},
119
- {kNtVkLeft , - S ("OD" ), - S ("OD" ), S ("D" ), S ("D" )},
120
- {kNtVkPrior , S ("5~" ), S ("5;2~" ), S ("5;5~" ), S ("5;6~" )},
121
- {kNtVkNext , S ("6~" ), S ("6;2~" ), S ("6;5~" ), S ("6;6~" )},
122
- {0 },
123
- };
124
-
125
114
#define KEYSTROKE_CONTAINER (e ) DLL_CONTAINER(struct Keystroke, elem, e)
126
115
127
116
struct Keystroke {
@@ -142,7 +131,6 @@ struct Keystrokes {
142
131
struct Dll * line ;
143
132
struct Dll * free ;
144
133
pthread_mutex_t lock ;
145
- const struct VirtualKey * vkt ;
146
134
struct Keystroke pool [512 ];
147
135
};
148
136
@@ -180,7 +168,6 @@ textwindows static void FreeKeystrokes(struct Dll **list) {
180
168
}
181
169
182
170
textwindows static void OpenConsole (void ) {
183
- __keystroke .vkt = kVirtualKey ;
184
171
__keystroke .cin = CreateFile (u"CONIN$" , kNtGenericRead | kNtGenericWrite ,
185
172
kNtFileShareRead , 0 , kNtOpenExisting , 0 , 0 );
186
173
__keystroke .cot = CreateFile (u"CONOUT$" , kNtGenericRead | kNtGenericWrite ,
@@ -227,16 +214,16 @@ textwindows static bool IsMouseModeCommand(int x) {
227
214
}
228
215
229
216
textwindows static int GetVirtualKey (uint16_t vk , bool shift , bool ctrl ) {
230
- for (int i = 0 ; __keystroke . vkt [i ].vk ; ++ i ) {
231
- if (__keystroke . vkt [i ].vk == vk ) {
217
+ for (int i = 0 ; kVirtualKey [i ].vk ; ++ i ) {
218
+ if (kVirtualKey [i ].vk == vk ) {
232
219
if (shift && ctrl ) {
233
- return __keystroke . vkt [i ].shift_ctrl_str ;
220
+ return kVirtualKey [i ].shift_ctrl_str ;
234
221
} else if (shift ) {
235
- return __keystroke . vkt [i ].shift_str ;
222
+ return kVirtualKey [i ].shift_str ;
236
223
} else if (ctrl ) {
237
- return __keystroke . vkt [i ].ctrl_str ;
224
+ return kVirtualKey [i ].ctrl_str ;
238
225
} else {
239
- return __keystroke . vkt [i ].normal_str ;
226
+ return kVirtualKey [i ].normal_str ;
240
227
}
241
228
}
242
229
}
@@ -737,8 +724,14 @@ textwindows void InterceptTerminalCommands(const char *data, size_t size) {
737
724
x = 0 ;
738
725
} else if (data [i ] == 'h' ) {
739
726
if (x == 1 ) {
740
- __keystroke . vkt = kDecckm ; // \e[?1h decckm on
727
+ // \e[?1h decckm on
741
728
__keystroke .ohno_decckm = true;
729
+ kVirtualKey [0 ].normal_str = - S ("OA" ); // kNtVkUp
730
+ kVirtualKey [1 ].normal_str = - S ("OB" ); // kNtVkDown
731
+ kVirtualKey [2 ].normal_str = - S ("OC" ); // kNtVkRight
732
+ kVirtualKey [3 ].normal_str = - S ("OD" ); // kNtVkLeft
733
+ kVirtualKey [4 ].normal_str = - S ("OF" ); // kNtVkEnd
734
+ kVirtualKey [5 ].normal_str = - S ("OH" ); // kNtVkHome
742
735
} else if ((ismouse |= IsMouseModeCommand (x ))) {
743
736
__ttyconf .magic |= kTtyXtMouse ;
744
737
cm2 |= kNtEnableMouseInput ;
@@ -747,8 +740,14 @@ textwindows void InterceptTerminalCommands(const char *data, size_t size) {
747
740
t = ASC ;
748
741
} else if (data [i ] == 'l' ) {
749
742
if (x == 1 ) {
750
- __keystroke . vkt = kVirtualKey ; // \e[?1l decckm off
743
+ // \e[?1l decckm off
751
744
__keystroke .ohno_decckm = false;
745
+ kVirtualKey [0 ].normal_str = S ("A" ); // kNtVkUp
746
+ kVirtualKey [1 ].normal_str = S ("B" ); // kNtVkDown
747
+ kVirtualKey [2 ].normal_str = S ("C" ); // kNtVkRight
748
+ kVirtualKey [3 ].normal_str = S ("D" ); // kNtVkLeft
749
+ kVirtualKey [4 ].normal_str = S ("F" ); // kNtVkEnd
750
+ kVirtualKey [5 ].normal_str = S ("H" ); // kNtVkHome
752
751
} else if ((ismouse |= IsMouseModeCommand (x ))) {
753
752
__ttyconf .magic &= ~kTtyXtMouse ;
754
753
cm2 |= kNtEnableQuickEditMode ; // release mouse
0 commit comments