bug fix:: Never reach readline_prompt() in nsh_initialize, moved it up to the top. Works now.
enhancement: TAB completion now works like Unix, it will autocomplete as much as possible for multiple matches.
This commit is contained in:
parent
09add96e22
commit
211f8bf76d
@ -101,6 +101,18 @@ static const struct extmatch_vtable_s g_nsh_extmatch =
|
||||
|
||||
void nsh_initialize(void)
|
||||
{
|
||||
#if defined(CONFIG_NSH_READLINE) && defined(CONFIG_READLINE_TABCOMPLETION)
|
||||
/* Configure the NSH prompt */
|
||||
|
||||
(void)readline_prompt(g_nshprompt);
|
||||
|
||||
#ifdef CONFIG_READLINE_HAVE_EXTMATCH
|
||||
/* Set up for tab completion on NSH commands */
|
||||
|
||||
(void)readline_extmatch(&g_nsh_extmatch);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Mount the /etc filesystem */
|
||||
|
||||
(void)nsh_romfsetc();
|
||||
@ -114,16 +126,4 @@ void nsh_initialize(void)
|
||||
/* Bring up the network */
|
||||
|
||||
(void)nsh_netinit();
|
||||
|
||||
#if defined(CONFIG_NSH_READLINE) && defined(CONFIG_READLINE_TABCOMPLETION)
|
||||
/* Configure the NSH prompt */
|
||||
|
||||
(void)readline_prompt(g_nshprompt);
|
||||
|
||||
#ifdef CONFIG_READLINE_HAVE_EXTMATCH
|
||||
/* Set up for tab completion on NSH commands */
|
||||
|
||||
(void)readline_extmatch(&g_nsh_extmatch);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
@ -147,6 +147,8 @@ static void tab_completion(FAR struct rl_common_s *vtbl, char *buf,
|
||||
int len = *nch;
|
||||
int i;
|
||||
int j;
|
||||
int name_len;
|
||||
char tmp_name[CONFIG_TASK_NAME_SIZE+1];
|
||||
|
||||
if (len >= 1)
|
||||
{
|
||||
@ -177,8 +179,6 @@ static void tab_completion(FAR struct rl_common_s *vtbl, char *buf,
|
||||
|
||||
if (nr_matches == 1)
|
||||
{
|
||||
int name_len;
|
||||
|
||||
/* Yes... that that is the one we want. Was it a match with a
|
||||
* builtin command? Or with an external command.
|
||||
*/
|
||||
@ -229,18 +229,40 @@ static void tab_completion(FAR struct rl_common_s *vtbl, char *buf,
|
||||
{
|
||||
RL_PUTC(vtbl, '\n');
|
||||
|
||||
/* See how many characters we can auto complete for the user
|
||||
* For example, if we have the following commands:
|
||||
* - prog1
|
||||
* - prog2
|
||||
* - prog3
|
||||
* then it should automatically complete up to prog.
|
||||
* We do this in one pass using a temp */
|
||||
|
||||
memset(tmp_name, 0, sizeof(tmp_name));
|
||||
#ifdef CONFIG_READLINE_HAVE_EXTMATCH
|
||||
/* Show the possible external completions */
|
||||
|
||||
for (i = 0; i < nr_ext_matches; i++)
|
||||
{
|
||||
name = g_extmatch_vtbl->getname(ext_matches[i]);
|
||||
/* initialize temp */
|
||||
|
||||
if (tmp_name[0] == '\0')
|
||||
{
|
||||
strcpy(tmp_name, name);
|
||||
}
|
||||
|
||||
RL_PUTC(vtbl, ' ');
|
||||
RL_PUTC(vtbl, ' ');
|
||||
|
||||
for (j = 0; j < strlen(name); j++)
|
||||
{
|
||||
/* removing characters that aren't common to all the
|
||||
* matches */
|
||||
|
||||
if (name[j] != tmp_name[j])
|
||||
{
|
||||
tmp_name[j] = '\0';
|
||||
}
|
||||
RL_PUTC(vtbl, name[j]);
|
||||
}
|
||||
|
||||
@ -254,18 +276,34 @@ static void tab_completion(FAR struct rl_common_s *vtbl, char *buf,
|
||||
for (i = 0; i < nr_builtin_matches; i++)
|
||||
{
|
||||
name = builtin_getname(builtin_matches[i]);
|
||||
/* initialize temp */
|
||||
|
||||
if (tmp_name[0] == '\0')
|
||||
{
|
||||
strcpy(tmp_name, name);
|
||||
}
|
||||
|
||||
RL_PUTC(vtbl, ' ');
|
||||
RL_PUTC(vtbl, ' ');
|
||||
|
||||
for (j = 0; j < strlen(name); j++)
|
||||
{
|
||||
/* removing characters that aren't common to all the
|
||||
* matches */
|
||||
|
||||
if (name[j] != tmp_name[j])
|
||||
{
|
||||
tmp_name[j] = '\0';
|
||||
}
|
||||
RL_PUTC(vtbl, name[j]);
|
||||
}
|
||||
|
||||
RL_PUTC(vtbl, '\n');
|
||||
}
|
||||
#endif
|
||||
strcpy(buf, tmp_name);
|
||||
|
||||
name_len = strlen(tmp_name);
|
||||
|
||||
/* Output the original prompt */
|
||||
|
||||
@ -277,10 +315,17 @@ static void tab_completion(FAR struct rl_common_s *vtbl, char *buf,
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
for (i = 0; i < name_len; i++)
|
||||
{
|
||||
RL_PUTC(vtbl, buf[i]);
|
||||
}
|
||||
|
||||
/* Don't remove extra characters after the completed word, if any. */
|
||||
|
||||
if (len < name_len)
|
||||
{
|
||||
*nch = name_len;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user