bin/colors2.sh (view raw)
1#!/bin/bash
2
3useage() {
4 printf "\n\e[1;4mAscii Escape Code Helper Utility\e[m\n\n"
5 printf " \e[1mUseage:\e[m colors.sh [-|-b|-f|-bq|-fq|-?|?] [start] [end] [step]\n\n"
6 printf "The values for the first parameter may be one of the following:\n\n"
7 printf " \e[1m-\e[m Will result in the default output.\n"
8 printf " \e[1m-b\e[m This will display the 8 color version of this chart.\n"
9 printf " \e[1m-f\e[m This will display the 256 color version of this chart using foreground colors.\n"
10 printf " \e[1m-q\e[m This will display the 256 color version of this chart without the extra text.\n"
11 printf " \e[1m-bq\e[m This will display the 8 color version of this chart without the extra text.\n"
12 printf " \e[1m-fq\e[m This will display the 256 color version of this chart using foreground colors without the extra text.\n"
13 printf " \e[1m-?|?\e[m Displays this help screen.\n"
14 printf "\nThe remaining parameters are only used if the first parameter is one of: \e[1m-,-f,q,fq\e[m\n\n"
15 printf " \e[1mstart\e[m The color index to begin display at.\n"
16 printf " \e[1mend\e[m The color index to stop display at.\n"
17 printf " \e[1mstart\e[m The number of indexes to increment color by each iteration.\n\n\n"
18
19}
20verbose() {
21 if [[ "$1" != "-q" && "$1" != "-fq" && "$1" != "-bq" ]]; then
22 printf "\nTo control the display style use \e[1m%s\e[m where \e[1m%s\e[m is:\n" '\e[{$value}[:{$value}]m' '{$value}'
23 printf "\n 0 Normal \e[1m1 Bold\e[m \e[2m2 Dim\e[m \e[3m3 ???\e[m \e[4m4 Underlined\e[m \e[5m5 Blink\e[m \e[6m6 ???\e[m \e[7m7 Inverted\e[m \e[8m8 Hidden\e[m\n\n"
24 printf "If \e[1m%s\e[m is not provided it will reset the display.\n\n" '{$value}'
25 fi
26}
27eight_color() {
28 local fgc bgc vals seq0
29 if [ "$1" != "-bq" ]; then
30 printf "\n\e[1;4m8 Color Escape Value Pallette\e[m\n\n"
31 printf "Color escapes are \e[1m%s\e[m\n" '\e[${value};...;${value}m'
32 printf " Values \e[1m30..37\e[m are \e[1mforeground\e[m colors\n"
33 printf " Values \e[1m40..47\e[m are \e[1mbackground\e[m colors\n\n"
34 fi
35 for fgc in {30..37}; do
36 for bgc in {40..47}; do
37 fgc=${fgc#37}
38 bgc=${bgc#40}
39 vals="${fgc:+$fgc;}${bgc}"
40 vals=${vals%%;}
41 seq0="${vals:+\e[${vals}m}"
42 printf " %-9s" "${seq0:-(default)}"
43 printf " ${seq0}TEXT\e[m"
44 printf " \e[${vals:+${vals+$vals;}}1mBOLD\e[m"
45 done
46 printf "\e[0m\n"
47 done
48}
49
50
51if [[ "$1" == "-b" || "$1" == "-bq" ]]; then
52 eight_color "$1"
53 verbose "$1"
54elif [[ "$1" == "" || "$1" == "-" || "$1" == "-f" || "$1" == "-q" || "$1" == "-fq" ]]; then
55 start=${2:-0}
56 end=${3:-255}
57 step=${4:-1}
58 color=$start
59 style="48;5;"
60 if [[ "$1" == "-f" || "$1" == "-fq" ]]; then
61 style="38;5;"
62 fi
63 perLine=$(( ( $(tput cols) - 2 ) / 9 ));
64 if [[ "$1" != "-q" && "$1" != "-fq" ]]; then
65 printf "\n\e[1;4m256 Color Escape Value Pallette\e[0m\n\n"
66 printf " \e[1m%s\e[m for \e[1mbackground\e[m colors\n \e[1m%s\e[m for \e[1mforeground\e[m colors\n\n" '\e[48;5;${value}m' '\e[38;5;${value}m'
67 fi
68 while [ $color -le $end ]; do
69 printf "\e[m \e[${style}${color}m %3d \e[m " $color
70 ((color+=step))
71 if [ $(( ( ( $color - $start ) / $step ) % $perLine )) -eq 0 ]; then
72 printf "\n"
73 fi
74 done
75 printf "\e[m\n"
76 verbose "$1"
77else
78 useage
79fi