diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2017-02-15 10:34:20 +0000 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2017-02-15 10:34:20 +0000 |
commit | b9b7daf3b2196364afea8d04a0755ca0cc2ffa55 (patch) | |
tree | 2b063e6bd97bc4971a97f42cf3102a0ca027cdc0 | |
parent | 36734afdd8f0cf0daa664b8448728cdff0ca1550 (diff) | |
download | rtmux-b9b7daf3b2196364afea8d04a0755ca0cc2ffa55.tar.gz rtmux-b9b7daf3b2196364afea8d04a0755ca0cc2ffa55.tar.bz2 rtmux-b9b7daf3b2196364afea8d04a0755ca0cc2ffa55.zip |
Copy 24-bit-color.sh from iTerm2.
-rw-r--r-- | tools/24-bit-color.sh | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/tools/24-bit-color.sh b/tools/24-bit-color.sh new file mode 100644 index 00000000..81d7cd41 --- /dev/null +++ b/tools/24-bit-color.sh @@ -0,0 +1,113 @@ +#!/bin/bash +# +# This file echoes four gradients with 24-bit color codes +# to the terminal to demonstrate their 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 + +# +# From +# https://github.com/gnachman/iTerm2/blob/master/tests/24-bit-color.sh +# and presumably covered by +# https://github.com/gnachman/iTerm2/blob/master/LICENSE +# + +if which gseq >/dev/null +then + SEQ=gseq +else + SEQ=seq +fi +SEPARATOR=';' + +setBackgroundColor() +{ + echo -en "\033[48${SEPARATOR}2${SEPARATOR}$1${SEPARATOR}$2${SEPARATOR}$3""m" +} + +resetOutput() +{ + echo -en "\033[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 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 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 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 128`; do + setBackgroundColor `rainbowColor $i` + echo -n " " +done +resetOutput |