shell: tab feature optimization
Add options to Kconfig that deactivate the Tab button and autocompletion feature. Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
This commit is contained in:
parent
572d2b02a2
commit
de7e208d8d
2 changed files with 34 additions and 2 deletions
|
@ -65,6 +65,22 @@ config SHELL_ARGC_MAX
|
|||
help
|
||||
Maximum number of arguments that can build a command.
|
||||
|
||||
config SHELL_TAB
|
||||
bool "Enable the Tab button supporort in shell"
|
||||
default y
|
||||
help
|
||||
Enable using the Tab button in the shell. The button
|
||||
can be used for prompting commands, or for autocompletion.
|
||||
This feature has high impact on flash usage.
|
||||
|
||||
config SHELL_TAB_AUTOCOMPLETION
|
||||
bool "Enable commands autocompletion with the Tab button"
|
||||
depends on SHELL_TAB
|
||||
default y
|
||||
help
|
||||
Enable commands and subcommands autocompletion with the Tab
|
||||
key. This function can be deactivated to save some flash.
|
||||
|
||||
config SHELL_WILDCARD
|
||||
bool "Enable wildcard support in shell"
|
||||
select FNMATCH
|
||||
|
|
|
@ -313,11 +313,12 @@ static void find_completion_candidates(const struct shell *shell,
|
|||
size_t *first_idx, size_t *cnt,
|
||||
uint16_t *longest)
|
||||
{
|
||||
size_t incompl_cmd_len = shell_strlen(incompl_cmd);
|
||||
const struct shell_static_entry *candidate;
|
||||
struct shell_static_entry dloc;
|
||||
size_t incompl_cmd_len;
|
||||
size_t idx = 0;
|
||||
|
||||
incompl_cmd_len = shell_strlen(incompl_cmd);
|
||||
*longest = 0U;
|
||||
*cnt = 0;
|
||||
|
||||
|
@ -353,6 +354,16 @@ static void autocomplete(const struct shell *shell,
|
|||
__ASSERT_NO_MSG(match != NULL);
|
||||
cmd_len = shell_strlen(match->syntax);
|
||||
|
||||
if (!IS_ENABLED(CONFIG_SHELL_TAB_AUTOCOMPLETION)) {
|
||||
/* Add a space if the Tab button is pressed when command is
|
||||
* complete.
|
||||
*/
|
||||
if (cmd_len == arg_len) {
|
||||
shell_op_char_insert(shell, ' ');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* no exact match found */
|
||||
if (cmd_len != arg_len) {
|
||||
shell_op_completion_insert(shell,
|
||||
|
@ -478,6 +489,10 @@ static void partial_autocomplete(const struct shell *shell,
|
|||
uint16_t common = common_beginning_find(shell, cmd, &completion, first,
|
||||
cnt, arg_len);
|
||||
|
||||
if (!IS_ENABLED(CONFIG_SHELL_TAB_AUTOCOMPLETION)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (common) {
|
||||
shell_op_completion_insert(shell, &completion[arg_len],
|
||||
common - arg_len);
|
||||
|
@ -951,7 +966,8 @@ static void state_collect(const struct shell *shell)
|
|||
break;
|
||||
|
||||
case '\t': /* TAB */
|
||||
if (flag_echo_get(shell)) {
|
||||
if (flag_echo_get(shell) &&
|
||||
IS_ENABLED(CONFIG_SHELL_TAB)) {
|
||||
/* If the Tab key is pressed, "history
|
||||
* mode" must be terminated because
|
||||
* tab and history handlers are sharing
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue