diff options
Diffstat (limited to '')
-rw-r--r-- | dumbsh.c | 25 |
1 files changed, 14 insertions, 11 deletions
@@ -188,25 +188,30 @@ static struct keyCommand simpleEmacsKeys[] = | |||
188 | }; | 188 | }; |
189 | 189 | ||
190 | // Callback for incoming key sequences from the user. | 190 | // Callback for incoming key sequences from the user. |
191 | static int handleKeySequence(long extra, char *sequence) | 191 | static int handleKeySequence(long extra, char *sequence, int isTranslated) |
192 | { | 192 | { |
193 | int j; | 193 | int j, l = strlen(sequence); |
194 | 194 | ||
195 | // Search for a key sequence bound to a command. | 195 | // Search for a key sequence bound to a command. |
196 | for (j = 0; j < (sizeof(simpleEmacsKeys) / sizeof(*simpleEmacsKeys)); j++) | 196 | for (j = 0; j < (sizeof(simpleEmacsKeys) / sizeof(*simpleEmacsKeys)); j++) |
197 | { | 197 | { |
198 | if (strcmp(simpleEmacsKeys[j].key, sequence) == 0) | 198 | if (strncmp(simpleEmacsKeys[j].key, sequence, l) == 0) |
199 | { | 199 | { |
200 | if (simpleEmacsKeys[j].handler) simpleEmacsKeys[j].handler(); | 200 | // If it's a partial match, keep accumulating them. |
201 | return 1; | 201 | if (strlen(simpleEmacsKeys[j].key) != l) |
202 | return 0; | ||
203 | else | ||
204 | { | ||
205 | if (simpleEmacsKeys[j].handler) simpleEmacsKeys[j].handler(); | ||
206 | return 1; | ||
207 | } | ||
202 | } | 208 | } |
203 | } | 209 | } |
204 | 210 | ||
205 | // See if it's ordinary keys. | 211 | // See if it's ordinary keys. |
206 | // NOTE - with vi style ordinary keys can be commands, | 212 | // NOTE - with vi style ordinary keys can be commands, |
207 | // but they would be found by the command check above first. | 213 | // but they would be found by the command check above first. |
208 | // So here we just check the first character, and insert it all. | 214 | if (!isTranslated) |
209 | if (isprint(sequence[0])) | ||
210 | { | 215 | { |
211 | if (TT.x < sizeof(toybuf)) | 216 | if (TT.x < sizeof(toybuf)) |
212 | { | 217 | { |
@@ -219,12 +224,10 @@ static int handleKeySequence(long extra, char *sequence) | |||
219 | TT.x += l; | 224 | TT.x += l; |
220 | updateLine(); | 225 | updateLine(); |
221 | } | 226 | } |
222 | return 1; | ||
223 | } | 227 | } |
224 | 228 | ||
225 | // Return 0 if we didn't handle it, handle_keys will just keep on | 229 | // Tell handle_keys to drop it, coz we dealt with it, or it's not one of ours. |
226 | // accumulating sequences and trying again. | 230 | return 1; |
227 | return 0; | ||
228 | } | 231 | } |
229 | 232 | ||
230 | void dumbsh_main(void) | 233 | void dumbsh_main(void) |