From: Leo C Date: Fri, 22 Apr 2016 09:21:03 +0000 (+0200) Subject: Store only command line input in history buffer, but not data (i.e mm command) X-Git-Tag: hexrel-6.6~1 X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/commitdiff_plain/8ed660166ce9cdeb63b4cf710c663407b7ec9128 Store only command line input in history buffer, but not data (i.e mm command) --- diff --git a/avr/cli.c b/avr/cli.c index 8763ed1..aa2c388 100644 --- a/avr/cli.c +++ b/avr/cli.c @@ -8,9 +8,10 @@ * (C) Copyright 2005 * JinHua Luo, GuangDong Linux Center, * - * SPDX-License-Identifier: GPL-2.0+ + * SPDX-License-Identifier: GPL-2.0 */ +#include "cli.h" #include "common.h" #include @@ -25,7 +26,6 @@ #include "env.h" #include "cli_readline.h" #include "con-utils.h" -#include "cli.h" /* FIXME: Quoting problems */ @@ -364,7 +364,7 @@ void cli_loop(void) int rc = 1; for (;;) { - len = cli_readline(PSTR(CONFIG_SYS_PROMPT)); + len = cli_readline(PSTR(CONFIG_SYS_PROMPT), 1); flag = 0; /* assume no special flags for now */ if (len > 0) { diff --git a/avr/cli_readline.c b/avr/cli_readline.c index 5545015..e4c3f5a 100644 --- a/avr/cli_readline.c +++ b/avr/cli_readline.c @@ -11,6 +11,7 @@ * SPDX-License-Identifier: GPL-2.0 */ +#include "cli_readline.h" #include "common.h" #include #include @@ -22,7 +23,6 @@ #include "con-utils.h" #include "print-utils.h" #include "command.h" -#include "cli_readline.h" @@ -357,7 +357,8 @@ static void cread_add_str(char *str, int strsize, bool insert, } } -static int cread_line(const FLASH char *const prompt, char *buf, uint_fast8_t *len) +static int cread_line(const FLASH char *const prompt, char *buf, + uint_fast8_t *len, bool enable_history) { uint_fast8_t num = 0; uint_fast8_t eol_num = 0; @@ -455,32 +456,33 @@ static int cread_line(const FLASH char *const prompt, char *buf, uint_fast8_t *l case CTL_CH('p'): /* previous-history */ case KEY_DOWN: case CTL_CH('n'): /* next-history */ - { - char *hline; - - if (ichar == CTL_CH('p') || ichar == KEY_UP) - hline = hist_prev(); - else - hline = hist_next(); - - if (!hline) { + if (enable_history) { + char *hline; + + if (ichar == CTL_CH('p') || ichar == KEY_UP) + hline = hist_prev(); + else + hline = hist_next(); + + if (hline) { + /* nuke the current line */ + /* first, go home */ + BEGINNING_OF_LINE(); + + /* erase to end of line */ + ERASE_TO_EOL(); + + /* copy new line into place and display */ + strcpy(buf, hline); + eol_num = strlen(buf); + REFRESH_TO_EOL(); + } else { + getcmd_cbeep(); + } + } else { getcmd_cbeep(); - continue; } - - /* nuke the current line */ - /* first, go home */ - BEGINNING_OF_LINE(); - - /* erase to end of line */ - ERASE_TO_EOL(); - - /* copy new line into place and display */ - strcpy(buf, hline); - eol_num = strlen(buf); - REFRESH_TO_EOL(); - continue; - } + break; #ifdef CONFIG_AUTO_COMPLETE case '\t': { int num2, col; @@ -512,16 +514,18 @@ static int cread_line(const FLASH char *const prompt, char *buf, uint_fast8_t *l *len = eol_num; buf[eol_num] = '\0'; /* lose the newline */ - if (buf[0] /* && buf[0] != CREAD_HIST_CHAR */) - cread_add_to_hist(buf); - hist_cur = hist_add_idx; - + if (enable_history) { + if (buf[0]) + cread_add_to_hist(buf); + hist_cur = hist_add_idx; + } return 0; } /****************************************************************************/ -static int cli_readline_into_buffer(const FLASH char *const prompt, char *buffer) +static int cli_readline_into_buffer(const FLASH char *const prompt, + char *buffer, bool enable_history) { char *p = buffer; uint_fast8_t len = CONFIG_SYS_CBSIZE; @@ -530,11 +534,11 @@ static int cli_readline_into_buffer(const FLASH char *const prompt, char *buffer if (prompt) my_puts_P(prompt); - rc = cread_line(prompt, p, &len); + rc = cread_line(prompt, p, &len, enable_history); return rc < 0 ? rc : (int) len; } -int cli_readline(const FLASH char *const prompt) +int cli_readline(const FLASH char *const prompt, bool enable_history) { /* * If console_buffer isn't 0-length the user will be prompted to modify @@ -542,5 +546,5 @@ int cli_readline(const FLASH char *const prompt) */ console_buffer[0] = '\0'; - return cli_readline_into_buffer(prompt, console_buffer); + return cli_readline_into_buffer(prompt, console_buffer, enable_history); } diff --git a/avr/cmd_boot.c b/avr/cmd_boot.c index ce280ac..f3bce9d 100644 --- a/avr/cmd_boot.c +++ b/avr/cmd_boot.c @@ -241,7 +241,7 @@ command_ret_t do_console(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv case ':': putchar('\n'); - int cmdlen = cli_readline(PSTR(": ")); + int cmdlen = cli_readline(PSTR(": "), 1); if (cmdlen > 0) run_command(console_buffer, 0); break; diff --git a/avr/cmd_mem.c b/avr/cmd_mem.c index effa416..a725c61 100644 --- a/avr/cmd_mem.c +++ b/avr/cmd_mem.c @@ -4,7 +4,7 @@ * (C) Copyright 2000 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * - * SPDX-License-Identifier: GPL-2.0+ + * SPDX-License-Identifier: GPL-2.0 */ /* @@ -151,7 +151,7 @@ mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[]) z80_bus_cmd(Release); printf_P(PSTR("%05lx: %02x"), addr, data); - nbytes = cli_readline(PSTR(" ? ")); + nbytes = cli_readline(PSTR(" ? "), 0); if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) { /* pressed as only input, don't modify current * location and move to next. "-" pressed will go back. diff --git a/avr/debug.c b/avr/debug.c index e29a085..384a5ad 100644 --- a/avr/debug.c +++ b/avr/debug.c @@ -1,9 +1,10 @@ /* * (C) Copyright 2014 Leo C. * - * SPDX-License-Identifier: GPL-2.0+ + * SPDX-License-Identifier: GPL-2.0 */ +#include "debug.h" #include "common.h" #include #include @@ -13,7 +14,6 @@ #include "command.h" #include "cli_readline.h" #include "print-utils.h" -#include "debug.h" /* * Debugging @@ -170,7 +170,7 @@ mod_mem_avr(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const arg data = *addr; printf_P(PSTR("%04x: %02x"), addr, data); - nbytes = cli_readline(PSTR(" ? ")); + nbytes = cli_readline(PSTR(" ? "), 0); if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) { /* pressed as only input, don't modify current * location and move to next. "-" pressed will go back. diff --git a/include/cli.h b/include/cli.h index 4920cc4..20e852f 100644 --- a/include/cli.h +++ b/include/cli.h @@ -4,7 +4,7 @@ * (C) Copyright 2014 Google, Inc * Simon Glass * - * SPDX-License-Identifier: GPL-2.0+ + * SPDX-License-Identifier: GPL-2.0 */ #ifndef CLI_H diff --git a/include/cli_readline.h b/include/cli_readline.h index 4471568..0e165cc 100644 --- a/include/cli_readline.h +++ b/include/cli_readline.h @@ -4,12 +4,15 @@ * (C) Copyright 2014 Google, Inc * Simon Glass * - * SPDX-License-Identifier: GPL-2.0+ + * SPDX-License-Identifier: GPL-2.0 */ #ifndef CLI_READLINE_H #define CLI_READLINE_H +#include "common.h" +#include + extern char console_buffer[]; /* console I/O buffer */ /** @@ -18,9 +21,10 @@ extern char console_buffer[]; /* console I/O buffer */ * This is a convenience function which calls cli_readline_into_buffer(). * * @prompt: Prompt to display + * @enable_history: Use history buffer if true * @return command line length excluding terminator, or -ve on error */ -int cli_readline(const FLASH char *const prompt); +int cli_readline(const FLASH char *const prompt, bool enable_history); /** * readline_into_buffer() - read a line into a buffer @@ -44,7 +48,8 @@ int cli_readline(const FLASH char *const prompt); * parameter), then -2 is returned. If a break is detected (Ctrl-C) then * -1 is returned. */ -//int cli_readline_into_buffer(const char *const prompt, char *buffer, int timeout); +//int cli_readline_into_buffer(const char *const prompt, char *buffer, +// int timeout, bool enable_history); #endif /* CLI_READLINE_H */ diff --git a/include/config.h b/include/config.h index 1501989..efc793e 100644 --- a/include/config.h +++ b/include/config.h @@ -1,7 +1,7 @@ /* * (C) Copyright 2014 Leo C. * - * SPDX-License-Identifier: GPL-2.0+ + * SPDX-License-Identifier: GPL-2.0 */ #ifndef CONFIG_H diff --git a/include/debug.h b/include/debug.h index 39c15b0..0ee0129 100644 --- a/include/debug.h +++ b/include/debug.h @@ -4,7 +4,7 @@ * (C) Copyright 2000-2009 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * - * SPDX-License-Identifier: GPL-2.0+ + * SPDX-License-Identifier: GPL-2.0 */