#! /bin/zsh # # this file: # https://dataswamp.org/~incal/conf/.zsh/colors # # examples: # https://dataswamp.org/~incal/figures/tty-colors.png # https://dataswamp.org/~incal/conf/.Xresources # # tutorial: # https://dataswamp.org/~incal/cols/www/COLORS set-fg-color () { tput setaf $1 # 0-7 } set-bg-color () { tput setab $1 # 0-7 } set-bold () { tput bold } reset-color() { tput sgr0 } effect-cols () { local colors=${1:-normal} sudo ~/cols/run $colors exec-cols # restart tty after } set-color () { local color_string=$1 local colors=(black red green yellow blue magenta cyan white) local color_index=${colors[(i)$color_string]} local tput_index=$(( $color_index - 1 )) set-fg-color $tput_index } echo-with-color () { local color_string=$1 shift set-color $color_string echo $@ reset-color } test-colors () { local color_number local color local bg_number local bg local color_names=(bl re gr ye bl ma cy wh) echo for color_number in {0..7}; do echo -n " $color_number " set-fg-color $color_number color=$color_names[(( $color_number + 1 ))] echo -n "$color "; tput bold; echo -n $color reset-color for bg_number in {0..7}; do bg=$color_names[(( $bg_number + 1 ))] echo -n " " set-fg-color $color_number set-bg-color $bg_number echo -n $bg tput bold echo -n " " set-fg-color $color_number set-bg-color $bg_number echo -n $bg reset-color done echo done echo } alias cols=test-colors print-label () { local bg=$1 local fg=$2 shift shift set-bg-color $bg set-fg-color $fg echo -n $@ reset-color }