diff options
author | David Walter Seikel | 2014-01-31 14:42:27 +1000 |
---|---|---|
committer | David Walter Seikel | 2014-01-31 14:42:27 +1000 |
commit | 27f03dbabe7678ada059bc6dd2b06b8de4b09e52 (patch) | |
tree | 9c6a4a42dd318658127608971ec1996cb57b3b8f | |
parent | Another null terminated array removal. (diff) | |
download | boxes-27f03dbabe7678ada059bc6dd2b06b8de4b09e52.zip boxes-27f03dbabe7678ada059bc6dd2b06b8de4b09e52.tar.gz boxes-27f03dbabe7678ada059bc6dd2b06b8de4b09e52.tar.bz2 boxes-27f03dbabe7678ada059bc6dd2b06b8de4b09e52.tar.xz |
Add more comments.
Diffstat (limited to '')
-rw-r--r-- | dumbsh.c | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -35,6 +35,7 @@ GLOBALS( | |||
35 | 35 | ||
36 | #define TT this.dumbsh | 36 | #define TT this.dumbsh |
37 | 37 | ||
38 | // Sanity check cursor location and update the current line. | ||
38 | static void updateLine() | 39 | static void updateLine() |
39 | { | 40 | { |
40 | if (0 > TT.x) TT.x = 0; | 41 | if (0 > TT.x) TT.x = 0; |
@@ -70,6 +71,10 @@ static void handleCSI(long extra, char *command, int *params, int count) | |||
70 | updateLine(); | 71 | updateLine(); |
71 | } | 72 | } |
72 | } | 73 | } |
74 | // NOTE - The CSI differs from the sequence callback | ||
75 | // in not having to return anything. CSI sequences include a | ||
76 | // definite terminating byte, so no need for this callback | ||
77 | // to tell handle_keys to keep accumulating. | ||
73 | } | 78 | } |
74 | 79 | ||
75 | // The various commands. | 80 | // The various commands. |
@@ -93,6 +98,14 @@ static void backSpaceChar() | |||
93 | 98 | ||
94 | // This is where we would actually deal with what ever command the user had typed in. | 99 | // This is where we would actually deal with what ever command the user had typed in. |
95 | // For now we just move on. | 100 | // For now we just move on. |
101 | // For now we just move on to the next line. | ||
102 | // TODO - We would want to redirect I/O, capture some keys (^C), | ||
103 | // but pass the rest on. | ||
104 | // Dunno yet how to deal with that. | ||
105 | // We still want handle_keys to be doing it's thing, | ||
106 | // so maybe handing it another fd, and a callback. | ||
107 | // A function to add and remove fd and callback pairs for | ||
108 | // handle_keys to check? | ||
96 | static void doCommand() | 109 | static void doCommand() |
97 | { | 110 | { |
98 | toybuf[0] = 0; | 111 | toybuf[0] = 0; |
@@ -171,6 +184,7 @@ static struct keyCommand simpleEmacsKeys[] = | |||
171 | {"^P", prevHistory} | 184 | {"^P", prevHistory} |
172 | }; | 185 | }; |
173 | 186 | ||
187 | // Callback for incoming key sequences from the user. | ||
174 | static int handleKeySequence(long extra, char *sequence) | 188 | static int handleKeySequence(long extra, char *sequence) |
175 | { | 189 | { |
176 | int j; | 190 | int j; |
@@ -186,6 +200,9 @@ static int handleKeySequence(long extra, char *sequence) | |||
186 | } | 200 | } |
187 | 201 | ||
188 | // See if it's ordinary keys. | 202 | // See if it's ordinary keys. |
203 | // NOTE - with vi style ordinary keys can be commands, | ||
204 | // but they would be found by the command check above first. | ||
205 | // So here we just check the first character, and insert it all. | ||
189 | if (isprint(sequence[0])) | 206 | if (isprint(sequence[0])) |
190 | { | 207 | { |
191 | if (TT.x < sizeof(toybuf)) | 208 | if (TT.x < sizeof(toybuf)) |
@@ -202,6 +219,8 @@ static int handleKeySequence(long extra, char *sequence) | |||
202 | return 1; | 219 | return 1; |
203 | } | 220 | } |
204 | 221 | ||
222 | // Return 0 if we didn't handle it, handle_keys will just keep on | ||
223 | // accumulating sequences and trying again. | ||
205 | return 0; | 224 | return 0; |
206 | } | 225 | } |
207 | 226 | ||
@@ -245,9 +264,11 @@ void dumbsh_main(void) | |||
245 | TT.h = 24; | 264 | TT.h = 24; |
246 | terminal_size(&TT.w, &TT.h); | 265 | terminal_size(&TT.w, &TT.h); |
247 | 266 | ||
267 | // Let's rock! | ||
248 | updateLine(); | 268 | updateLine(); |
249 | handle_keys(0, handleKeySequence, handleCSI); | 269 | handle_keys(0, handleKeySequence, handleCSI); |
250 | 270 | ||
271 | // Clean up. | ||
251 | tcsetattr(0, TCSANOW, &oldTermIo); | 272 | tcsetattr(0, TCSANOW, &oldTermIo); |
252 | puts(""); | 273 | puts(""); |
253 | fflush(stdout); | 274 | fflush(stdout); |