Skip to content

Instantly share code, notes, and snippets.

@jaggzh
Created April 4, 2026 03:46
Show Gist options
  • Select an option

  • Save jaggzh/99e059d406d41c888b25b426e0719b24 to your computer and use it in GitHub Desktop.

Select an option

Save jaggzh/99e059d406d41c888b25b426e0719b24 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [[ $# -gt 0 && "$1" = no-less ]]; then
shift
else
exec ansi-text-attributes-preview no-less "$@" 2>&1 | less -R
# Less also doesn't carry attributes across lines, so...
# ..to do this piping we have to put the attribute term
# sequences on each line.
fi
w=60
read -d '' -r testtext <<'EOT'
0123456789 !\"#$%&'()*+,-./:;<=>?@[\\]^_\`{|}~
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
àáâäæçèéêëìíîïñòóôöùúûüÿ
← ↑ → ↓ ↔ ↕ ↖ ↗ ↘ ↙ ↚ ↛ ↜ ↝ ↞ ↟ ↠ ↡ ↢ ↣ ↤ ↥ ↦ ↧ ↨ ↩ ↪ ↫
↬ ↭ ↮ ↯ ↰ ↱ ↲ ↳ ↴ ↵ ↶ ↷ ↸ ↹ ↺ ↻ ↼ ↽ ↾ ↿ ⇀ ⇁ ⇂ ⇃ ⇄ ⇅ ⇆ ⇇
⇈ ⇉ ⇊ ⇋ ⇌ ⇍ ⇎ ⇏ ⇐ ⇑ ⇒ ⇓ ⇔ ⇕ ⇖ ⇗ ⇘ ⇙ ⇚ ⇛ ⇜ ⇝ ⇞ ⇟ ⇠ ⇡ ⇢ ⇣
⇤ ⇥ ⇦ ⇧ ⇨ ⇩ ⇪ ⇫ ⇬ ⇭ ⇮ ⇯ ⇰ ⇱ ⇲ ⇳ ⇴ ⇵ ⇶ ⇷ ⇸ ⇹ ⇺ ⇻ ⇼ ⇽ ⇾ ⇿
😀😁😂🤣😅😊😍🤔👍🔥🍀🌍
EOT
if [[ $# -gt 0 ]]; then
testtext="$*"
fi
testtext=${testtext%$'\n'}$'\n'
repc() {
local c=$1;
local cnt=$2;
# echo "cnt: $cnt"
for ((i=0; i<$cnt; i++)); do echo -n "$c"; done
}
cline() { local c=$1; repc "$c" "$w"; echo; }
showstyle() {
lbl=$1; txt=$2; st=$3; en=$4;
perl_st=$5; perl_en=$6;
lbl_blank=$(printf '%*s' "${#lbl}")
# echo "=== $lbl === (st:$st) (en:$en)"
# echo ───────────────────────────────────────────────────────────
echo -n $'\e[30;1m '
cline ▁
echo -n $'\e[m'
echo -n $'╭\e[48;2;0;20;40m'
title="$lbl │ (st:$st) (en:$en)"
title2="$lbl_blank │ Perl/Bash: $perl_st .. $perl_en"
tit_l="▒░▏ "
tit_r=" ▕░▒"
tit_l_len=${#tit_l}
tit_r_len=${#tit_r}
tit_bord_len=$((tit_l_len + tit_r_len))
tit_len=${#title}
tit2_len=${#title2}
printf '%s%s%*s%s\e[0m╮\n' "$tit_l" "$title" $(($w-$tit_bord_len-$tit_len)) '' "$tit_r"
if [[ -n "$perl_st" || -n "$perl_en" ]]; then
echo -n $'│\e[48;2;0;20;40m'
printf '%s%s%*s%s\e[0m│\n' "$tit_l" "$title2" $(($w-$tit_bord_len-$tit2_len)) '' "$tit_r"
fi
# echo -e "$st$txt$en"
st=${st//\\e/}
en=${en//\\e/}
printf '%s' "$txt" | sed -e "s/^/$st/; s/$/$en/;"
}
showstyle 'Normal' "$testtext" '' ''
# Font styles
showstyle 'Bold' "$testtext" '\e[1m' '\e[22m' '$bo_s' '$bo_e'
showstyle 'Faint' "$testtext" '\e[2m' '\e[22m' '$faint_s' '$faint_e'
showstyle 'Italic' "$testtext" '\e[3m' '\e[23m' '$it_s' '$it_e'
showstyle 'Bold+Italic' "$testtext" '\e[1m\e[3m' '\e[22m\e[23m' '$boit_s' '$boit_e'
showstyle 'Underline' "$testtext" '\e[4m' '\e[24m' '$un_s' '$un_e'
showstyle 'Double Under' "$testtext" '\e[21m' '\e[24m' '$dun_s' '$dun_e'
showstyle 'Curly Under' "$testtext" '\e[4:3m' '\e[24m' '$curly_un_s' '$curly_un_e'
showstyle 'Dotted Under' "$testtext" '\e[4:4m' '\e[24m' '$dot_un_s' '$dot_un_e'
showstyle 'Dashed Under' "$testtext" '\e[4:5m' '\e[24m' '$dash_un_s' '$dash_un_e'
showstyle 'Overline' "$testtext" '\e[53m' '\e[55m' '$oline_s' '$oline_e'
# Cross-out & invert
showstyle 'Strikethru' "$testtext" '\e[9m' '\e[29m' '$strikethru_s' '$strikethru_e'
showstyle 'Inverse' "$testtext" '\e[7m' '\e[27m' '$inv_s' '$inv_e'
# Heavier/extra-bold (if supported by font/terminal)
showstyle 'Heavy' "$testtext" '\e[1;2m' '\e[22m' '$heavy_s' '$heavy_e'
# Reset
echo -e "\e[0m"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment