• pause() then continue on mouse click or key press

    From Michael Sanders@porkchop@invalid.foo to comp.unix.shell on Fri Oct 24 00:11:51 2025
    From Newsgroup: comp.unix.shell

    #!/bin/sh

    <<'NOTES'

    pauses your script then continues on either a single key press
    or mouse click, works here with an xterm compatible terminal

    Michael Sanders 2025

    NOTES

    pause() {
    msg=${1:-"Press any key or click..."} # default message
    printf '%s' "$msg"
    old=$(stty -g)
    printf '\033[?1000h'
    stty raw -echo
    dd bs=1 count=1 < /dev/tty 2>/dev/null
    printf '\033[?1000l'
    stty "$old"
    }

    pause "Your script has finished"

    # eof
    --
    Mike Sanders
    :wq
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Janis Papanagnou@janis_papanagnou+ng@hotmail.com to comp.unix.shell on Fri Oct 24 03:03:11 2025
    From Newsgroup: comp.unix.shell

    On 24.10.2025 02:11, Michael Sanders wrote:
    #!/bin/sh

    <<'NOTES'

    pauses your script then continues on either a single key press
    or mouse click, works here with an xterm compatible terminal

    Michael Sanders 2025

    NOTES

    pause() {
    msg=${1:-"Press any key or click..."} # default message
    printf '%s' "$msg"
    old=$(stty -g)
    printf '\033[?1000h'
    stty raw -echo
    dd bs=1 count=1 < /dev/tty 2>/dev/null
    printf '\033[?1000l'
    stty "$old"
    }

    pause "Your script has finished"

    # eof


    What are all these ANSI terminal control commands doing?


    Bash users may prefer terser and clearer solutions, like

    pause() {
    msg=${1:-"Press any key or click..."}
    read -n1 -s -p "$msg"
    echo
    }

    (Personally I'm using Ksh with its own variant of that.)

    Janis

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Kaz Kylheku@643-408-1753@kylheku.com to comp.unix.shell on Fri Oct 24 01:31:14 2025
    From Newsgroup: comp.unix.shell

    On 2025-10-24, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
    On 24.10.2025 02:11, Michael Sanders wrote:
    #!/bin/sh

    <<'NOTES'

    pauses your script then continues on either a single key press
    or mouse click, works here with an xterm compatible terminal

    Michael Sanders 2025

    NOTES

    pause() {
    msg=${1:-"Press any key or click..."} # default message
    printf '%s' "$msg"
    old=$(stty -g)
    printf '\033[?1000h'
    stty raw -echo
    dd bs=1 count=1 < /dev/tty 2>/dev/null
    printf '\033[?1000l'
    stty "$old"
    }

    pause "Your script has finished"

    # eof


    What are all these ANSI terminal control commands doing?

    1000h enables mouse events being reported; 1000l disables it.

    I've messed with these in the past in an attempt to disable "paste
    bracketing" being turned on, when I didn't want that.

    ( "paste bracketing" is when you use the mouse to paste some
    text into the terminal, and it is preceded by a certain prologue
    sequence and terminated by an epilogue. Applications can detect
    that and then use that to distinguish pasted text from typed.

    For instance you know how in Vim you have to sometimes use
    :set paste in order to capture pasted data verbatim (i.e. not
    do any autoindent on the lines). That's the kind of situation where the
    editor could recognize a paste automatically, and preserve its
    formatting. )
    --
    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 Fri Oct 24 01:46:06 2025
    From Newsgroup: comp.unix.shell

    On Fri, 24 Oct 2025 03:03:11 +0200, Janis Papanagnou wrote:

    What are all these ANSI terminal control commands doing?

    Kaz nailed it spot on down-thread.
    --
    Mike Sanders
    :wq
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Janis Papanagnou@janis_papanagnou+ng@hotmail.com to comp.unix.shell on Fri Oct 24 04:08:02 2025
    From Newsgroup: comp.unix.shell

    On 24.10.2025 03:31, Kaz Kylheku wrote:
    On 2025-10-24, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
    On 24.10.2025 02:11, Michael Sanders wrote:

    printf '\033[?1000h'
    printf '\033[?1000l'

    What are all these ANSI terminal control commands doing?

    1000h enables mouse events being reported; 1000l disables it.

    Thanks.

    Incidentally I encountered some similar codes just recently and
    wondered what they are doing; the following I could not resolve

    033 [ 1 ; 2 8 r
    033 ( B
    033 [ 4 l
    033 [ ? 7 h
    033 [ ? 1 2 l

    Can someone shed some light on that?

    In my attempts to find some lists of ANSI control codes I found
    a lot of pages, but obviously none complete. - Any hints on that?

    (The problem is surely that there's so many terminal types, and
    that not all are supported or standardized?)

    Janis

    [...]

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Michael Sanders@porkchop@invalid.foo to comp.unix.shell on Fri Oct 24 02:20:25 2025
    From Newsgroup: comp.unix.shell

    On Fri, 24 Oct 2025 04:08:02 +0200, Janis Papanagnou wrote:

    Incidentally I encountered some similar codes just recently and wondered
    what they are doing; the following I could not resolve

    033 [ 1 ; 2 8 r 033 ( B 033 [ 4 l 033 [ ? 7
    h 033 [ ? 1 2 l

    Can someone shed some light on that?

    033[1;28r Set scroll region from line 1 to 28
    033(B Select default character set (ASCII)
    033[4l Disable underline mode
    033[?7h Enable line wrapping
    033[?12l Disable blinking cursor

    I *think* these are correct.

    In my attempts to find some lists of ANSI control codes I found a lot of pages, but obviously none complete. - Any hints on that?

    Everything I come across seems either incomplete or in some cases,
    have differing meanings from one reference to another...

    (The problem is surely that there's so many terminal types, and that not
    all are supported or standardized?)

    I think this too.
    --
    Mike Sanders
    :wq
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Janis Papanagnou@janis_papanagnou+ng@hotmail.com to comp.unix.shell on Fri Oct 24 04:47:56 2025
    From Newsgroup: comp.unix.shell

    On 24.10.2025 04:20, Michael Sanders wrote:
    On Fri, 24 Oct 2025 04:08:02 +0200, Janis Papanagnou wrote:

    Incidentally I encountered some similar codes just recently and wondered
    what they are doing; the following I could not resolve

    033 [ 1 ; 2 8 r 033 ( B 033 [ 4 l 033 [ ? 7
    h 033 [ ? 1 2 l

    Can someone shed some light on that?

    033[1;28r Set scroll region from line 1 to 28

    Darn. - I now recall I even used that one in one of my programs!
    The problem was I took that from an isolated source, not one of
    the many lists I inspected and where it was missing.

    033(B Select default character set (ASCII)

    This one is a bit misleading; is ASCII per definition the default?
    (I wonder what happens in an ISO 8859-15 or UTF-8 encoded system
    context.)

    033[4l Disable underline mode
    033[?7h Enable line wrapping
    033[?12l Disable blinking cursor

    I *think* these are correct.

    Thanks.

    In my attempts to find some lists of ANSI control codes I found a lot of
    pages, but obviously none complete. - Any hints on that?

    Everything I come across seems either incomplete or in some cases,
    have differing meanings from one reference to another...

    Oh! This sounds even worse.


    (The problem is surely that there's so many terminal types, and that not
    all are supported or standardized?)

    I think this too.

    Janis

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Michael Sanders@porkchop@invalid.foo to comp.unix.shell on Fri Oct 24 03:03:37 2025
    From Newsgroup: comp.unix.shell

    Bug fix (of course!)

    pause() {
    msg=${1:-"Press any key or click..."} # default message
    printf '%s' "$msg"
    old=$(stty -g)
    # enable mouse tracking (emits multiple bytes!)
    printf '\033[?1000h'
    stty raw -echo
    # blocking: consume 1st byte only
    dd bs=1 count=1 < /dev/tty >/dev/null 2>&1
    # non-blocking: consume remaining bytes if any
    dd bs=1 iflag=nonblock < /dev/tty >/dev/null 2>&1
    # disable mouse tracking
    printf '\033[?1000l'
    stty "$old"
    echo
    }

    On Fri, 24 Oct 2025 00:11:51 -0000 (UTC), Michael Sanders wrote:

    #!/bin/sh

    <<'NOTES'

    pauses your script then continues on either a single key press or mouse click, works here with an xterm compatible terminal

    Michael Sanders 2025

    NOTES

    pause() {
    msg=${1:-"Press any key or click..."} # default message printf '%s'
    "$msg"
    old=$(stty -g)
    printf '\033[?1000h'
    stty raw -echo dd bs=1 count=1 < /dev/tty 2>/dev/null printf
    '\033[?1000l'
    stty "$old"
    }

    pause "Your script has finished"

    # eof
    --
    Mike Sanders
    :wq
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Lawrence =?iso-8859-13?q?D=FFOliveiro?=@ldo@nz.invalid to comp.unix.shell on Fri Oct 24 04:44:13 2025
    From Newsgroup: comp.unix.shell

    On Fri, 24 Oct 2025 02:20:25 -0000 (UTC), Michael Sanders wrote:

    033[1;28r Set scroll region from line 1 to 28
    033(B Select default character set (ASCII)
    033[4l Disable underline mode
    033[?7h Enable line wrapping
    033[?12l Disable blinking cursor

    I *think* these are correct.

    <https://manpages.debian.org/console_codes(4)> covers just the Linux text console, which is already pretty extensive; I think most if not all the
    GUI terminal emulators implement supersets of that.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Keith Thompson@Keith.S.Thompson+u@gmail.com to comp.unix.shell on Fri Oct 24 03:23:57 2025
    From Newsgroup: comp.unix.shell

    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
    [...]
    In my attempts to find some lists of ANSI control codes I found
    a lot of pages, but obviously none complete. - Any hints on that?

    (The problem is surely that there's so many terminal types, and
    that not all are supported or standardized?)

    I usually refer to this web page :

    https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
    --
    Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
    void Void(void) { Void(); } /* The recursive call of the void */
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Michael Sanders@porkchop@invalid.foo to comp.unix.shell on Fri Oct 24 11:26:41 2025
    From Newsgroup: comp.unix.shell

    On Fri, 24 Oct 2025 04:44:13 -0000 (UTC), Lawrence DrCOOliveiro wrote:

    <https://manpages.debian.org/console_codes(4)> covers just the Linux
    text console, which is already pretty extensive; I think most if not all
    the GUI terminal emulators implement supersets of that.

    Appreciate it.
    --
    Mike Sanders
    :wq
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Michael Sanders@porkchop@invalid.foo to comp.unix.shell on Fri Oct 24 12:29:11 2025
    From Newsgroup: comp.unix.shell

    Final update for me, works well it seems. Thanks to all.

    #!/bin/sh

    <<'NOTES'

    pauses your script then continues on either a single key press
    or mouse click, works here with an xterm compatible terminal

    updated with comments, etc

    Michael Sanders 2025

    001 default message
    002 print formatted message
    003 save terminal cfg
    004 X10: enable mouse mode, use X10 or SGR not both
    005 SGR: enable mouse mode
    006 input byte-for-byte, no line buffering
    007 blocking: consume 1st byte only
    008 non-blocking: consume remaining bytes
    009 X10: disable mouse mode, use X10 or SGR not both
    010 SGR: disable mouse mode
    011 restore terminal cfg
    012 new-line after reset

    NOTES

    pause() {
    msg=${1:-'Press any key or click...'} # 001
    printf '%b' "$msg" # 002
    cfg=$(stty -g) # 003
    # printf '\033[?1000h' # 004
    printf '\033[?1002h\033[?1006h' # 005
    stty raw -echo # 006
    dd bs=1 count=1 < /dev/tty >/dev/null 2>&1 # 007
    dd bs=1 iflag=nonblock < /dev/tty >/dev/null 2>&1 # 008
    # printf '\033[?1000l' # 009
    printf '\033[?1002l\033[?1006l' # 010
    stty "$cfg" # 011
    echo # 012
    }

    for x in 3 2 1; do echo $x; done

    pause 'Your script has finished'

    # eof
    --
    Mike Sanders
    :wq
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Janis Papanagnou@janis_papanagnou+ng@hotmail.com to comp.unix.shell on Sat Oct 25 03:28:04 2025
    From Newsgroup: comp.unix.shell

    On 24.10.2025 12:23, Keith Thompson wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
    [...]
    In my attempts to find some lists of ANSI control codes I found
    a lot of pages, but obviously none complete. - Any hints on that?

    (The problem is surely that there's so many terminal types, and
    that not all are supported or standardized?)

    I usually refer to this web page :

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

    Noted. Looks good. Thanks.

    Janis

    --- Synchronet 3.21a-Linux NewsLink 1.2