diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-02-25 20:46:18 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-02-25 20:46:18 +0000 |
commit | 8e4c33b69f0f9b3939e76c66aec65aa8c43a9b4a (patch) | |
tree | 0615dcb5b01fcc369ca6b1bc8a954b5a50eeccf2 /apps/system/readline | |
parent | 8adf9f884d6add4e42e733e5a966855da0ff8f7c (diff) | |
download | nuttx-8e4c33b69f0f9b3939e76c66aec65aa8c43a9b4a.tar.gz nuttx-8e4c33b69f0f9b3939e76c66aec65aa8c43a9b4a.tar.bz2 nuttx-8e4c33b69f0f9b3939e76c66aec65aa8c43a9b4a.zip |
readline() (and hence NSH) now accept the DEL character as well as the Backspace character for the backspace functionality
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4428 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps/system/readline')
-rw-r--r-- | apps/system/readline/readline.c | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/apps/system/readline/readline.c b/apps/system/readline/readline.c index 4cd29c16f..97bdf6502 100644 --- a/apps/system/readline/readline.c +++ b/apps/system/readline/readline.c @@ -68,6 +68,13 @@ #undef CONFIG_EOL_IS_BOTH_CRLF #define CONFIG_EOL_IS_EITHER_CRLF 1 +/* Some special characters */ + +#define BS 0x08 /* Backspace */ +#define ESC 0x1b /* Escape */ +#define LBRACKET 0x5b /* Left bracket */ +#define DEL 0x7f /* DEL */ + /**************************************************************************** * Private Type Declarations ****************************************************************************/ @@ -219,7 +226,7 @@ ssize_t readline(FAR char *buf, int buflen, FILE *instream, FILE *outstream) { /* Yes, is it an <esc>[, 3 byte sequence */ - if (ch != 0x5b || escape == 2) + if (ch != LBRACKET || escape == 2) { /* We are finished with the escape sequence */ @@ -238,9 +245,16 @@ ssize_t readline(FAR char *buf, int buflen, FILE *instream, FILE *outstream) } } - /* Check for backspace */ + /* Check for backspace + * + * There are several notions of backspace, for an elaborate summary see + * http://www.ibb.net/~anne/keyboard.html. There is no clean solution. + * Here both DEL and backspace are treated like backspace here. The + * Unix/Linux screen terminal by default outputs DEL (0x7f) when the + * backspace key is pressed. + */ - else if (ch == 0x08) + else if (ch == BS || ch == DEL) { /* Eliminate that last character in the buffer. */ @@ -249,9 +263,12 @@ ssize_t readline(FAR char *buf, int buflen, FILE *instream, FILE *outstream) nch--; #ifdef CONFIG_READLINE_ECHO - /* Echo the backspace character on the console */ + /* Echo the backspace character on the console. Always output + * the backspace character because the VT100 terminal doesn't + * understand DEL properly. + */ - readline_consoleputc(ch, outfd); + readline_consoleputc(BS, outfd); readline_consoleputs(g_erasetoeol, outfd); #endif } @@ -259,7 +276,7 @@ ssize_t readline(FAR char *buf, int buflen, FILE *instream, FILE *outstream) /* Check for the beginning of a VT100 escape sequence */ - else if (ch == 0x1b) + else if (ch == ESC) { /* The next character is escaped */ |