[PATCH v3 25/32] Add a new Kconfig for command-line history

Simon Glass sjg at chromium.org
Tue Oct 17 00:28:16 CEST 2023


At present EXPO requires CMDLINE since it uses cli_readline, which
needs history enabled. It should be possible to enter lines of text
into an expo without having history available.

Fix this dependency by creating a new Kconfig for cmdline history.
Adjust the code to use the correct condiition.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

Changes in v3:
- Add new patch with a Kconfig for command-line entry

 cmd/Kconfig        | 15 +++++++++++++--
 common/cli_cread.c | 24 ++++++++++++++----------
 include/cli.h      |  3 ++-
 3 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 5cb45f9c025e..491737ca8ba7 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -29,8 +29,19 @@ config CMDLINE_EDITING
 	depends on CMDLINE
 	default y
 	help
-	  Enable editing and History functions for interactive command line
-	  input operations
+	  Enable an editing function for interactive, command-line-input
+	  operations. This allows moving the cursor back and forth within
+	  the line, inserting and deleting characters, etc.
+
+config CMDLINE_HISTORY
+	bool "Enable command-line history"
+	depends on CMDLINE_EDITING
+	default y
+	help
+	  Enable a history function for interactive, command-line-input
+	  operations. This maintains a small buffer of previously entered
+	  commands, allowing the user to enter or edit old commands without
+	  having to retype them.
 
 config CMDLINE_PS_SUPPORT
 	bool "Enable support for changing the command prompt string at run-time"
diff --git a/common/cli_cread.c b/common/cli_cread.c
index 19af27303cfc..33c678e89f3d 100644
--- a/common/cli_cread.c
+++ b/common/cli_cread.c
@@ -28,11 +28,12 @@ DECLARE_GLOBAL_DATA_PTR;
 #define CTL_BACKSPACE		('\b')
 #define DEL			((char)255)
 #define DEL7			((char)127)
-#define CREAD_HIST_CHAR		('!')
 
 #define getcmd_putch(ch)	putc(ch)
 #define getcmd_cbeep()		getcmd_putch('\a')
 
+#define CREAD_HIST_CHAR		('!')
+
 #ifdef CONFIG_SPL_BUILD
 #define HIST_MAX		3
 #define HIST_SIZE		32
@@ -41,14 +42,6 @@ DECLARE_GLOBAL_DATA_PTR;
 #define HIST_SIZE		CONFIG_SYS_CBSIZE
 #endif
 
-static int hist_max;
-static int hist_add_idx;
-static int hist_cur = -1;
-static uint hist_num;
-
-static char *hist_list[HIST_MAX];
-static char hist_lines[HIST_MAX][HIST_SIZE + 1];	/* Save room for NULL */
-
 static void getcmd_putchars(int count, int ch)
 {
 	int i;
@@ -57,6 +50,16 @@ static void getcmd_putchars(int count, int ch)
 		getcmd_putch(ch);
 }
 
+#ifdef CONFIG_CMDLINE_HISTORY
+
+static int hist_max;
+static int hist_add_idx;
+static int hist_cur = -1;
+static uint hist_num;
+
+static char *hist_list[HIST_MAX];
+static char hist_lines[HIST_MAX][HIST_SIZE + 1];	/* Save room for NULL */
+
 void hist_init(void)
 {
 	int i;
@@ -150,6 +153,7 @@ void cread_print_hist_list(void)
 		i++;
 	}
 }
+#endif /* CMDLINE_HISTORY */
 
 #define BEGINNING_OF_LINE() {			\
 	while (cls->num) {			\
@@ -325,7 +329,7 @@ int cread_line_process_ch(struct cli_line_state *cls, char ichar)
 		break;
 	case CTL_CH('p'):
 	case CTL_CH('n'):
-		if (cls->history) {
+		if (IS_ENABLED(CONFIG_CMDLINE_HISTORY) && cls->history) {
 			char *hline;
 
 			if (ichar == CTL_CH('p'))
diff --git a/include/cli.h b/include/cli.h
index bca24c8c565f..45a338f709f7 100644
--- a/include/cli.h
+++ b/include/cli.h
@@ -294,6 +294,7 @@ char *hist_prev(void);
  */
 char *hist_next(void);
 
+#ifdef CONFIG_CMDLINE_HISTORY
 /**
  * cread_add_to_hist() - Add a line to the history buffer
  *
@@ -304,10 +305,10 @@ char *hist_next(void);
  */
 void cread_add_to_hist(char *line);
 
-#ifdef CONFIG_CMDLINE_EDITING
 void hist_init(void);
 #else
 static inline void hist_init(void) {}
+static inline void cread_add_to_hist(char *line) {}
 #endif
 
 #endif
-- 
2.42.0.655.g421f12c284-goog



More information about the U-Boot mailing list