cli: Allow command completion to be disabled

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@chromium.org>
This commit is contained in:
Simon Glass
2023-10-01 19:13:16 -06:00
committed by Tom Rini
parent 8fc041fe4c
commit 3b487bf511
2 changed files with 4 additions and 1 deletions

View File

@@ -389,7 +389,7 @@ int cread_line_process_ch(struct cli_line_state *cls, char ichar)
} }
break; break;
case '\t': case '\t':
if (IS_ENABLED(CONFIG_AUTO_COMPLETE)) { if (IS_ENABLED(CONFIG_AUTO_COMPLETE) && cls->cmd_complete) {
int num2, col; int num2, col;
/* do not autocomplete when in the middle */ /* 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->prompt = prompt;
cls->buf = buf; cls->buf = buf;
cls->history = true; cls->history = true;
cls->cmd_complete = true;
if (init_len) if (init_len)
cread_add_str(buf, init_len, 1, &cls->num, &cls->eol_num, buf, cread_add_str(buf, init_len, 1, &cls->num, &cls->eol_num, buf,

View File

@@ -32,6 +32,7 @@ struct cli_ch_state {
* @eol_num: Number of characters in the buffer * @eol_num: Number of characters in the buffer
* @insert: true if in 'insert' mode * @insert: true if in 'insert' mode
* @history: true if history should be accessible * @history: true if history should be accessible
* @cmd_complete: true if tab completion should be enabled
* @buf: Buffer containing line * @buf: Buffer containing line
* @prompt: Prompt for the line * @prompt: Prompt for the line
*/ */
@@ -41,6 +42,7 @@ struct cli_line_state {
uint len; uint len;
bool insert; bool insert;
bool history; bool history;
bool cmd_complete;
char *buf; char *buf;
const char *prompt; const char *prompt;
}; };