[PATCH 12/36] cli: Allow command completion to be disabled

Simon Glass sjg at chromium.org
Tue Sep 19 20:08:42 CEST 2023


When inputting text outside the command line we don't want to use tab
for command completion. Add an option to control this.

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

 common/cli_readline.c | 3 ++-
 include/cli.h         | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/common/cli_readline.c b/common/cli_readline.c
index fa8f525d3a4..23913a857a9 100644
--- a/common/cli_readline.c
+++ b/common/cli_readline.c
@@ -389,7 +389,7 @@ int cread_line_process_ch(struct cli_line_state *cls, char ichar)
 		}
 		break;
 	case '\t':
-		if (IS_ENABLED(CONFIG_AUTO_COMPLETE)) {
+		if (IS_ENABLED(CONFIG_AUTO_COMPLETE) && cls->cmd_complete) {
 			int num2, col;
 
 			/* do not autocomplete when in the middle */
@@ -440,6 +440,7 @@ static int cread_line(const char *const prompt, char *buf, unsigned int *len,
 	cls->prompt = prompt;
 	cls->buf = buf;
 	cls->history = true;
+	cls->cmd_complete = true;
 
 	if (init_len)
 		cread_add_str(buf, init_len, 1, &cls->num, &cls->eol_num, buf,
diff --git a/include/cli.h b/include/cli.h
index 252bdb70ab0..ad3cb4499fe 100644
--- a/include/cli.h
+++ b/include/cli.h
@@ -32,6 +32,7 @@ struct cli_ch_state {
  * @eol_num: Number of characters in the buffer
  * @insert: true if in 'insert' mode
  * @history: true if history should be accessible
+ * @cmd_complete: true if tab completion should be enabled
  * @buf: Buffer containing line
  * @prompt: Prompt for the line
  */
@@ -41,6 +42,7 @@ struct cli_line_state {
 	uint len;
 	bool insert;
 	bool history;
+	bool cmd_complete;
 	char *buf;
 	const char *prompt;
 };
-- 
2.42.0.459.ge4e396fd5e-goog



More information about the U-Boot mailing list