aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/dumbsh.c
diff options
context:
space:
mode:
authorDavid Walter Seikel2014-02-01 15:00:00 +1000
committerDavid Walter Seikel2014-02-01 15:00:00 +1000
commitf26667d117af5a119471eb531f3ded65b9c1fbc8 (patch)
tree992b67a657a159371b88ba48537126370312efa3 /dumbsh.c
parentSmarten up the CSI parser a little. (diff)
downloadboxes-f26667d117af5a119471eb531f3ded65b9c1fbc8.zip
boxes-f26667d117af5a119471eb531f3ded65b9c1fbc8.tar.gz
boxes-f26667d117af5a119471eb531f3ded65b9c1fbc8.tar.bz2
boxes-f26667d117af5a119471eb531f3ded65b9c1fbc8.tar.xz
Better method to tell if it's ordinary characters, and deal with partial reads better.
Diffstat (limited to 'dumbsh.c')
-rw-r--r--dumbsh.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/dumbsh.c b/dumbsh.c
index 875614b..5f2c63e 100644
--- a/dumbsh.c
+++ b/dumbsh.c
@@ -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.
191static int handleKeySequence(long extra, char *sequence) 191static 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
230void dumbsh_main(void) 233void dumbsh_main(void)