]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
cli: Allow history to be disabled
authorSimon Glass <sjg@chromium.org>
Mon, 2 Oct 2023 01:13:15 +0000 (19:13 -0600)
committerTom Rini <trini@konsulko.com>
Wed, 11 Oct 2023 19:43:54 +0000 (15:43 -0400)
When inputting text outside the command line we don't want history to be
accessible. Add an option to control this.

Signed-off-by: Simon Glass <sjg@chromium.org>
common/cli_readline.c
include/cli.h

index fdb84d9204f648752e5147e8c65303b2050e0827..fa8f525d3a41769fc60f42a2e2ef982d0d177525 100644 (file)
@@ -361,32 +361,33 @@ int cread_line_process_ch(struct cli_line_state *cls, char ichar)
                break;
        case CTL_CH('p'):
        case CTL_CH('n'):
-       {
-               char *hline;
+               if (cls->history) {
+                       char *hline;
 
-               if (ichar == CTL_CH('p'))
-                       hline = hist_prev();
-               else
-                       hline = hist_next();
+                       if (ichar == CTL_CH('p'))
+                               hline = hist_prev();
+                       else
+                               hline = hist_next();
 
-               if (!hline) {
-                       getcmd_cbeep();
-                       break;
-               }
+                       if (!hline) {
+                               getcmd_cbeep();
+                               break;
+                       }
 
-               /* nuke the current line */
-               /* first, go home */
-               BEGINNING_OF_LINE();
+                       /* nuke the current line */
+                       /* first, go home */
+                       BEGINNING_OF_LINE();
 
-               /* erase to end of line */
-               ERASE_TO_EOL();
+                       /* erase to end of line */
+                       ERASE_TO_EOL();
 
-               /* copy new line into place and display */
-               strcpy(buf, hline);
-               cls->eol_num = strlen(buf);
-               REFRESH_TO_EOL();
+                       /* copy new line into place and display */
+                       strcpy(buf, hline);
+                       cls->eol_num = strlen(buf);
+                       REFRESH_TO_EOL();
+                       break;
+               }
                break;
-       }
        case '\t':
                if (IS_ENABLED(CONFIG_AUTO_COMPLETE)) {
                        int num2, col;
@@ -438,6 +439,7 @@ static int cread_line(const char *const prompt, char *buf, unsigned int *len,
        cls->len = *len;
        cls->prompt = prompt;
        cls->buf = buf;
+       cls->history = true;
 
        if (init_len)
                cread_add_str(buf, init_len, 1, &cls->num, &cls->eol_num, buf,
index bbc5327643554a8aa3d60e188ad4e70f0b4c8081..252bdb70ab0da0bfb5326cf5a135b1f7db3d7613 100644 (file)
@@ -31,6 +31,7 @@ struct cli_ch_state {
  * @num: Current cursor position, where 0 is the start
  * @eol_num: Number of characters in the buffer
  * @insert: true if in 'insert' mode
+ * @history: true if history should be accessible
  * @buf: Buffer containing line
  * @prompt: Prompt for the line
  */
@@ -39,6 +40,7 @@ struct cli_line_state {
        uint eol_num;
        uint len;
        bool insert;
+       bool history;
        char *buf;
        const char *prompt;
 };