mirror of
https://xff.cz/git/u-boot/
synced 2025-09-03 17:52:07 +02:00
cli: Allow history to be disabled
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>
This commit is contained in:
@@ -361,32 +361,33 @@ int cread_line_process_ch(struct cli_line_state *cls, char ichar)
|
|||||||
break;
|
break;
|
||||||
case CTL_CH('p'):
|
case CTL_CH('p'):
|
||||||
case CTL_CH('n'):
|
case CTL_CH('n'):
|
||||||
{
|
if (cls->history) {
|
||||||
char *hline;
|
char *hline;
|
||||||
|
|
||||||
if (ichar == CTL_CH('p'))
|
if (ichar == CTL_CH('p'))
|
||||||
hline = hist_prev();
|
hline = hist_prev();
|
||||||
else
|
else
|
||||||
hline = hist_next();
|
hline = hist_next();
|
||||||
|
|
||||||
if (!hline) {
|
if (!hline) {
|
||||||
getcmd_cbeep();
|
getcmd_cbeep();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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);
|
||||||
|
cls->eol_num = strlen(buf);
|
||||||
|
REFRESH_TO_EOL();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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);
|
|
||||||
cls->eol_num = strlen(buf);
|
|
||||||
REFRESH_TO_EOL();
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case '\t':
|
case '\t':
|
||||||
if (IS_ENABLED(CONFIG_AUTO_COMPLETE)) {
|
if (IS_ENABLED(CONFIG_AUTO_COMPLETE)) {
|
||||||
int num2, col;
|
int num2, col;
|
||||||
@@ -438,6 +439,7 @@ static int cread_line(const char *const prompt, char *buf, unsigned int *len,
|
|||||||
cls->len = *len;
|
cls->len = *len;
|
||||||
cls->prompt = prompt;
|
cls->prompt = prompt;
|
||||||
cls->buf = buf;
|
cls->buf = buf;
|
||||||
|
cls->history = 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,
|
||||||
|
@@ -31,6 +31,7 @@ struct cli_ch_state {
|
|||||||
* @num: Current cursor position, where 0 is the start
|
* @num: Current cursor position, where 0 is the start
|
||||||
* @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
|
||||||
* @buf: Buffer containing line
|
* @buf: Buffer containing line
|
||||||
* @prompt: Prompt for the line
|
* @prompt: Prompt for the line
|
||||||
*/
|
*/
|
||||||
@@ -39,6 +40,7 @@ struct cli_line_state {
|
|||||||
uint eol_num;
|
uint eol_num;
|
||||||
uint len;
|
uint len;
|
||||||
bool insert;
|
bool insert;
|
||||||
|
bool history;
|
||||||
char *buf;
|
char *buf;
|
||||||
const char *prompt;
|
const char *prompt;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user