Skip to content

Instantly share code, notes, and snippets.

@ochafik
Last active February 1, 2022 02:47
Show Gist options
  • Select an option

  • Save ochafik/aef806cc1b697ec034b540cdaa9fd3aa to your computer and use it in GitHub Desktop.

Select an option

Save ochafik/aef806cc1b697ec034b540cdaa9fd3aa to your computer and use it in GitHub Desktop.
Unicode block art in Bash for animated progress indicators or sliders
export amplitudeChars=( " " ▁ ▂ ▃ ▄ ▅ ▆ ▇ █ )
axis() {
local negSym="$1"
local posSym="$2"
local value="$3"
local maxAmplitude="$4"
local amplitudeChar=${amplitudeChars[$( printf "%d" $(( value * ${#amplitudeChars[@]} / maxAmplitude )) )]}
local percent=$( printf "%03d" $(( value * 100 / maxAmplitude )) )
if (( $value < 0 )); then
echo -n "$negSym $amplitudeChar"
elif (( $value > 0 )); then
echo -n "$negSym $amplitudeChar"
else
echo -n " "
fi
}
axis ⬇︎ ⬆︎ 50 100
axis ⬅ ⮕ 50 100
#!/bin/bash
set -eu
export seq1=( ▖ ▘ ▝ ▗ )
export seq2=( ▌ ▞ ▀ ▚ ▐ ▞ ▄ ▚ )
export seq3=( ▜ ▟ ▙ ▛ )
export seq4=( ▁ ▂ ▃ ▄ ▅ ▆ ▇ █ ▇ ▆ ▅ ▄ ▃ ▂ )
sym1() {
echo -n "${seq1[$(( i % ${#seq1[@]} ))]}"
}
sym2() {
echo -n "${seq2[$(( i % ${#seq2[@]} ))]}"
}
sym3() {
echo -n "${seq3[$(( i % ${#seq3[@]} ))]}"
}
sym4() {
echo -n "${seq4[$(( i % ${#seq4[@]} ))]}"
}
export i=0
while true ; do
echo -ne \
"\b\b\b\b\b\b\b\b$( sym1 $i ) $( sym2 $i ) $( sym3 $i ) $( sym4 $i ) "
sleep 0.2
export i=$(( i + 1 ))
done
<window height="250" width="300" duration="1:00:00.00" bgcolor="yellow">
<time begin="0:00:00.00" end="0:00:05.00"/>
<pre>
| ↑▄ ↑▄ |
| ←▄ ✛ ▄→ ←▄ ✛ ▄→ |
| ↓▄ ↓▄ |
</pre>
<time begin="0:00:05.00" end="0:00:10.00"/>
<pre>
| ↑▄ |
| ←▄ ✛ ✛ ▄→ |
| ↓▄ |
</pre>
<time begin="0:00:10.00" end="0:00:15.00"/>
<pre>
| ↑▄ |
| ✛ ✛ |
| ↓▄ |
</pre>
<time begin="0:00:05.00"/>Hello
</window>
<pre><code>
⬆︎▄ ⬆︎▄
▄⬅ ⮕▄ ▄⬅ ⮕▄
⬇︎▄ ⬇︎▄
</code></pre>
<pre><code>
↑▄ ↑▄ ↑▄
▄← ✛ →▄ ▄← ✛ →▄ ▄←✛→▄
↓▄ ↓▄ ↓▄
</code></pre>
<pre><code>
↑▄
▄← ✛ ✛ →▄
↓▄
</code></pre>
<pre>
↑▄ ↑▄
←▄ ✛ ▄→ ←▄ ✛ ▄→
↓▄ ↓▄
</pre>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment