[PATCH v2] cmdline: update clear screen behavior
Kerem Aksu
kerem.aksu at i2i-systems.com
Fri Jan 16 16:35:13 CET 2026
Control+L should clear screen and redisplay prompt at the top
line. DPDK rdline library will not change anything on the screen when
fed with Control+L. When prompt is lost after too many text written
to the terminal, users will press Control+L to clear screen and put
the prompt to the top line. This is expected behavior in bash(1) or
applications that are using readline(3). Updated to behave as users
expected.
Signed-off-by: Kerem Aksu <kerem.aksu at i2i-systems.com>
---
doc/guides/rel_notes/release_26_03.rst | 1 +
lib/cmdline/cmdline_rdline.c | 29 ++++++++++++++++++++------
lib/cmdline/cmdline_vt100.h | 1 +
3 files changed, 25 insertions(+), 6 deletions(-)
diff --git a/doc/guides/rel_notes/release_26_03.rst b/doc/guides/rel_notes/release_26_03.rst
index 15dabee7a1..7a3df7fc84 100644
--- a/doc/guides/rel_notes/release_26_03.rst
+++ b/doc/guides/rel_notes/release_26_03.rst
@@ -84,6 +84,7 @@ API Changes
Also, make sure to start the actual text at the margin.
=======================================================
+* cmdline: Updated ``rdline`` library to clear screen when fed with Control+L.
ABI Changes
-----------
diff --git a/lib/cmdline/cmdline_rdline.c b/lib/cmdline/cmdline_rdline.c
index 3b8d435e98..ddca4d0a73 100644
--- a/lib/cmdline/cmdline_rdline.c
+++ b/lib/cmdline/cmdline_rdline.c
@@ -182,9 +182,8 @@ display_right_buffer(struct rdline *rdl, int force)
CIRBUF_GET_LEN(&rdl->right));
}
-RTE_EXPORT_SYMBOL(rdline_redisplay)
-void
-rdline_redisplay(struct rdline *rdl)
+static void
+rdline_reprint(struct rdline *rdl, int clear_screen)
{
unsigned int i;
char tmp;
@@ -192,7 +191,12 @@ rdline_redisplay(struct rdline *rdl)
if (!rdl)
return;
- rdline_puts(rdl, vt100_home);
+ if (clear_screen) {
+ rdline_puts(rdl, vt100_clear_screen);
+ rdline_puts(rdl, vt100_homecursor);
+ } else {
+ rdline_puts(rdl, vt100_home);
+ }
for (i=0 ; i<rdl->prompt_size ; i++)
rdl->write_char(rdl, rdl->prompt[i]);
CIRBUF_FOREACH(&rdl->left, i, tmp) {
@@ -201,6 +205,19 @@ rdline_redisplay(struct rdline *rdl)
display_right_buffer(rdl, 1);
}
+RTE_EXPORT_SYMBOL(rdline_redisplay)
+void
+rdline_redisplay(struct rdline *rdl)
+{
+ rdline_reprint(rdl, 0);
+}
+
+static void
+rdline_clear_screen(struct rdline *rdl)
+{
+ rdline_reprint(rdl, 1);
+}
+
RTE_EXPORT_SYMBOL(rdline_char_in)
int
rdline_char_in(struct rdline *rdl, char c)
@@ -382,9 +399,9 @@ rdline_char_in(struct rdline *rdl, char c)
rdline_newline(rdl, rdl->prompt);
break;
- /* redisplay (helps when prompt is lost in other output) */
+ /* clear screen (helps when prompt is lost in other output) */
case CMDLINE_KEY_CTRL_L:
- rdline_redisplay(rdl);
+ rdline_clear_screen(rdl);
break;
/* autocomplete */
diff --git a/lib/cmdline/cmdline_vt100.h b/lib/cmdline/cmdline_vt100.h
index be9ae8e1c9..5f11ebdb74 100644
--- a/lib/cmdline/cmdline_vt100.h
+++ b/lib/cmdline/cmdline_vt100.h
@@ -38,6 +38,7 @@ extern "C" {
#endif
#define vt100_word_left "\033\142"
#define vt100_word_right "\033\146"
+#define vt100_homecursor "\033[H"
/* Result of parsing : it must be synchronized with
* cmdline_vt100_commands[] in vt100.c */
--
2.34.1
--
Yasal Uyarı: *Bu elektronik posta bu linki kullanarak ulaşabileceğiniz
koşullara tabidir:** **https://i2i-systems.com/email-disclaimer/
<http://i2i-systems.com/about-us/email-disclaimer/>*
More information about the dev
mailing list