Alan D. Salewski via plug on 28 Jun 2024 19:20:41 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Smooth Scrolling Terminals


On 2024-06-23 17:21:07, Casey Bralla via plug <plug@lists.phillylinux.org> spake thus:
Back in ancient times, Fred Flintstone and I used DEC VT-100 terminals. 
These terminals had gorgeous smooth scrolling where the text floated
upward instead of jerking line by line.

I assume somebody has written a smooth-scrolling terminal emulator, but
I haven't been able to find one easily.  The docs for xterm mention
smooth mode, but don't explain how to set it.

Here's a clunky way to enable/disable it in xterm. There's probably
a better way, but I couldn't find the knob:

    $ # enable smooth (slow) scrolling
    $ echo -n -e '\x1b\x5b\x3f\x34\x68'

    $ # enable jump (fast) scrolling
    $ echo -n -e '\x1b\x5b\x3f\x34\x6c'

Note that those byte sequences are identical except for the last
byte. The relevant bits from ascii(7) are:

    Oct   Dec   Hex   Char
    ──────────────────────────────
    033   27    1B    ESC (escape)
    064   52    34    4
    077   63    3F    ?
    133   91    5B    [
    150   104   68    h
    154   108   6C    l

Thomas Dickey (maintainer of xterm) has a document[0] of the control
sequences supported by xterm at:

    https://invisible-island.net/xterm/ctlseqs/ctlseqs.pdf

The relevant control sequences are on page 13 (enable smooth
scrolling) and page 16 (enable jump scrolling):

    CSI ? Pm h    DEC Private Mode Set (DECSET)
        ...
        Ps = 4    →    Smooth (Slow) Scroll (DECSCLM), VT100.
        ...

    CSI ? Pm l    DEC Private Mode Reset (DECRST).
        ...
        Ps = 4    →    Jump (Fast) Scroll (DECSCLM), VT100.
        ...

where:
    'CSI' is the "Control Sequence Introducer", which is the 2-byte
     sequence:  ESC [
    (written above in Bash hex notation as \x1b \x5b)

    '?' is the literal question mark char (\x3f)

    'Pm' means "one or more semicolon-separated Ps values"

    'Ps' means "A single numeric parameter, composed of one or more digits"

    'h' is the literal letter 'aitch (\x68)
and
    'l' is the literal letter ell (\x6c)

The 'echo' commands could have also been written with some literal
characters:

    $ # enable smooth (slow) scrolling
    $ echo -n -e '\e[?4h'

    $ # enable jump (fast) scrolling
    $ echo -n -e '\e[?4l'

but for the purpose of the explanation I think using the hex codes
makes it more clear what is going on (does not look like magic
syntax).

So to get smooth scrolling by default, I suppose you could add
something like the following to your shell startup script:

    case $- in
        *i*) if   test -t 1; then echo -n -e '\e[?4h';
             elif test -t 2; then echo -n -e '\e[?4h' 1>&2;
             fi
             ;;
    esac

As I'm sure you're expecting, the smooth scrolling is /a lot/ slower
than the jump scrolling.

Smooth/Slow:

    $ time for nn in {1..10}; do ls -al; done
    ...

    real    0m7.461s
    user    0m0.034s
    sys     0m0.066s


Jump/Fast:

    $ time for nn in {1..10}; do ls -al; done
    ...

    real    0m0.281s
    user    0m0.030s
    sys     0m0.050s

HTH,
-Al


[0] "XTerm Control Sequences"


    by Edward Moy, University of California, Berkeley

    Revised by Stephen Gildea, X Consortium (1994)

    Updated by Thomas Dickey, XFree86 Project (1996-2006)
                              invisible-island.net (2006-2024)
                              updated for XTerm Patch #392 (2024/05/22)

--
a l a n   d.   s a l e w s k i
ads@salewski.email
salewski@att.net
https://github.com/salewski
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug