diff options
-rw-r--r-- | btctl.c | 4 | ||||
-rw-r--r-- | rl_helper.c | 12 | ||||
-rw-r--r-- | rl_helper.h | 4 |
3 files changed, 14 insertions, 6 deletions
@@ -1200,8 +1200,8 @@ int main (int argc, char * argv[]) { c == 'Y' ? true : false, 0); } change_prompt_state(NORMAL_PSTATE); - } else - rl_feed(c); + } else if (!rl_feed(c)) + break; /* user pressed ctrl-d */ } /* Disable adapter on exit */ diff --git a/rl_helper.c b/rl_helper.c index f34639d..b066600 100644 --- a/rl_helper.c +++ b/rl_helper.c @@ -21,7 +21,9 @@ #include <ctype.h> #include <stdarg.h> +#include <stdbool.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <termios.h> #include "rl_helper.h" @@ -37,6 +39,7 @@ }) typedef enum { + K_EOT = 0x04, /* end-of-transmission (ctrl-d) */ K_TAB = 0x09, K_ESC = 0x1b, K_BACKSPACE = 0x7f, @@ -196,12 +199,15 @@ int rl_parse_seq(int *c) { } } -void rl_feed(int c) { +bool rl_feed(int c) { if (rl_parse_seq(&c)) - return; + return true; switch (c) { + case K_EOT: + putchar('\n'); + return false; case K_TAB: if (tab_completer_cb) { const char *str = tab_completer_cb(lnbuf, pos); @@ -272,6 +278,8 @@ void rl_feed(int c) { printf(" %x ", c); break; } + + return true; } void rl_printf(const char *fmt, ...) { diff --git a/rl_helper.h b/rl_helper.h index 756a79a..beeed8c 100644 --- a/rl_helper.h +++ b/rl_helper.h @@ -13,8 +13,8 @@ void rl_set_prompt(const char *str); void rl_set_tab_completer(tab_completer_callback cb); /* close resources */ void rl_quit(); -/* add char to line buffer */ -void rl_feed(int c); +/* add char to line buffer, returns false on ctrl-d */ +bool rl_feed(int c); /* printf version */ void rl_printf(const char *fmt, ...); |