Wow did not know this...
alt screens are very handy.
I wish every OS had this.
#!/bin/sh
<<'NOTES'
printf '\033[?1049h' # alt screen 1
printf '\033[?1049h' # alt screen 2
printf '\033[?1049l' # back to alt screen 1
printf '\033[?1049l' # back to normal screen
- each h pushes a new screen
- each l pops back one level
NOTES
Wow did not know this...
alt screens are very handy.
I wish every OS had this.
- each h pushes a new screen - each l pops back one level
Wow did not know this...
alt screens are very handy.
I wish every OS had this.
[...]
printf '\033[?1049h' # alt screen 1
printf '\033[?1049h' # alt screen 2
printf '\033[?1049l' # back to alt screen 1
printf '\033[?1049l' # back to normal screen
- each h pushes a new screen
- each l pops back one level
[...]
What I hadn't yet tried was to _nest_ (as you've depict in your
example below) these alternative screens. It's indeed useful to
not have it restricted to just one alternative screen. - But in
my interactive Linux terminals (including 'xterm') that isn't
supported; the 'h' versions creates a new and then another new
empty screen, but the 'l' version switches back to the original
screen - so it does not stack.
I'd be interested to hear from others whether they observe a
"stacking" or just an "alternate" effect in their environments.
Interesting. I've been using this feature for a long time - basically,
as you illustrate, to run a command that generates a lot of (basically useless) output on an alternate screen, then switch back to the main
screen after it finishes. Two comments:
1) You can use "tput smcup" and "tput rmcup" to avoid hardcoding the
escape sequences. This is what I do.
2) Observer that the output of "tput [sr]mcup" (*) includes some
extra stuff,
the function of which I do not know:
$ tput smcup|od -bc 0000000 033 133 077 061 060 064 071 150 033 133 062
062 073 060 073 060
033 [ ? 1 0 4 9 h 033 [ 2 2 ; 0 ; 0 0000020 164
t
0000021 $ tput rmcup|od -bc 0000000 033 133 077 061 060 064 071 154 033
133 062 063 073 060 073 060
033 [ ? 1 0 4 9 l 033 [ 2 3 ; 0 ; 0 0000020 164
t
0000021
(*) On one of the systems I tested, but not all of them.
Also, I did not know that you can have more than one (**) alternate
screen.
I always assumed it was just one. Learn something new every day!
(**) It looks like you can have as many as you want; is that right?
On Sat, 1 Nov 2025 23:53:12 -0000 (UTC), Michael Sanders wrote:
Wow did not know this...
Neither did I!
alt screens are very handy.
I wish every OS had this.
Seems to have originated in xterm, and been copied by other terminal emulators <https://invisible-island.net/xterm/ctlseqs/ctlseqs.html> <https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797>.
- each h pushes a new screen - each l pops back one level
I think you only get one level.
Also, in my investigation, I found this: <https://docs.kde.org/stable5/en/konsole/konsole/semantic-shell-integration.html>.
Actually quite some standard tools seem to use that. Obviously (in my
Linux environment) the 'less' pager, the 'watch' command,
or the 'vim' editor. It's indeed very useful to not litter the screen
and have an application use an own screen to work with.
While I've supported that feature, e.g. in my "ansi.a68" module,
I've not yet used it in practice, though. - I certainly try to not
litter the screen in the first place. ;-)
What I hadn't yet tried was to _nest_ (as you've depict in your example below) these alternative screens. It's indeed useful to not have it restricted to just one alternative screen. - But in my interactive Linux terminals (including 'xterm') that isn't supported; the 'h' versions
creates a new and then another new empty screen, but the 'l' version
switches back to the original screen - so it does not stack.
I'd be interested to hear from others whether they observe a "stacking"
or just an "alternate" effect in their environments.
Janis
P.S. (pedantic point for OP). This is not a function of "the OS", but rather of the terminal emulator in use.
Wow did not know this...
alt screens are very handy.
I wish every OS had this.
Of course, you think that wrapping bc in a shell script is like the
invention of electricity.
alt screens are very handy.
I wish every OS had this.
/No/ OS has it, it's in the terminal.
less(1) also has an -X switch that disables sending ti/te.
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 54 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 17:34:44 |
| Calls: | 742 |
| Files: | 1,218 |
| D/L today: |
4 files (8,203K bytes) |
| Messages: | 184,412 |
| Posted today: | 1 |