Color picker proof of concept works.

This commit is contained in:
2025-07-26 00:45:34 -04:00
parent 6f321dfdcf
commit 50d2b94ad0
2 changed files with 171 additions and 42 deletions

View File

@ -1,25 +1,70 @@
#!/usr/bin/env bash
. ~/cshenv/lib/vulgar.sh
save_block 11 1 15 32
erase_block 11 1 15 32
echo '[?25l'
echo '[?25h'
echo '[?25l'
create_button Red 12 2 Red 1
highlight_button Red
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 12 Green 2
create_button Green 12 13 Green 2
#build_box 12 12 14 20
#write_string "Green" 13 14
create_button Blue 12 24 Blue 4
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
@ -45,11 +90,32 @@ do
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
#erase_block 11 1 15 32
break
elif [ "${sym}" == "0" ]
then
Colors[${Index}]=0
update_color ${color}
fi
done
restore_block 11 1 15 32
sleep 10
stty ${tmp}
#sleep 0.10
echo -n '[?25h'