From 619150cfe7c273bf35e8c53315fa4c2949bef435 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Wed, 23 Jul 2025 12:51:07 -0400 Subject: [PATCH] Starting point for the terminal applications. --- bin/color_picker.sh | 52 ++++++++++++++++++++++++++++++ bin/term_clock.sh | 5 +++ {bin => lib}/vulgar.sh | 73 ++++++++++++++++-------------------------- 3 files changed, 85 insertions(+), 45 deletions(-) create mode 100755 bin/color_picker.sh create mode 100755 bin/term_clock.sh rename {bin => lib}/vulgar.sh (80%) diff --git a/bin/color_picker.sh b/bin/color_picker.sh new file mode 100755 index 0000000..43810fb --- /dev/null +++ b/bin/color_picker.sh @@ -0,0 +1,52 @@ +. ~/cshenv/lib/vulgar.sh + +erase_block 11 1 15 32 + +create_button Red 12 2 Red 1 +highlight_button Red +#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 +#build_box 12 12 14 20 +#write_string "Green" 13 14 + +create_button Blue 12 24 Blue 4 +#build_box 12 24 14 31 +#write_string "Blue" 13 26 + +Buttons=("Red" "Green" "Blue") +Index=0 + +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}" == "Escape" ] + then + #erase_block 11 1 15 32 + break + fi +done diff --git a/bin/term_clock.sh b/bin/term_clock.sh new file mode 100755 index 0000000..c0698da --- /dev/null +++ b/bin/term_clock.sh @@ -0,0 +1,5 @@ +. ~/cshenv/lib/vulgar.sh + +get_terminal_size rows cols + +echo "Terminal is ${rows} rows and ${cols} cols" diff --git a/bin/vulgar.sh b/lib/vulgar.sh similarity index 80% rename from bin/vulgar.sh rename to lib/vulgar.sh index bba4d49..b49adb7 100755 --- a/bin/vulgar.sh +++ b/lib/vulgar.sh @@ -282,57 +282,40 @@ unhighlight_button() fi } - +get_terminal_size() +{ + send_csi_command t 18 + read_key _seq + # Consume ^[[8; -erase_block 11 1 15 32 + echo "Pre Array: ${_seq}" + _seq=(${_seq}) + echo "Array: ${_seq}" + _seq=(${_seq[@]:4}) + echo "Trimmed Array: ${_seq}" -create_button Red 12 2 Red 1 -highlight_button Red -#build_box 12 2 14 8 -#write_string "Red" 13 4 -#fill_block_attributes 12 2 14 8 41 + _rows=0 + while [ "${_seq[ 0 ]}" != ";" ] + do + _rchar="${_seq[ 0 ]}" + echo "RChar: ${_rchar}" + _seq=${_seq[@]:1} -create_button Green 12 12 Green 2 -#build_box 12 12 14 20 -#write_string "Green" 13 14 + #_rows=$(( ${_rows} * 16 + $( printf "\x${_rchar}" ) )) + done -create_button Blue 12 24 Blue 4 -#build_box 12 24 14 31 -#write_string "Blue" 13 26 -Buttons=("Red" "Green" "Blue") -Index=0 + _cols=0 + while [ "${_seq[ 0 ]}" != ";" ] + do + _cchar="${_seq[ 0 ]}" + _seq=${_seq[@]:1} -while true -do - read_key codes - sym=`translate_key ${codes}` + #_cols=$(( ${_cols} * 16 + $( printf "\x${_cchar}" ) )) + done - 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}" == "Escape" ] - then - #erase_block 11 1 15 32 - break - fi -done + eval $1=\"${_rows}\" + eval $2=\"${_cols}\" +}