mirror of https://gerrit.osmocom.org/libosmocore
vty: clear screen with ^L
Use ANSI escape characters to clear the screen with ^L, like it works in typical Linux shells. I always found it slightly inconvenient that this didn't work in the VTY. Change-Id: Ie2356cd92f39b4dc28b5c20bbe4557fb0d972747
This commit is contained in:
parent
466be65176
commit
053ad96600
|
@ -459,6 +459,7 @@ static int vty_command(struct vty *vty)
|
|||
|
||||
static const char telnet_backward_char = 0x08;
|
||||
static const char telnet_space_char = ' ';
|
||||
static const char telnet_escape_char = 0x1B;
|
||||
|
||||
/* Basic function to write buffer to vty. */
|
||||
static void vty_write(struct vty *vty, const char *buf, size_t nbytes)
|
||||
|
@ -858,6 +859,19 @@ static void vty_down_level(struct vty *vty)
|
|||
vty->cp = 0;
|
||||
}
|
||||
|
||||
/* When '^L' is typed, clear all lines above the current one. */
|
||||
static void vty_clear_screen(struct vty *vty)
|
||||
{
|
||||
vty_out(vty, "%c%s%c%s",
|
||||
telnet_escape_char,
|
||||
"[2J", /* Erase Screen */
|
||||
telnet_escape_char,
|
||||
"[H" /* Cursor Home */
|
||||
);
|
||||
vty_prompt(vty);
|
||||
vty_redraw_line(vty);
|
||||
}
|
||||
|
||||
/* When '^Z' is received from vty, move down to the enable mode. */
|
||||
static void vty_end_config(struct vty *vty)
|
||||
{
|
||||
|
@ -1402,6 +1416,9 @@ int vty_read(struct vty *vty)
|
|||
case CONTROL('K'):
|
||||
vty_kill_line(vty);
|
||||
break;
|
||||
case CONTROL('L'):
|
||||
vty_clear_screen(vty);
|
||||
break;
|
||||
case CONTROL('N'):
|
||||
vty_next_line(vty);
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue