#!/usr/bin/env bash . ~/cshenv/lib/vulgar.sh echo '[?25l' echo '[?25h' echo '[?25l' erase_block 1 1 15 34 build_box 1 1 15 34 fill_block_attributes 1 1 15 34 47 30 write_string "Terminal Color Picker" 2 7 47 30 create_button Red 12 3 Red 1 #build_box 12 2 14 8 #write_string "Red" 13 4 #fill_block_attributes 12 2 14 8 41 create_button Green 12 13 Green 2 #build_box 12 12 14 20 #write_string "Green" 13 14 create_button Blue 12 25 Blue 4 #build_box 12 24 14 31 #write_string "Blue" 13 26 highlight_button Red # TODO: Add color picker # TODO: Negative colors support specials: # -1 is background # -2 is foreground # -3 is cursor color=12 write_string "Index:" 4 3 47 30 erase_block 4 10 4 12 color_padded=" ${color}" write_string "${color_padded:-3}" 4 10 write_string "Code:" 4 14 47 30 erase_block 4 20 4 25 get_color_hex ${color} red green blue write_string "${red}${green}${blue}" 4 20 build_box 6 9 9 25 fill_block_attributes 7 10 8 24 44 #erase_block 4 13 4 21 Controls=() Buttons=("Red" "Green" "Blue") Index=0 Colors=( $((0x${red})) $((0x${green})) $((0x${blue})) ) tmp=`stty -g` stty -echo update_color() { _color=${1} echo -n "]4;${_color};#$(hexbyte ${Colors[0]})$(hexbyte ${Colors[1]})$(hexbyte ${Colors[2]})" write_string "$(hexbyte ${Colors[0]})$(hexbyte ${Colors[1]})$(hexbyte ${Colors[2]})" 4 20 } while true do read_key codes sym=`translate_key ${codes}` OldIndex=${Index} if [ "${sym}" == "Right" ] then if (( ${Index} < $(( ${#Buttons} - 1 )) )) then Index=$(( ${Index} + 1 )) unhighlight_button ${Buttons[${OldIndex}]} highlight_button ${Buttons[${Index}]} fi elif [ "${sym}" == "Left" ] then if (( ${Index} > 0 )) then Index=$(( ${Index} - 1 )) unhighlight_button ${Buttons[${OldIndex}]} highlight_button ${Buttons[${Index}]} fi elif [ "${sym}" == "Up" ] then #echo "${Colors[${Index}]}:$(hexbyte ${Colors[${Index}]} )" if (( ${Colors[${Index}]} < 255 )) then Colors[${Index}]=$(( ${Colors[${Index}]} + 1 )) fi update_color ${color} elif [ "${sym}" == "Down" ] then #echo "${Colors[${Index}]}:$(hexbyte ${Colors[${Index}]} )" if (( ${Colors[${Index}]} > 0 )) then Colors[${Index}]=$(( ${Colors[${Index}]} - 1 )) fi update_color ${color} elif [ "${sym}" == "Escape" ] then break elif [ "${sym}" == "0" ] then Colors[${Index}]=0 update_color ${color} fi done stty ${tmp} #sleep 0.10 echo -n '[?25h'