• Re: tput help

    From Greg Wooledge@21:1/5 to Eben King on Sun Jun 29 02:40:01 2025
    On Sat, Jun 28, 2025 at 18:28:31 -0400, Eben King wrote:
    A while back I wrote a script to take the output of dd and make a graph of the transfer rate. It worked, but since it scrolls up I wasn't happy with it.

    In a bash script, I'm trying to use tput commands to delete column 1 (tput cup $row 1 && tput el1), scoot the rest of the line left, then draw along
    the right edge (echo -n). Step 2 is proving problematic, as in I don't know how to do it. Is there another way? Thanks.

    Are you doing a two-dimensional grid, or just a single line of text
    which is continually replaced?

    A single line is extremely simple: you write a CR (\r) character to move
    the cursor to the start of the line, and then you rewrite the entire
    line of text, with space padding at the end if necessary. No tput is
    even needed, if you use the space padding. You could use a "clear to
    end of line" command if you don't want to pad it.

    Here's a simple demonstration of a single line with space padding.
    We know that the output of $RANDOM is always between 1 and 5 characters
    (the highest number it can produce is 32767), so we take that into
    account when calculating the field width.

    ==================================================
    #!/bin/bash

    for ((i=0; i < 60; i++)); do
    text="There are $RANDOM things left."
    printf '\r%-28s' "$text"
    sleep 0.3s
    done

    echo
    ==================================================

    If you want to use tput output (erase to EOL, for example), the best way
    to do it is to run the tput command once up front and save its output
    in a variable. Then use the variable in your printing loop. Here's the
    same example using that technique:

    ==================================================
    #!/bin/bash

    el=$(tput el)
    for ((i=0; i < 60; i++)); do
    text="There are $RANDOM things left."
    printf '\r%s%s' "$text" "$el"
    sleep 0.3s
    done

    echo
    ==================================================

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Michael Paoli@21:1/5 to [email protected] on Mon Jun 30 18:50:01 2025
    I think you want delete, rather than erase, so use tput dch1 or tput dch 1. Erase simply replaces the character(s) with blank(s),
    whereas delete removes the character(s), shifting those to the right,
    to the left.

    E.g.:
    (row=3; sleep=2; cols=$(tput cols) && tput clear && (while [ $row -gt
    0 ]; do echo; row=$((row - 1)); done) && d=32 && e=$(($d + $cols - 2))
    && while [ $d -le 126 ]; do [ $d -le $e ] || break; echo -ne "$(printf
    '\%04o' $d)"; d=$((d + 1)); done && sleep $sleep && tput cup $row 0 &&
    sleep $sleep; tput dch1; sleep $sleep; echo)

    Note however, if (long) line was wrapped by terminal rather than by newline, depending on terminal/emulation, it might possibly also alter
    subsequent displayed line(s).

    Read The Fine Manual (RTFM)

    https://manpages.debian.org/stable/ncurses-bin/terminfo.5.en.html

    On Sat, Jun 28, 2025 at 3:29 PM Eben King <[email protected]> wrote:

    A while back I wrote a script to take the output of dd and make a graph
    of the transfer rate. It worked, but since it scrolls up I wasn't happy
    with it.

    In a bash script, I'm trying to use tput commands to delete column 1
    (tput cup $row 1 && tput el1), scoot the rest of the line left, then
    draw along the right edge (echo -n). Step 2 is proving problematic, as
    in I don't know how to do it. Is there another way? Thanks.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)