aboutsummaryrefslogtreecommitdiff
path: root/linenoise.c
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2010-11-10 12:02:00 +1000
committerSteve Bennett <steveb@workware.net.au>2010-11-17 07:57:39 +1000
commit0c8cc0722c0a5eb13ea39aa6ef5c7a80ff16a1bd (patch)
treef6e748dd55f5f450ee8bea82a5132a9f99b1790e /linenoise.c
parentb93609dd51bb92f9a7d466159f4128a6f5e59cc1 (diff)
downloadjimtcl-0c8cc0722c0a5eb13ea39aa6ef5c7a80ff16a1bd.zip
jimtcl-0c8cc0722c0a5eb13ea39aa6ef5c7a80ff16a1bd.tar.gz
jimtcl-0c8cc0722c0a5eb13ea39aa6ef5c7a80ff16a1bd.tar.bz2
Linenoise improvement for ^D
Use default readline/bash behaviour of deleting char to the right, unless the line is empty. Then it is EOF. Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'linenoise.c')
-rw-r--r--linenoise.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/linenoise.c b/linenoise.c
index a2c0255..2c83960 100644
--- a/linenoise.c
+++ b/linenoise.c
@@ -521,14 +521,23 @@ static int linenoisePrompt(const char *prompt, struct current *current) {
process_char:
if (c == -1) return current->len;
switch(c) {
- case ctrl('D'): /* ctrl-d */
case '\r': /* enter */
history_len--;
free(history[history_len]);
- if (current->len == 0 && c == ctrl('D')) {
+ return current->len;
+
+ case ctrl('D'): /* ctrl-d */
+ if (current->len == 0) {
+ /* Empty line, so EOF */
+ history_len--;
+ free(history[history_len]);
return -1;
}
- return current->len;
+ /* Otherwise delete char to right of cursor */
+ if (remove_char(current, current->pos)) {
+ refreshLine(prompt, current);
+ }
+ break;
case ctrl('C'): /* ctrl-c */
errno = EAGAIN;
@@ -594,7 +603,7 @@ process_char:
}
skipsame = 1;
}
- else if (c == CTRL('N') || c == SPECIAL_DOWN) {
+ else if (c == ctrl('N') || c == SPECIAL_DOWN) {
/* Search for the next (later) match */
if (searchpos < history_len) {
searchpos++;