Change in libosmocore[master]: vty: clear screen with ^L

osmith gerrit-no-reply at lists.osmocom.org
Thu Jul 22 18:31:49 UTC 2021


osmith has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/25013 )


Change subject: vty: clear screen with ^L
......................................................................

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
---
M src/vty/vty.c
1 file changed, 17 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/13/25013/1

diff --git a/src/vty/vty.c b/src/vty/vty.c
index 76c6ef5..a39f268 100644
--- a/src/vty/vty.c
+++ b/src/vty/vty.c
@@ -459,6 +459,7 @@
 
 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 @@
 	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 @@
 		case CONTROL('K'):
 			vty_kill_line(vty);
 			break;
+		case CONTROL('L'):
+			vty_clear_screen(vty);
+			break;
 		case CONTROL('N'):
 			vty_next_line(vty);
 			break;

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/25013
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ie2356cd92f39b4dc28b5c20bbe4557fb0d972747
Gerrit-Change-Number: 25013
Gerrit-PatchSet: 1
Gerrit-Owner: osmith <osmith at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210722/6129d36a/attachment.htm>


More information about the gerrit-log mailing list