From e1a50c19eb3734d414cd4f1d13ca57761a4d9e18 Mon Sep 17 00:00:00 2001 From: Leo C Date: Wed, 26 Nov 2014 16:51:41 +0100 Subject: [PATCH] Enable command line editing and history (CONFIG_CMDLINE_EDITING) --- avr/cli_readline.c | 56 +++++++++++++++++++++++++--------------------- include/config.h | 5 ++--- 2 files changed, 33 insertions(+), 28 deletions(-) diff --git a/avr/cli_readline.c b/avr/cli_readline.c index 1dbc73b..1a0aaf2 100644 --- a/avr/cli_readline.c +++ b/avr/cli_readline.c @@ -64,20 +64,26 @@ static char *delete_char (char *buffer, char *p, int *colp, int *np, int plen) * Author: Janghoon Lyu */ -#define putnstr(str, n) printf_P(PSTR("%.*s"), (int)n, str) +static void putnstr(char *str, int n) +{ + /* printf_P(PSTR("%.*s"), (int)n, str) */ + while (n--) + putchar(*str++); +} -#define CTL_CH(c) ((c) - 'a' + 1) + +#define CTL_CH(c) ((c) - 'a' + 1) #define CTL_BACKSPACE ('\b') -#define DEL ((char)255) -#define DEL7 ((char)127) +#define DEL ((char)255) +#define DEL7 ((char)127) #define CREAD_HIST_CHAR ('!') #define getcmd_putch(ch) putchar(ch) #define getcmd_getch() my_getchar(1) #define getcmd_cbeep() getcmd_putch('\a') -#define HIST_MAX 5 -#define HIST_SIZE CONFIG_SYS_CBSIZE +#define HIST_MAX 5 +#define HIST_SIZE CONFIG_SYS_CBSIZE static int hist_max; static int hist_add_idx; @@ -181,28 +187,29 @@ static void cread_print_hist_list(void) } #endif /* CONFIG_CMDLINE_EDITING */ -#define BEGINNING_OF_LINE() { \ - while (num) { \ - getcmd_putch(CTL_BACKSPACE); \ - num--; \ - } \ +#define BEGINNING_OF_LINE() { \ + while (num) { \ + getcmd_putch(CTL_BACKSPACE); \ + num--; \ + } \ } -#define ERASE_TO_EOL() { \ - if (num < eol_num) { \ - printf_P(PSTR("%*S"), (int)(eol_num - num), PSTR("")); \ - do { \ - getcmd_putch(CTL_BACKSPACE); \ - } while (--eol_num > num); \ - } \ +#define ERASE_TO_EOL() { \ + if (num < eol_num) { \ + /* printf_P(PSTR("%*S"), (int)(eol_num - num), PSTR("")); */ \ + print_blanks(eol_num - num); \ + do { \ + getcmd_putch(CTL_BACKSPACE); \ + } while (--eol_num > num); \ + } \ } -#define REFRESH_TO_EOL() { \ - if (num < eol_num) { \ - wlen = eol_num - num; \ - putnstr(buf + num, wlen); \ - num = eol_num; \ - } \ +#define REFRESH_TO_EOL() { \ + if (num < eol_num) { \ + wlen = eol_num - num; \ + putnstr(buf + num, wlen); \ + num = eol_num; \ + } \ } static void cread_add_char(char ichar, int insert, unsigned long *num, @@ -591,4 +598,3 @@ int cli_readline(const FLASH char *const prompt) return cli_readline_into_buffer(prompt, console_buffer); } - diff --git a/include/config.h b/include/config.h index 82dbf81..d192559 100644 --- a/include/config.h +++ b/include/config.h @@ -1,4 +1,4 @@ -#ifndef CONFIG_H +#ifndef CONFIG_H #define CONFIG_H /* Environment variables */ @@ -35,11 +35,10 @@ #define CONFIG_ESC_CHAR ('^'-0x40) +#define CONFIG_CMDLINE_EDITING 1 /* TODO: */ -//#define CONFIG_CMDLINE_EDITING 1 //#define CONFIG_AUTO_COMPLETE 1 #define CONFIG_SYS_LONGHELP 1 #endif /* CONFIG_H */ - -- 2.39.2