aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Smith <osmith@sysmocom.de>2021-07-22 20:24:00 +0200
committerosmith <osmith@sysmocom.de>2021-07-27 12:38:28 +0000
commit053ad966007b3bc50fa03b8e0d947a8ad0eaecca (patch)
tree4a0716efb27850a3351fd7b710f5da55b0429e60
parent466be651768aa14f0677b02851f1f7038cc7f16e (diff)
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
-rw-r--r--src/vty/vty.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/vty/vty.c b/src/vty/vty.c
index 76c6ef55..a39f2680 100644
--- a/src/vty/vty.c
+++ b/src/vty/vty.c
@@ -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;