• Just Discovered Alt Screens

    From Michael Sanders@porkchop@invalid.foo to comp.unix.shell on Sat Nov 1 23:53:12 2025
    From Newsgroup: comp.unix.shell

    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

    alt_screen() {

    printf '\033[?1049h' # switch to alternate screen
    "$@" # run the command passed
    printf '\033[?1049l' # return to normal screen
    }

    ls /

    alt_screen top

    # eof
    --
    :wq
    Mike Sanders
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From gazelle@gazelle@shell.xmission.com (Kenny McCormack) to comp.unix.shell on Sun Nov 2 00:12:53 2025
    From Newsgroup: comp.unix.shell

    In article <10e66h8$1md5g$1@dont-email.me>,
    Michael Sanders <porkchop@invalid.foo> wrote:
    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

    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?
    --
    Res ipsa loquitur.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@ldo@nz.invalid to comp.unix.shell on Sun Nov 2 01:44:47 2025
    From Newsgroup: comp.unix.shell

    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>.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Janis Papanagnou@janis_papanagnou+ng@hotmail.com to comp.unix.shell on Sun Nov 2 07:06:55 2025
    From Newsgroup: comp.unix.shell

    On 02.11.2025 00:53, Michael Sanders wrote:
    Wow did not know this...
    alt screens are very handy.
    I wish every OS had this.

    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

    [...]

    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

    [...]

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From gazelle@gazelle@shell.xmission.com (Kenny McCormack) to comp.unix.shell on Sun Nov 2 08:33:16 2025
    From Newsgroup: comp.unix.shell

    In article <10e6se0$1s19n$1@dont-email.me>,
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
    ...
    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.

    Correct. I just tested in an lxterminal and they do not stack, as OP
    claimed they do. Note that when I composed my previous post in this
    thread, I did not bother to test before posting.

    In a way, it'd be cool if they did, but I can see how that could:

    1) Be hard to manage (from both the user and system POV).
    and
    2) Eat up memory in the terminal emulator's space.

    P.S. (pedantic point for OP). This is not a function of "the OS", but
    rather of the terminal emulator in use.
    --
    I'll give him credit for one thing: He is (& will be) the most quotable President
    ever. Books have been written about (GW) Bushisms, but Dubya's got nothing on Trump.

    Tremendously wet - from the standpoint of water.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Michael Sanders@porkchop@invalid.foo to comp.unix.shell on Sun Nov 2 12:08:38 2025
    From Newsgroup: comp.unix.shell

    On Sun, 2 Nov 2025 00:12:53 -0000 (UTC), Kenny McCormack wrote:


    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?

    Thank for the additional info Kenny. It 'looks' we only get a single
    alt screen. I think that my top, as shown in the script I posted, may
    be using alt screen itself giving me the impression of multiple alt
    screens - still I'll be using alt screen in my work when it seems
    like a good choice.
    --
    :wq
    Mike Sanders
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Michael Sanders@porkchop@invalid.foo to comp.unix.shell on Sun Nov 2 12:11:31 2025
    From Newsgroup: comp.unix.shell

    On Sun, 2 Nov 2025 01:44:47 -0000 (UTC), Lawrence DrCOOliveiro wrote:

    On Sat, 1 Nov 2025 23:53:12 -0000 (UTC), Michael Sanders wrote:

    Wow did not know this...

    Neither did I!

    Pretty nifty yeah?

    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.

    Me thinks you're right. Read my response to Kenny to see what
    I thought was happening...

    Also, in my investigation, I found this: <https://docs.kde.org/stable5/en/konsole/konsole/semantic-shell-
    integration.html>.

    That's interesting, thank you Lawrence. Love to learn this stuff.
    --
    :wq
    Mike Sanders
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Michael Sanders@porkchop@invalid.foo to comp.unix.shell on Sun Nov 2 12:17:55 2025
    From Newsgroup: comp.unix.shell

    On Sun, 2 Nov 2025 07:06:55 +0100, Janis Papanagnou wrote:

    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. ;-)

    Good thinking - 'keep it clean'.

    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

    No stacking, single instance only (in my excitement I misread what was happening). My top in the example script uses alt screen as well as my
    function calling top in that manner too. Nevertheless, the function I
    posted is small enough to drop right in a script & use without much fuss.

    I really do like the concept even if it is limited to one toggle between
    the two screens.
    --
    :wq
    Mike Sanders
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Michael Sanders@porkchop@invalid.foo to comp.unix.shell on Sun Nov 2 12:24:24 2025
    From Newsgroup: comp.unix.shell

    On Sun, 2 Nov 2025 08:33:16 -0000 (UTC), Kenny McCormack wrote:

    P.S. (pedantic point for OP). This is not a function of "the OS", but rather of the terminal emulator in use.

    Noted. It all hinges on whether or not the ANSI escapes are supported
    by the terminal in use. Current version of Windows terminal (I tested)
    support it too (url will wrap):

    <https://superuser.com/questions/1863323/does-windows-terminal-not-have- alternate-screen#:~:text=1%20Answer,switch%20back%20to%20regular%20mode.)
    --
    :wq
    Mike Sanders
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Kaz Kylheku@643-408-1753@kylheku.com to comp.unix.shell on Sun Nov 2 20:12:31 2025
    From Newsgroup: comp.unix.shell

    On 2025-11-01, Michael Sanders <porkchop@invalid.foo> wrote:
    Wow did not know this...

    You never noticed that editors restore the prior content
    of your terminal when they quit, and wondered how that works?

    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.

    Or, well, of course terminal emulation being built into kernel consoles
    counts as it literally being in the OS. But that is made to look as if
    it were an externally attached terminal.
    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Michael Sanders@porkchop@invalid.foo to comp.unix.shell on Sun Nov 2 21:28:54 2025
    From Newsgroup: comp.unix.shell

    On Sun, 2 Nov 2025 20:12:31 -0000 (UTC), Kaz Kylheku wrote:

    Of course, you think that wrapping bc in a shell script is like the
    invention of electricity.

    Kaz I hope we can be friends - but you wont talk to me like that.
    --
    :wq
    Mike Sanders
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Christian Weisgerber@naddy@mips.inka.de to comp.unix.shell on Sun Nov 2 23:22:02 2025
    From Newsgroup: comp.unix.shell

    On 2025-11-02, Kaz Kylheku <643-408-1753@kylheku.com> wrote:

    alt screens are very handy.
    I wish every OS had this.

    /No/ OS has it, it's in the terminal.

    The OS part is where it is in the operating system's termcap/terminfo
    database. And there's the rub. On FreeBSD, for instance, the ti/te capabilities with the alt screen switches are missing from the xterm
    termcap entry because some people had VERY STRONG OPINIONS that
    they dislike this feature and that it must be disabled.

    less(1) also has an -X switch that disables sending ti/te.
    --
    Christian "naddy" Weisgerber naddy@mips.inka.de
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@ldo@nz.invalid to comp.unix.shell on Mon Nov 3 01:55:30 2025
    From Newsgroup: comp.unix.shell

    On Sun, 2 Nov 2025 23:22:02 -0000 (UTC), Christian Weisgerber wrote:

    less(1) also has an -X switch that disables sending ti/te.

    Which I am very pleased about.

    export PAGER='less -iX -x4'
    alias more="$PAGER"

    (The rCL-x4rCY is for very old program source files of mine, dating back to when I used tabs for indentation instead of spaces.)
    --- Synchronet 3.21a-Linux NewsLink 1.2