β³ Progress & Prompts
Progress bars, spinners, loaders, animations, and interactive prompts.
Progress
Adds a newline by default. Use --inline for loop-based updates.
shui progress 50 100
shui progress 50 100 --width=30 --label="Downloading "
for i in {1..100}; do
shui progress $i 100 --inline
sleep 0.05
done
echoββββββββββββββββββββββββββββββββββββββββ 50%
Downloading ββββββββββββββββββββββββββββββ 50%Pass --iterm (or --iterm=<state>) to also update the native macOS progress
indicator in iTerm2 β normal, success, warning, error,
indeterminate, or clear. No-op in other terminals.
Spinner
Runs a command in the background with a spinner. Exits with the command's exit code, and in iTerm2 emits an indeterminate badge while running.
shui spinner "Installingβ¦" -- brew install ripgrep
shui spinner \
--success="Installed!" \
--fail="Installation failed" \
"Installingβ¦" -- npm installLoader
Indeterminate loading indicator β loops for a fixed duration then clears the
line. Use when you can't wrap a command in spinner.
shui loader "Installing packages"
shui loader --duration=10 "Building"
shui loader --style=pulse "Connecting"| Style | Description |
|---|---|
dots | Cycling dot trail β . .. ... |
pulse | Bold/dim alternating text |
spinner | Braille spinner character |
Animation
One-shot text effects β play once and exit.
shui typewriter "Deploying to productionβ¦"
shui typewriter --delay=0.05 --color=success "Done!"
shui fade-in "Welcome"
shui fade-in --steps=10 "Welcome"Interactive
Prompt the user for confirmation, a selection, or free-form input.
# Confirm β exits 0 for yes, 1 for no
shui confirm "Deploy to production?"
# Select β numbered list, prints the chosen option to stdout
choice=$(shui select "Pick a profile:" work personal staging)
# Radio β ββ to move, Enter to confirm
env=$(shui radio "Target environment:" development staging production)
# Multiselect β Space to toggle, Enter to confirm
choices=$(shui multiselect "Which packages?" brew npm cargo)
# Input β prints the entered value to stdout
name=$(shui input --default="world" "Your name:")
# Password β nothing echoed, prints the value to stdout
secret=$(shui password "Passphrase:")password reads the line the way sudo does, with echo off, so terminals that
watch for password prompts (iTerm2's padlock, Terminal.app's Secure Keyboard
Entry) engage secure input while you type. In place of stars, a muted
(typing hidden) hint follows the prompt, drawn like input's default.
--mask shows a * per keystroke
instead, but it reads key by key in raw mode, which hides the prompt from that
check: secure input stays off. Ctrl-C is a real signal here, as under sudo:
echo comes back, the prompt exits 130, and a script that does not trap INT
stops.
radio and multiselect take options as labelβ₯hint and print only the labels.
A list taller than the terminal scrolls with the cursor, under a position line
such as 12β30 of 76, and a line wider than the terminal is cut with an
ellipsis on screen, never in what is printed. q, Esc and Ctrl-C cancel with
exit 130.
Columns, a detail pane and a footer
multiselect can draw each row as aligned columns, with a pane under the list
that follows the cursor and a footer that follows the ticks. Every flag is
opt-in; without them the list is the plain labelβ₯hint one above.
rows=(
$'alpha\t{success:βββ}\talpha\t1.2.0 β 1.2.{success:1}\t{success:patch}\t~2m'
$'beta\t{muted:β}\tbeta\t2.4.0 β {error:3.0.0}\t{error:MAJOR}\t~8m'
)
details=(
$'alpha Β· a small example library\nVersion 1.2.0 β 1.2.1 patch\nBuild ~2m estimated'
$'beta Β· another one\nVersion 2.4.0 β 3.0.0 MAJOR\nBuild ~8m estimated\nNote may change behaviour'
)
total() { print -r -- "$# ticked Β· {bold:about $(( $# * 5 ))m}" }
ids=$(shui multiselect \
--columns='l:3:1,l:*:0,r:16:3,l:7:0,r:4:0' \
--header=$'\tname\tfrom β to\tlevel\ttime' \
--keys='ββ move Β· space tick Β· a all Β· enter build Β· q later' \
--details=details --footer=total \
"Build which now?" "${rows[@]}")- Rows are
idβ₯cellβ₯cellβ¦. The id is never drawn; it is what comes back for each ticked row, one per line. --columnstakes onealign:width:dropentry per cell:lorr; a width, or*for the one flexible column, which takes the room left up to its widest cell (at least 12 wide,*Nfor a larger minimum); and a drop number. When a row does not fit, the column with the highest drop number goes first, then the next;0never goes. Fixed widths come from you and the flexible one is measured once over every row, so nothing shifts as the list scrolls.--headeris a row of cells with no id, drawn muted above the list.--keysreplaces the key hint, so the words can match what enter does.--detailsnames an array with one element per row. Its lines are joined by newlines; the first is drawn as a rule (ββ text βββ), the rest under it. The pane keeps the height of the longest element (at most 6 lines), so the list never jumps, and it is the first thing given up in a short terminal.--footernames a function. It runs in a subshell with the ticked ids as arguments, once at the start and again whenever the ticks change, never on a cursor move. Its first line of output is the footer; no output or a failure is an empty footer. Keep it fast and free of side effects: a footer that hangs cannot be interrupted.
Cells, the header, detail lines and the footer take colour spans:
{success:text}, {warning:β¦}, {error:β¦}, {info:β¦}, {muted:β¦} and
{bold:β¦}, mapped to the theme, so they disappear under plain. {{ is a
literal {, and inside a span }} is a literal }. Anything else in braces is
drawn as written; still, escape text you did not write with ${s//\{/{{}.
The cursor row's flexible cell is drawn bold, beside the pointer.
--details and --footer name things in the calling shell, so they work with
a sourced shui only, which is how shui is used. A malformed flag prints the
reason to stderr and exits 1 before anything is drawn.
Every prompt reads its answer from the terminal, not from stdin. When there is no
terminal to ask (cron, CI, a detached process), it draws nothing, prints
shui: no terminal to ask; pass --yes to stderr and exits 2 β a default is
never taken on the user's behalf, so --default=y cannot turn into consent
nobody gave. Scripts can tell the three outcomes apart:
shui confirm "Deploy to production?"
case $? in
0) deploy ;;
1) echo "cancelled" ;;
2) echo "no terminal: rerun with --yes" >&2; exit 2 ;;
esac