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

@ -21,7 +21,8 @@ send_csi_command()
shift 1
echo -n "[${1}"
echo -n ""
echo -n "[${1}"
# First one no ';' prefix....
#echo -n "${1}"
@ -44,12 +45,22 @@ send_csi_command()
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()
{
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 ##############
@ -97,6 +108,7 @@ write_string()
_row=$1
shift 1
_col=$1
shift 1
while [ -n "$_str" ]
do
_ch=${_str:0:1}
@ -151,47 +163,40 @@ build_box()
read_key()
{
seq=""
read -sn 1 key
read -sN 1 key
code=`printf "%x" "'$key"`
seq=${code}
seq=K${code}
while read -t 0
do
read -sn 1 key
read -sN 1 key
code=`printf "%x" "'$key"`
seq="${seq} ${code}"
seq="${seq}${code}"
done
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()
{
_codes=${1}
case "${codes}" in
"1b 5b 41")
echo "Up"
;;
"1b 5b 42")
echo "Down"
;;
"1b 5b 44")
echo "Left"
;;
"1b 5b 43")
echo "Right"
;;
"1b")
echo "Escape"
;;
*)
echo "${codes}"
;;
esac
if [[ ! -v _keycodes[$1] ]];
then
echo "MISS ($1)" > /dev/fd/2
echo "$1"
else
_key="${_keycodes[${1}]}"
#echo "HIT (${_key})" > /dev/fd/2
echo ${_key}
fi
}
@ -322,3 +327,61 @@ get_terminal_size()
eval $1=\"${_rows}\"
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}\"
}