I just want to clear the screen sounds like such a simple thing. Why is it difficult? Because there are so many types of screens! Are we talking about a terminal emulator program, like xterm, rxvt, telnet? Are we talking about a physical terminal on a serial line (vt220)? Is it a line printer???? Is it a Tk text widget?
Here are a few ways:
exec clear >@ stdout ; # Most unix systems should have a clear command puts [exec clear] ; # The puts forces the connection to stdout? puts \x1B\[2J ; # for Solaris xterm - VERY terminal specific eval exec [auto_execok cls] ; # Most windows systems should have a cls exec command /c cls ; # DOS? exec >&@stdout $::env(COMSPEC) /c cls ; # Win95 $t delete 1.0 end ;# Tk text widget
In clear screen from within Tcl , comp.lang.tcl, 2005-04-13, Bruce Hartweg suggests:
eval exec >&@stdout <@stdin [auto_execok cls]
Ro: Pretty neat tricks ;)
Angel Sosa:
In addition the following examples clears the whole screen (on which platforms and for what kinds of machines?)
puts \x1b\[H\x1b\[2J
This initializes and clears the screen on a unix system with some sort of terminfo/termcap/curses library installation: :
exec tput clear >@ stdout
drh - 2024-08-02 17:44:11
I discovered on 2024-08-02, that command prompts on my Win11 laptop understand VT100 control codes. (Unix shell windows have done this seemingly forever, but as far as I can tell, the capability is relatively new to Windows.)
That means that you can clearscreen on all modern platforms using just:
puts "\033\[2J"