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:
Jakub Rzeszutko 2020-11-18 14:24:57 +01:00 committed by Maureen Helm
commit de7e208d8d
2 changed files with 34 additions and 2 deletions

View file

@ -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