>From https://landley.net/notes-2022.html#17-10-2022:
the smallest one is "clear" which is actually fraught (the escape does not
reset the TTY out of "cooked" mode,
ncurses clear doesn't seem to effect tty settings (unix2dox because -opost):
$ stty raw && stty | unix2dos
speed 38400 baud; line = 0;
min = 1; time = 0;
-brkint -icrnl -imaxbel
-opost
-isig -icanon
$ clear && stty | unix2dos
speed 38400 baud; line = 0;
-brkint -icrnl -imaxbel
-opost
-isig
$ stty cooked && stty
speed 38400 baud; line = 0;
-imaxbel iutf8
$ clear && stty
speed 38400 baud; line = 0;
-imaxbel
Looking more at ncurses clear, what does it do?
It has a -T option to specify TERM (because env wasn't good enough apparently):
$ clear -T linux | xxd
00000000: 1b5b 481b 5b4a 1b5b 334a .[H.[J.[3J
$ clear -T tmux | xxd
00000000: 1b5b 481b 5b4a 1b5b 334a .[H.[J.[3J
$ clear -T xterm | xxd
00000000: 1b5b 481b 5b32 4a1b 5b33 4a .[H.[2J.[3J
$ clear -T st | xxd
00000000: 1b5b 481b 5b32 4a .[H.[2J
$ clear -T vt100 | xxd
00000000: 1b5b 481b 5b4a 0000 0000 0000 0000 0000 .[H.[J..........
[Large block of zeros]
$ env -i clear
TERM environment variable not set
Trying to find all the terminals clear supported lead me down a rabbit hole
through decompiling the entire terminfo database and sorting through it.
The answer is 159 unique ways, some of them being line mode ttys that clear by
doing '\r\n' and _4_ things for the Apple II (You can set your TERM to
aepro, apple-videx{2,3}, and apple-80 to get them, in case you were interested).
"\ec" is supported by linux ttys, and clears the screen in all terminals I
tested.
And "\e[3J" has been supported by linux since 3.0, and clears the scrollback
buffer in every
terminal I've tested that has one, and is a NOP for terminals without one like
linux tty's or st
- Oliver Webb <[email protected]>
From 6078461243f9863b838af26507fbbaa31ae9dac8 Mon Sep 17 00:00:00 2001
From: Oliver Webb <[email protected]>
Date: Tue, 5 Mar 2024 14:36:45 -0600
Subject: [PATCH] clear.c: Clear scrollback buffer on Non-VTE Terminals by
specifying \e[3J, printf -> xputsn
---
toys/other/clear.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/toys/other/clear.c b/toys/other/clear.c
index 400fe7b3..3b0d9e87 100644
--- a/toys/other/clear.c
+++ b/toys/other/clear.c
@@ -15,5 +15,5 @@ config CLEAR
void clear_main(void)
{
- printf("\e[2J\e[H");
+ xputsn("\ec\e[3J");
}
--
2.44.0
_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net