Simple embedded shell with runtime pluggable commands.
Implements a simple unix-like shell for embedded systems with a pluggable command architecture.
Revision 10:c3faa7ffd23b, committed 2018-12-13
- Comitter:
- shimniok
- Date:
- Thu Dec 13 08:56:58 2018 +0000
- Parent:
- 7:b58450c94d32
- Child:
- 11:23f61057d877
- Commit message:
- Fixed recognition of esc sequence keys (home, end, etc.)
Changed in this revision
SimpleShell.cpp | Show annotated file Show diff for this revision Revisions of this file |
SimpleShell.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/SimpleShell.cpp Wed Dec 12 17:58:27 2018 +0000 +++ b/SimpleShell.cpp Thu Dec 13 08:56:58 2018 +0000 @@ -1,6 +1,8 @@ #include "SimpleShell.h" #include <ctype.h> +#define ESC 0x1b + SimpleShell::SimpleShell() { lookupEnd = 0; @@ -85,18 +87,72 @@ c = fgetc(stdin); if (c == '\r') { // if return is hit, we're done, don't add \r to cmd done = true; + } else if (c == ESC) { // keyboard escape codes (arrow keys, etc) + char c2 = getchar(); + char c3 = getchar(); + + if (c2 == 0x4f && c3 == 0x46) { + printf("<END>"); + } else if (c2 == 0x5b) { + switch (c3) { + case 0x41 : // up + printf("<UP>"); + break; + case 0x42 : // down + printf("<DOWN>"); + break; + case 0x43 : // right + printf("<RIGHT>"); + break; + case 0x44 : // left + printf("<LEFT>"); + break; + case 0x31 : // home + case 0x32 : // ins + case 0x33: // del + case 0x35: // pgup + case 0x36: // pgdn + char c4 = getchar(); + if (c4 == 0x7e) { + switch (c3) { + case 0x31 : + printf("<HOME>"); + break; + case 0x32 : // ins + printf("<INS>"); + break; + case 0x33: // del + printf("<DEL>"); + break; + case 0x35: // pgup + printf("<PGUP>"); + break; + case 0x36: // pgdn + printf("<PGDN>"); + break; + default: + break; + }//switch + }//if + default: + //printf("<0x%02x>", c3); + break; + }//switch + }//if + //printf("\n"); } else if (i < MAXBUF-1) { if (c == 0x7f || c == '\b') { // backspace or delete if (i > 0) { // if we're at the beginning, do nothing i--; fputs("\b \b", stdout); - } } else { - fputc(c, stdout); + if (isprint(c)) + fputc(c, stdout); cmd[i++] = c; } } + } while (!done); fputc('\n', stdout);
--- a/SimpleShell.h Wed Dec 12 17:58:27 2018 +0000 +++ b/SimpleShell.h Thu Dec 13 08:56:58 2018 +0000 @@ -77,6 +77,10 @@ /// Current working directory char _cwd[MAXBUF]; + + /// shell command history + + }; // class #endif \ No newline at end of file