Color picker proof of concept works.
This commit is contained in:
@ -1,25 +1,70 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
. ~/cshenv/lib/vulgar.sh
|
. ~/cshenv/lib/vulgar.sh
|
||||||
|
|
||||||
save_block 11 1 15 32
|
echo '[?25l'
|
||||||
erase_block 11 1 15 32
|
echo '[?25h'
|
||||||
|
echo '[?25l'
|
||||||
|
|
||||||
create_button Red 12 2 Red 1
|
erase_block 1 1 15 34
|
||||||
highlight_button Red
|
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
|
#build_box 12 2 14 8
|
||||||
#write_string "Red" 13 4
|
#write_string "Red" 13 4
|
||||||
#fill_block_attributes 12 2 14 8 41
|
#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
|
#build_box 12 12 14 20
|
||||||
#write_string "Green" 13 14
|
#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
|
#build_box 12 24 14 31
|
||||||
#write_string "Blue" 13 26
|
#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")
|
Buttons=("Red" "Green" "Blue")
|
||||||
Index=0
|
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
|
while true
|
||||||
do
|
do
|
||||||
read_key codes
|
read_key codes
|
||||||
@ -45,11 +90,32 @@ do
|
|||||||
unhighlight_button ${Buttons[${OldIndex}]}
|
unhighlight_button ${Buttons[${OldIndex}]}
|
||||||
highlight_button ${Buttons[${Index}]}
|
highlight_button ${Buttons[${Index}]}
|
||||||
fi
|
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" ]
|
elif [ "${sym}" == "Escape" ]
|
||||||
then
|
then
|
||||||
#erase_block 11 1 15 32
|
|
||||||
break
|
break
|
||||||
|
elif [ "${sym}" == "0" ]
|
||||||
|
then
|
||||||
|
Colors[${Index}]=0
|
||||||
|
update_color ${color}
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
restore_block 11 1 15 32
|
|
||||||
sleep 10
|
stty ${tmp}
|
||||||
|
#sleep 0.10
|
||||||
|
echo -n '[?25h'
|
||||||
|
127
lib/vulgar.sh
127
lib/vulgar.sh
@ -21,7 +21,8 @@ send_csi_command()
|
|||||||
shift 1
|
shift 1
|
||||||
|
|
||||||
|
|
||||||
echo -n "[${1}"
|
echo -n ""
|
||||||
|
echo -n "[${1}"
|
||||||
|
|
||||||
# First one no ';' prefix....
|
# First one no ';' prefix....
|
||||||
#echo -n "${1}"
|
#echo -n "${1}"
|
||||||
@ -44,12 +45,22 @@ send_csi_command()
|
|||||||
|
|
||||||
save_block()
|
save_block()
|
||||||
{
|
{
|
||||||
send_csi_command '$v' $* 1 $(( 25 + $1 )) $(( 25 + $2 )) $(( 25 + $3 )) $(( 25 + $4 )) 1
|
_T=$1
|
||||||
|
_L=$2
|
||||||
|
_B=$3
|
||||||
|
_R=$4
|
||||||
|
send_csi_command '$v' $_T $_L $_B $_R 1 1 140 1
|
||||||
}
|
}
|
||||||
|
|
||||||
restore_block()
|
restore_block()
|
||||||
{
|
{
|
||||||
send_csi_command '$v' $(( 25 + $1 )) $(( 25 + $2 )) $(( 25 + $3 )) $(( 25 + $4 )) 1 $* 1
|
_T=$1
|
||||||
|
_L=$2
|
||||||
|
_B=$3
|
||||||
|
_R=$4
|
||||||
|
_W=$(( ${_R} - ${_L} + 1 ))
|
||||||
|
_H=$(( ${_B} - ${_T} + 1 ))
|
||||||
|
send_csi_command '$v' 1 140 $_H $(( 140 + $_W - 1 )) 1 $_T $_L 1
|
||||||
}
|
}
|
||||||
|
|
||||||
##### END DECCRA Block ##############
|
##### END DECCRA Block ##############
|
||||||
@ -97,6 +108,7 @@ write_string()
|
|||||||
_row=$1
|
_row=$1
|
||||||
shift 1
|
shift 1
|
||||||
_col=$1
|
_col=$1
|
||||||
|
shift 1
|
||||||
while [ -n "$_str" ]
|
while [ -n "$_str" ]
|
||||||
do
|
do
|
||||||
_ch=${_str:0:1}
|
_ch=${_str:0:1}
|
||||||
@ -151,12 +163,12 @@ build_box()
|
|||||||
read_key()
|
read_key()
|
||||||
{
|
{
|
||||||
seq=""
|
seq=""
|
||||||
read -sn 1 key
|
read -sN 1 key
|
||||||
code=`printf "%x" "'$key"`
|
code=`printf "%x" "'$key"`
|
||||||
seq=${code}
|
seq=K${code}
|
||||||
while read -t 0
|
while read -t 0
|
||||||
do
|
do
|
||||||
read -sn 1 key
|
read -sN 1 key
|
||||||
code=`printf "%x" "'$key"`
|
code=`printf "%x" "'$key"`
|
||||||
seq="${seq}${code}"
|
seq="${seq}${code}"
|
||||||
done
|
done
|
||||||
@ -164,34 +176,27 @@ read_key()
|
|||||||
eval $1=\"${seq}\"
|
eval $1=\"${seq}\"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare -A _keycodes
|
||||||
|
_keycodes["K9"]="Tab"
|
||||||
|
_keycodes["K20"]="Space"
|
||||||
|
_keycodes["K1b"]="Escape"
|
||||||
|
_keycodes["K1b5b41"]="Up"
|
||||||
|
_keycodes["K1b5b42"]="Down"
|
||||||
|
_keycodes["K1b5b44"]="Left"
|
||||||
|
_keycodes["K1b5b43"]="Right"
|
||||||
|
_keycodes["K30"]="0"
|
||||||
|
|
||||||
translate_key()
|
translate_key()
|
||||||
{
|
{
|
||||||
_codes=${1}
|
if [[ ! -v _keycodes[$1] ]];
|
||||||
case "${codes}" in
|
then
|
||||||
"1b 5b 41")
|
echo "MISS ($1)" > /dev/fd/2
|
||||||
echo "Up"
|
echo "$1"
|
||||||
;;
|
else
|
||||||
|
_key="${_keycodes[${1}]}"
|
||||||
"1b 5b 42")
|
#echo "HIT (${_key})" > /dev/fd/2
|
||||||
echo "Down"
|
echo ${_key}
|
||||||
;;
|
fi
|
||||||
|
|
||||||
"1b 5b 44")
|
|
||||||
echo "Left"
|
|
||||||
;;
|
|
||||||
|
|
||||||
"1b 5b 43")
|
|
||||||
echo "Right"
|
|
||||||
;;
|
|
||||||
|
|
||||||
"1b")
|
|
||||||
echo "Escape"
|
|
||||||
;;
|
|
||||||
|
|
||||||
*)
|
|
||||||
echo "${codes}"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -322,3 +327,61 @@ get_terminal_size()
|
|||||||
eval $1=\"${_rows}\"
|
eval $1=\"${_rows}\"
|
||||||
eval $2=\"${_cols}\"
|
eval $2=\"${_cols}\"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#parse_color "${hex}" red green blue
|
||||||
|
|
||||||
|
declare -A _hexdigits
|
||||||
|
_hexdigits["0"]="0"
|
||||||
|
_hexdigits["1"]="1"
|
||||||
|
_hexdigits["2"]="2"
|
||||||
|
_hexdigits["3"]="3"
|
||||||
|
_hexdigits["4"]="4"
|
||||||
|
_hexdigits["5"]="5"
|
||||||
|
_hexdigits["6"]="6"
|
||||||
|
_hexdigits["7"]="7"
|
||||||
|
_hexdigits["8"]="8"
|
||||||
|
_hexdigits["9"]="9"
|
||||||
|
_hexdigits["10"]="a"
|
||||||
|
_hexdigits["11"]="b"
|
||||||
|
_hexdigits["12"]="c"
|
||||||
|
_hexdigits["13"]="d"
|
||||||
|
_hexdigits["14"]="e"
|
||||||
|
_hexdigits["15"]="f"
|
||||||
|
|
||||||
|
hexbyte()
|
||||||
|
{
|
||||||
|
echo -n "${_hexdigits[$((${1}/16))]}${_hexdigits[$((${1}%16))]}"
|
||||||
|
}
|
||||||
|
|
||||||
|
get_color_hex()
|
||||||
|
{
|
||||||
|
_color=$1
|
||||||
|
_tmp=`stty -g`
|
||||||
|
stty -echo
|
||||||
|
echo -n ']4;'"${_color}"';?'
|
||||||
|
read -sN 1 _ch # We know we'll get an Esc back, so drop it
|
||||||
|
read -sN 1 _ch
|
||||||
|
_hex=""
|
||||||
|
while [ "${_ch}" != '' ]
|
||||||
|
do
|
||||||
|
_hex="${_hex}${_ch}"
|
||||||
|
read -sN 1 _ch
|
||||||
|
done
|
||||||
|
stty ${_tmp}
|
||||||
|
|
||||||
|
#echo "Hex Pre: ${_hex}"
|
||||||
|
_hex=${_hex/]4;${_color};rgb:/}
|
||||||
|
#echo "Hex: ${_hex}"
|
||||||
|
_red=${_hex:0:2}
|
||||||
|
_green=${_hex:5:2}
|
||||||
|
_blue=${_hex:10:2}
|
||||||
|
|
||||||
|
#echo "R: ${_red}"
|
||||||
|
#echo "G: ${_green}"
|
||||||
|
#echo "B: ${_blue}"
|
||||||
|
|
||||||
|
eval $2=\"${_red}\"
|
||||||
|
eval $3=\"${_green}\"
|
||||||
|
eval $4=\"${_blue}\"
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user