From 6c44ccbbe2b20af6d7b63c230d75cab77859a9e0 Mon Sep 17 00:00:00 2001 From: Benjamin Lupton Date: Thu, 30 Jan 2025 23:05:17 +0800 Subject: [PATCH] choose, styles: fix terminal title and terminal resize not closing correctly /ref #261 #254 --- commands/choose | 30 +++++++++++++++--------------- config/styles.bash | 11 +++++++++-- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/commands/choose b/commands/choose index b09e412e0..b6772145a 100755 --- a/commands/choose +++ b/commands/choose @@ -987,7 +987,7 @@ function choose_() ( menu_body_rows=0 \ menu_body='' \ menu_mode='choose' \ - menu_resized_to='' \ + menu_resized_lines='' \ menu_skip_render='no' \ menu_status=0 \ menu_top_index_choose=0 \ @@ -1282,7 +1282,7 @@ function choose_() ( terminal_lines_prior="$terminal_lines" terminal_columns_prior="$terminal_columns" fi - if [[ -n $menu_resized_to && $menu_resized_to -gt $terminal_lines ]]; then + if [[ -n $menu_resized_lines && $menu_resized_lines -gt $terminal_lines ]]; then terminal_too_short='yes' else terminal_too_short='no' @@ -1724,10 +1724,10 @@ function choose_() ( fi menu_top_index="$menu_index" menu_bottom_index="$menu_index" - menu_resized_to='' + menu_resized_lines='' # debug function debug_menu { - debug "c=$menu_cursor" "mi=$menu_index" "ii=$item_index" "d=$menu_direction" "t=$menu_top_index" "b=$menu_bottom_index" "l=$menu_last" "u=$paging_used" "r=$menu_rows" "mr=$menu_resized_to" "tr=$terminal_lines" "tts=$terminal_too_short" + debug "c=$menu_cursor" "mi=$menu_index" "ii=$item_index" "d=$menu_direction" "t=$menu_top_index" "b=$menu_bottom_index" "l=$menu_last" "u=$paging_used" "r=$menu_rows" "mr=$menu_resized_lines" "tr=$terminal_lines" "tts=$terminal_too_short" } # e.g. go to second page, navigate half way, go page up for (( ; menu_index >= 0 && menu_index <= menu_last; menu_index += menu_direction)); do @@ -1808,7 +1808,7 @@ function choose_() ( if [[ $menu_rows -gt $terminal_lines ]]; then if [[ -z $items_bundled ]]; then # we need to resize the terminal - menu_resized_to="$menu_rows" + menu_resized_lines="$menu_rows" else # we already have content rendered, so exit with what we have break @@ -1824,7 +1824,7 @@ function choose_() ( items_bundled="$item_line$items_bundled" menu_top_index="$menu_index" fi - if [[ -n $menu_resized_to ]]; then + if [[ -n $menu_resized_lines ]]; then break fi done @@ -1901,8 +1901,8 @@ function choose_() ( fi # resize the terminal if it is too short? - if [[ -n $menu_resized_to ]]; then - terminal_title+="${style__terminal_resize}${menu_resized_to}${style__terminal_resize_end}" + if [[ -n $menu_resized_lines ]]; then + terminal_title+="${style__terminal_resize}${menu_resized_lines};${style__end__terminal_resize}" fi # calculate page top, middle, bottom @@ -2075,17 +2075,17 @@ function choose_() ( if [[ $title_supported == 'no' ]]; then terminal_title='' elif [[ $paging_used == 'yes' ]]; then - terminal_title+="${style__terminal_title}👉 ${verb} ${verb_total} of ${items_count} items 💁‍♀️ Viewing ${page_items_count} of ${items_count} items [$((menu_top_index + 1))…$((menu_cursor + 1))…$((menu_bottom_index + 1))] 👈${style__terminal_title_end}" + terminal_title+="${style__terminal_title}👉 ${verb} ${verb_total} of ${items_count} items 💁‍♀️ Viewing ${page_items_count} of ${items_count} items [$((menu_top_index + 1))…$((menu_cursor + 1))…$((menu_bottom_index + 1))] 👈${style__end__terminal_title}" else - terminal_title+="${style__terminal_title}👉 ${verb} ${verb_total} of ${items_count} items 👈${style__terminal_title_end}" + terminal_title+="${style__terminal_title}👉 ${verb} ${verb_total} of ${items_count} items 👈${style__end__terminal_title}" fi printf '%s' "${style__clear_screen}${style__hide_cursor}${terminal_title}${menu_title}${menu_body}${bar_top_content}${bar_middle_content}${items_bundled}${bar_bottom_content}${menu_legend_content}" >"$terminal_device_file" - if [[ -n $menu_resized_to ]]; then + if [[ -n $menu_resized_lines ]]; then refresh_terminal_size if [[ $terminal_too_short == 'yes' ]]; then - terminal_title="${style__terminal_title}‼️ TERMINAL TOO SHORT ‼️${style__terminal_title_end}" - local additional_rows="$((menu_resized_to - terminal_lines))" - printf '%s' "${style__clear_screen}${style__hide_cursor}${terminal_title}${style__error}You have been prompted to make a menu selection, however the terminal does not have enough vertical height to make that selection.${style__end__error}"$'\n'"${style__notice}Increase the terminal height or reduce font size to proceed, then press any key.${style__end__notice}"$'\n'"Terminal rows = ${terminal_lines}, Needed rows = ${menu_resized_to}, Additional rows = ${additional_rows}"$'\n' >"$terminal_device_file" + terminal_title="${style__terminal_title}‼️ TERMINAL TOO SHORT ‼️${style__end__terminal_title}" + local additional_rows="$((menu_resized_lines - terminal_lines))" + printf '%s' "${style__clear_screen}${style__hide_cursor}${terminal_title}${style__error}You have been prompted to make a menu selection, however the terminal does not have enough vertical height to make that selection.${style__end__error}"$'\n'"${style__notice}Increase the terminal height or reduce font size to proceed, then press any key.${style__end__notice}"$'\n'"Terminal rows = ${terminal_lines}, Needed rows = ${menu_resized_lines}, Additional rows = ${additional_rows}"$'\n' >"$terminal_device_file" fi fi } @@ -2144,7 +2144,7 @@ function choose_() ( printf '' >debug.txt fi message="$(printf '%q ' "$@" "c=${debug_counter}")" - printf '%s' "${style__terminal_title}${message}${style__terminal_title_end}" >"$terminal_device_file" + printf '%s' "${style__terminal_title}${message}${style__end__terminal_title}" >"$terminal_device_file" printf '%s\n' "$message" >>debug.txt debug_counter="$((debug_counter + 1))" } diff --git a/config/styles.bash b/config/styles.bash index 6b45d028c..7b6fd5b7c 100644 --- a/config/styles.bash +++ b/config/styles.bash @@ -57,10 +57,17 @@ style__backspace=$'\b' style__carriage_return=$'\r' style__escape=$'\e' style__home=$'\e[H' + +# terminal style__terminal_title=$'\e]0;' -style__terminal_title_end=$'\a' +style__end__terminal_title=$'\a' + +# echo-style --terminal-resize='100;80' # height and width +# echo-style --terminal-resize='100;' # width only +# echo-style --terminal-resize=';80' # width only style__terminal_resize=$'\e[8;' -style__terminal_resize_end=';t' +style__end__terminal_resize='t' + # modes style__color_end__intensity=$'\e[22m' #