Created
July 1, 2026 10:18
-
-
Save dln/cb136292bf58078f9007a7c21e3c4577 to your computer and use it in GitHub Desktop.
test-term.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| strip_ansi() { | |
| sed -E 's/\x1b\[[0-9;:]*[A-Za-z]//g' <<< "$1" | |
| } | |
| col_width=56 | |
| attr_col=24 | |
| # Renders "LABEL" + padding + "reverse LABEL", with "reverse" always | |
| # starting at attr_col regardless of label length. | |
| attr_row() { | |
| local code=$1 label=$2 rcode=$3 rlabel=$4 | |
| local pad=$(( attr_col - ${#label} )) | |
| (( pad < 2 )) && pad=2 | |
| printf '\e[%sm%s\e[0m%*s\e[%sm reverse%s \e[0m' "$code" "$label" "$pad" '' "$rcode" "$rlabel" | |
| } | |
| # Prints two arrays of pre-rendered lines side by side. Once the shorter | |
| # array runs out, remaining lines of the longer one print full width. | |
| print_columns() { | |
| local -n _left=$1 | |
| local -n _right=$2 | |
| local left_n=${#_left[@]} | |
| local right_n=${#_right[@]} | |
| local n=$(( left_n > right_n ? left_n : right_n )) | |
| local i | |
| for (( i = 0; i < n; i++ )); do | |
| if (( i >= left_n )); then | |
| printf '%s\n' "${_right[i]}" | |
| continue | |
| fi | |
| local l="${_left[i]}" | |
| local r="${_right[i]:-}" | |
| if [[ -z "$r" ]]; then | |
| printf '%s\n' "$l" | |
| continue | |
| fi | |
| local plain pad | |
| plain=$(strip_ansi "$l") | |
| pad=$(( col_width - ${#plain} )) | |
| (( pad < 2 )) && pad=2 | |
| printf '%s%*s%s\n' "$l" "$pad" '' "$r" | |
| done | |
| } | |
| # --- left column: SGR attribute / color tests --- | |
| LEFT=( | |
| "$(attr_row 0 normal 7 '')" | |
| "$(attr_row 2 dim '7;2' ' dim')" | |
| "$(attr_row 1 bold '7;1' ' bold')" | |
| "$(attr_row 3 italic '7;3' ' italic')" | |
| "$(attr_row '2;3' 'dim italic' '7;2;3' ' dim italic')" | |
| "$(attr_row '1;3' 'bold italic' '7;1;3' ' bold italic')" | |
| '' | |
| $'\e[4munderline\e[0m' | |
| $'\e[3;4mitalic underline\e[0m' | |
| $'\e[4:1mthis is also underline \e[0m' | |
| $'\e[21mdouble underline \e[0m' | |
| $'\e[4:2mthis is also double underline \e[0m' | |
| $'\e[4:3mcurly underline \e[0m' | |
| $'\e[21m\e[58;5;42m256-color underline \e[0m' | |
| $'\e[4:3m\e[58;2;240;143;104mtruecolor underline (*)\e[0m' | |
| $'\e[58:2::255:0:0m\e[4:1msingle underline \e[0m' | |
| $'\e[4:2mdouble underline \e[58:2::255:0:0m and with color\e[0m' | |
| $'\e[4:3mcurly underline \e[58:2::255:0:0m and with color\e[0m' | |
| $'\e[4:4mdotted underline \e[58:2::255:0:0m and with color\e[0m' | |
| $'\e[4:5mdashed underline \e[58:2::255:0:0m and with color\e[0m' | |
| '' | |
| $'\e[5mblink \e[0m' | |
| $'\e[8minvisible\e[0m <- invisible (but copy-pasteable)' | |
| $'\e[9mstrikethrough\e[0m' | |
| $'\e[53moverline \e[0m' | |
| $'\e[51mframed \e[0m' | |
| $'\e[52mencircled \e[0m' | |
| '' | |
| $'\e[31mred\e[0m' | |
| $'\e[91mbright red\e[0m' | |
| $'\e[38:5:42m256-color, de jure standard (ITU-T T.416)\e[0m' | |
| $'\e[38:2::240:143:104mtruecolor, de jure standard (ITU-T T.416) \e[0m' | |
| '' | |
| $'\e[46mcyan background\e[0m' | |
| $'\e[106mbright cyan background\e[0m' | |
| $'\e[48:5:42m256-color background, de jure std (ITU-T T.416)\e[0m' | |
| $'\e[48:2::240:143:104mtruecolor background, de jure std (ITU-T T.416) \e[0m' | |
| $'\e[48:2:240:143:104mtruecolor background, rarely used incorrect format\e[0m' | |
| '' | |
| "Blocks:" | |
| "🮙 ░ ▒ ▓ █ █ ▊ ▋ ▌ ▍ ▎ ▏" | |
| "🮙 ░ ▒ ▓ █ █ ▊ ▋ ▌ ▍ ▎ ▏" | |
| "🮙 ░ ▒ ▓ █ █ ▊ ▋ ▌ ▍ ▎ ▏" | |
| "▄ ▀ ▁ ▂ ▃ ▄ ▅ ▆ ▇ █" | |
| '' | |
| "╭──────────────╮" | |
| "│ border chars │" | |
| "╰──────────────╯" | |
| '' | |
| "Border styles (light, heavy, double, rounded):" | |
| "┌─┬─┐ ┏━┳━┓ ╔═╦═╗ ╭─┬─╮" | |
| "├─┼─┤ ┣━╋━┫ ╠═╬═╣ ├─┼─┤" | |
| "└─┴─┘ ┗━┻━┛ ╚═╩═╝ ╰─┴─╯" | |
| ) | |
| # --- right column: text / glyph rendering tests --- | |
| RIGHT=( | |
| "For a number of years now, work has been proceeding in order to" | |
| "bring perfection to the crudely conceived idea of a transmission" | |
| "that would not only supply inverse reactive current for use in" | |
| "unilateral phase detractors, but would also be capable of auto-" | |
| "matically synchronizing cardinal grammeters. Such an instrument" | |
| "is the turbo encabulator. Now basically the only new principle" | |
| "involved is that instead of power being generated by the relative" | |
| "motion of conductors and fluxes, it is produced by the modial" | |
| "interaction of magneto-reluctance and capacitive diractance. The" | |
| "original machine had a base plate of pre-famulated amulite" | |
| "surmounted by a malleable logarithmic casing in such a way that" | |
| "the two spurving bearings were in a direct line with the panamet-" | |
| "ric fan." | |
| '' | |
| $'\e[3mThe latter consisted simply of six hydrocoptic marzlevanes, so\e[0m' | |
| $'\e[3mfitted to the ambifacient lunar waneshaft that side fumbling was\e[0m' | |
| $'\e[3meffectively prevented. The main winding was of the normal\e[0m' | |
| $'\e[3mlotus-o-delta type placed in panendermic semi-boloid slots of the\e[0m' | |
| $'\e[3mstator, every seventh conductor being connected by a non-reversi\e[0m' | |
| $'\e[3mible tremie pipe to the differential girdle spring on the "up"\e[0m' | |
| $'\e[3mend of the grammeters. The turbo-encabulator has now reached a\e[0m' | |
| $'\e[3mhigh level of development, and it’s being successfully used in\e[0m' | |
| $'\e[3mthe operation of novertrunnions. Moreover, whenever a forescent\e[0m' | |
| $'\e[3mskor motion is required, it may also be employed in conjunction\e[0m' | |
| $'\e[3mwith a drawn reciprocation dingle arm, to reduce sinusoidal\e[0m' | |
| $'\e[3mrepleneration.\e[0m' | |
| '' | |
| "Emoji: 🚀 💩 😁 🍖 🔥 🔷 ❤️ " | |
| '' | |
| "Geometrical:" | |
| "◆ ◇ ◈ ● ○ ◉ ◎ ◍ ◌" | |
| "■ □ ▢ ▣ ▤ ▥ ▦ ▧ ▨ ▩" | |
| "◧ ◨ ◩ ◪ ◫ ◬ ◭ ◮ △ ▲ ▱ ▰ ▽ ▼ ▾ ▿" | |
| "◠ ◡ ◢ ◣ ◤ ◥ ◦ ◧ ◨ ◩ ◪ ◫ ◬ ◭ ◮ ◯ ◰ ◱ ◲ ◳ ◴ ◵ ◶ ◷ ◸ ◹ ◺ ◻ ◼ ◽ ◾ ◿" | |
| '' | |
| "Arrows:" | |
| "← → ↑ ↓ ↔ ↔ ↕ ↖ ↗ ↙ ↘ ↠ ↣ ↦ ↧ ↨ ↩ ↪ ↫ ↬ ↭ ↮" | |
| "↯ ↰ ↱ ↲ ↳ ↴ ↵ ↶ ↷ ↸ ↹ ↺ ↻ ↼ ↽ ↾ ↿ ↼ ↽ ↾ ↿ ⇄" | |
| "↔ ⇀ ⇂ ⇄ ⇆ ⇌ ⇎ ⇐ ⇑ ⇓ ⇕ ⇖ ⇗ ⇘ ⇙ ⇚ ⇛ ⇜ ⇝ ⇞ ⇟" | |
| '' | |
| "Ligatures:" | |
| "-<< -< -<- <-- <--- <<- <- -> ->> --> --->" | |
| "->- >- >>- <-> <--> <---> <----> <!--" | |
| "=<< =< =<= <== <=== <<= <= => =>> ==> ===>" | |
| "=>= >= >>= <=> <==> <===> <====> <!---" | |
| "[| |] {| |} <=< >=> <~~ <~ ~> ~~> :: ::: \/" | |
| "/\ == != /= ~= <> === !== =/= =!= :>" | |
| ":= :- :+ <* <*> *> <| <|> |> <. <.> .> +:" | |
| "-: =: <***> __ (* comm *) ++ +++ |- -|" | |
| ) | |
| print_columns LEFT RIGHT | |
| echo | |
| echo 24-bit colors: | |
| # This file was originally taken from iterm2 https://github.com/gnachman/iTerm2/blob/master/tests/24-bit-color.sh | |
| # | |
| # This file echoes a bunch of 24-bit color codes | |
| # to the terminal to demonstrate its functionality. | |
| # The foreground escape sequence is ^[38;2;<r>;<g>;<b>m | |
| # The background escape sequence is ^[48;2;<r>;<g>;<b>m | |
| # <r> <g> <b> range from 0 to 255 inclusive. | |
| # The escape sequence ^[0m returns output to default | |
| setBackgroundColor() { | |
| printf '\x1b[48;2;%s;%s;%sm' $1 $2 $3 | |
| } | |
| resetOutput() { | |
| echo -en "\x1b[0m\n" | |
| } | |
| # Gives a color $1/255 % along HSV | |
| # Who knows what happens when $1 is outside 0-255 | |
| # Echoes "$red $green $blue" where | |
| # $red $green and $blue are integers | |
| # ranging between 0 and 255 inclusive | |
| rainbowColor() { | |
| let h=$1/43 | |
| let f=$1-43*$h | |
| let t=$f*255/43 | |
| let q=255-t | |
| if [ $h -eq 0 ]; then | |
| echo "255 $t 0" | |
| elif [ $h -eq 1 ]; then | |
| echo "$q 255 0" | |
| elif [ $h -eq 2 ]; then | |
| echo "0 255 $t" | |
| elif [ $h -eq 3 ]; then | |
| echo "0 $q 255" | |
| elif [ $h -eq 4 ]; then | |
| echo "$t 0 255" | |
| elif [ $h -eq 5 ]; then | |
| echo "255 0 $q" | |
| else | |
| # execution should never reach here | |
| echo "0 0 0" | |
| fi | |
| } | |
| for i in $(seq 0 127); do | |
| setBackgroundColor $i 0 0 | |
| echo -en " " | |
| done | |
| resetOutput | |
| for i in $(seq 255 -1 128); do | |
| setBackgroundColor $i 0 0 | |
| echo -en " " | |
| done | |
| resetOutput | |
| for i in $(seq 0 127); do | |
| setBackgroundColor 0 $i 0 | |
| echo -n " " | |
| done | |
| resetOutput | |
| for i in $(seq 255 -1 128); do | |
| setBackgroundColor 0 $i 0 | |
| echo -n " " | |
| done | |
| resetOutput | |
| for i in $(seq 0 127); do | |
| setBackgroundColor 0 0 $i | |
| echo -n " " | |
| done | |
| resetOutput | |
| for i in $(seq 255 -1 128); do | |
| setBackgroundColor 0 0 $i | |
| echo -n " " | |
| done | |
| resetOutput | |
| for i in $(seq 0 127); do | |
| setBackgroundColor $(rainbowColor $i) | |
| echo -n " " | |
| done | |
| resetOutput | |
| for i in $(seq 255 -1 128); do | |
| setBackgroundColor $(rainbowColor $i) | |
| echo -n " " | |
| done | |
| resetOutput |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment