firasuke / colorsh

A small shell script that shows all supported terminal colors
ISC License
3 stars 0 forks source link

Somewhat limited.. #1

Open c-blake opened 1 month ago

c-blake commented 1 month ago

So, I never think to distribute my many little scripts, but I have one you might appreciate that I just call tcolors:

#!/bin/sh
for style in "$@"; do   # Dump colors to evaluate color combination readability
    case "$style" in    #..as well as assess terminal support for various SGRs.
    bold)      styles="${styles};1" ;;
    faint)     styles="${styles};2" ;;
    italic)    styles="${styles};3" ;;
    underline) styles="${styles};4" ;;
    blink)     styles="${styles};5" ;;
    BLINK)     styles="${styles};6" ;;
    inverse)   styles="${styles};7" ;;
    invisible) styles="${styles};8" ;;
    struck)    styles="${styles};9" ;;
    undercurl) styles="${styles};4:2" ;;
    esac
done
for bbank in 4 10; do                   #dark, light background banks
  for bc in 0 1 2 3 4 5 6 7; do         #all backgrounds
    printf "\033[${bbank}${bc}m"
    printf "%3d:" "${bbank}${bc}"
    for fbank in 3 9; do                #dark, light foreground banks
      for fc in 0 1 2 3 4 5 6 7; do     #all foregrounds
        printf "\033[${fbank}${fc}${styles}m ${fbank}${fc}"
      done
    done
    printf "\033[;${styles};${bbank}${bc};1m BD"  #Some terms support 3 more fg
    printf "\033[;${styles};${bbank}${bc};3m IT"  #..colors if fg is unspecified
    printf "\033[;${styles};${bbank}${bc};3;1m BI"
    printf "\033[;${styles};${bbank}${bc};4m UL"
    printf "\033[m\n"
  done
done
printf "\nxt256: "; for i in `seq 0 71`; do     # Check xterm256 color support
  printf "\033[48;5;%dm \033[m" "$((16 + 3*i))" # i=36*r + 6*g + b
done
printf "\nTruCo: "; for x in `seq 0 71`; do     # Check true color support
  r=$((255 - (x*255 / 71)))
  g=$((x*510 / 71))
  b=$((x*255 / 71))
  [ $g -gt 255 ] && g=$((510 - g))
  printf "\033[48;2;%d;%d;%dm \033[m" "$r" "$g" "$b"
done; echo

Relative to your colorsh it's output is more compactly formatted without redundant (but, trade-off, copy pastable..) text and more complete in covering special colors for "bold" (italic/underline) like the Linux VT has always had, true colors, and the 6x6x6 color cube of xterm-256.

firasuke commented 1 month ago

but I have one you might appreciate ...

I do appreciate the completeness of your script, thanks for sharing!

c-blake commented 1 month ago

Sure. FWIW, an interesting invocation that may vary across terminals is: ./tcolors; ./tcolors inverse because AFAIK there is no standard convention for fg-bg mappings under inverse. :-)