summaryrefslogtreecommitdiffstats
path: root/vlib
diff options
context:
space:
mode:
authorChris Luke <chrisy@flirble.org>2016-04-29 08:53:46 -0400
committerDave Barach <openvpp@barachs.net>2016-04-29 22:37:08 +0000
commit6de2ff28fef27421f6b9a6c1f4ef53d1bd8c7c6e (patch)
tree6c388fdabf4aaf744aedc0164de8682e4d558732 /vlib
parent7ef6d5bb681c60a4f7cde2f5c8fb6283907d39bc (diff)
VPP-26 Iterate through empty command line in cli history
When cursoring through the command history in the CLI, when you reach the end of the history (ie, back at "where you started") most CLI's typically show a blank line. This is a visual cue that you are back where you started. Change-Id: I5733dbd0dcdc6deac6a0a856cfadbdb987456ec0 Signed-off-by: Chris Luke <chrisy@flirble.org>
Diffstat (limited to 'vlib')
-rw-r--r--vlib/vlib/unix/cli.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/vlib/vlib/unix/cli.c b/vlib/vlib/unix/cli.c
index 7fb20560d77..0aa7f23cbc3 100644
--- a/vlib/vlib/unix/cli.c
+++ b/vlib/vlib/unix/cli.c
@@ -1048,18 +1048,32 @@ static int unix_cli_line_process_one(unix_cli_main_t * cm,
cf->excursion += delta;
- if (cf->excursion > (i32) vec_len (cf->command_history) -1)
- cf->excursion = 0;
+ if (cf->excursion == vec_len (cf->command_history))
+ {
+ /* down-arrowed to last entry - want a blank line */
+ _vec_len (cf->current_command) = 0;
+ }
else if (cf->excursion < 0)
- cf->excursion = vec_len (cf->command_history) -1;
+ {
+ /* up-arrowed over the start to the end, want a blank line */
+ cf->excursion = vec_len (cf->command_history);
+ _vec_len (cf->current_command) = 0;
+ }
+ else
+ {
+ if (cf->excursion > (i32) vec_len (cf->command_history) -1)
+ /* down-arrowed past end - wrap to start */
+ cf->excursion = 0;
- prev = cf->command_history [cf->excursion];
- vec_validate (cf->current_command, vec_len(prev)-1);
+ /* Print the command at the current position */
+ prev = cf->command_history [cf->excursion];
+ vec_validate (cf->current_command, vec_len(prev)-1);
- clib_memcpy (cf->current_command, prev, vec_len(prev));
- _vec_len (cf->current_command) = vec_len(prev);
- unix_vlib_cli_output_cooked (cf, uf, cf->current_command,
- vec_len (cf->current_command));
+ clib_memcpy (cf->current_command, prev, vec_len(prev));
+ _vec_len (cf->current_command) = vec_len(prev);
+ unix_vlib_cli_output_cooked (cf, uf, cf->current_command,
+ vec_len (cf->current_command));
+ }
cf->cursor = vec_len(cf->current_command);
break;
@@ -1422,10 +1436,10 @@ static int unix_cli_line_process_one(unix_cli_main_t * cm,
}
else
vec_reset_length (cf->current_command);
+ cf->excursion = vec_len (cf->command_history);
}
else /* history disabled */
vec_reset_length (cf->current_command);
- cf->excursion = 0;
cf->search_mode = 0;
vec_reset_length (cf->search_key);
cf->cursor = 0;