summaryrefslogtreecommitdiff
path: root/lib/command.c
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2016-10-06 01:15:48 +0000
committerQuentin Young <qlyoung@cumulusnetworks.com>2016-10-06 01:15:48 +0000
commit6011c1b213fa8e08126e33852403845a39881072 (patch)
tree8b1b986ceb17685c58d9b9a0cdb001c5ca768e05 /lib/command.c
parent03ca8d3dffb45aa1f20bc06802ca227a6b4e36cf (diff)
lib: Make <cr> appear first in completions
When a command is complete and <cr> appears in tab- or ?-completions, make sure it appears first Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/command.c')
-rw-r--r--lib/command.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/command.c b/lib/command.c
index 6368ebffe1..f51b2c69ee 100644
--- a/lib/command.c
+++ b/lib/command.c
@@ -498,7 +498,10 @@ compare_completions (const void *fst, const void *snd)
/**
* Takes a list of completions returned by command_complete,
* dedeuplicates them based on both text and description,
- * and returns them as a vector.
+ * sorts them, and returns them as a vector.
+ *
+ * @param completions linked list of cmd_token
+ * @return deduplicated and sorted vector with
*/
static vector
completions_to_vec (struct list *completions)
@@ -506,10 +509,13 @@ completions_to_vec (struct list *completions)
vector comps = vector_init (VECTOR_MIN_SIZE);
struct listnode *ln;
- struct cmd_token *token;
+ struct cmd_token *token, *cr = NULL;
unsigned int i, exists;
for (ALL_LIST_ELEMENTS_RO(completions,ln,token))
{
+ if (token->type == END_TKN && (cr = token))
+ continue;
+
// linear search for token in completions vector
exists = 0;
for (i = 0; i < vector_active (comps) && !exists; i++)
@@ -529,6 +535,13 @@ completions_to_vec (struct list *completions)
sizeof (void *),
&compare_completions);
+ if (cr)
+ {
+ vector_set_index (comps, vector_active (comps), NULL);
+ memmove (comps->index + 1, comps->index, (comps->alloced - 1) * sizeof (void *));
+ vector_set_index (comps, 0, copy_cmd_token (cr));
+ }
+
return comps;
}
/**