Skip to content

Commit 6c44ccb

Browse files
committed
choose, styles: fix terminal title and terminal resize not closing correctly
/ref #261 #254
1 parent d565f72 commit 6c44ccb

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

commands/choose

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ function choose_() (
987987
menu_body_rows=0 \
988988
menu_body='' \
989989
menu_mode='choose' \
990-
menu_resized_to='' \
990+
menu_resized_lines='' \
991991
menu_skip_render='no' \
992992
menu_status=0 \
993993
menu_top_index_choose=0 \
@@ -1282,7 +1282,7 @@ function choose_() (
12821282
terminal_lines_prior="$terminal_lines"
12831283
terminal_columns_prior="$terminal_columns"
12841284
fi
1285-
if [[ -n $menu_resized_to && $menu_resized_to -gt $terminal_lines ]]; then
1285+
if [[ -n $menu_resized_lines && $menu_resized_lines -gt $terminal_lines ]]; then
12861286
terminal_too_short='yes'
12871287
else
12881288
terminal_too_short='no'
@@ -1724,10 +1724,10 @@ function choose_() (
17241724
fi
17251725
menu_top_index="$menu_index"
17261726
menu_bottom_index="$menu_index"
1727-
menu_resized_to=''
1727+
menu_resized_lines=''
17281728
# debug
17291729
function debug_menu {
1730-
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"
1730+
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"
17311731
}
17321732
# e.g. go to second page, navigate half way, go page up
17331733
for (( ; menu_index >= 0 && menu_index <= menu_last; menu_index += menu_direction)); do
@@ -1808,7 +1808,7 @@ function choose_() (
18081808
if [[ $menu_rows -gt $terminal_lines ]]; then
18091809
if [[ -z $items_bundled ]]; then
18101810
# we need to resize the terminal
1811-
menu_resized_to="$menu_rows"
1811+
menu_resized_lines="$menu_rows"
18121812
else
18131813
# we already have content rendered, so exit with what we have
18141814
break
@@ -1824,7 +1824,7 @@ function choose_() (
18241824
items_bundled="$item_line$items_bundled"
18251825
menu_top_index="$menu_index"
18261826
fi
1827-
if [[ -n $menu_resized_to ]]; then
1827+
if [[ -n $menu_resized_lines ]]; then
18281828
break
18291829
fi
18301830
done
@@ -1901,8 +1901,8 @@ function choose_() (
19011901
fi
19021902

19031903
# resize the terminal if it is too short?
1904-
if [[ -n $menu_resized_to ]]; then
1905-
terminal_title+="${style__terminal_resize}${menu_resized_to}${style__terminal_resize_end}"
1904+
if [[ -n $menu_resized_lines ]]; then
1905+
terminal_title+="${style__terminal_resize}${menu_resized_lines};${style__end__terminal_resize}"
19061906
fi
19071907

19081908
# calculate page top, middle, bottom
@@ -2075,17 +2075,17 @@ function choose_() (
20752075
if [[ $title_supported == 'no' ]]; then
20762076
terminal_title=''
20772077
elif [[ $paging_used == 'yes' ]]; then
2078-
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}"
2078+
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}"
20792079
else
2080-
terminal_title+="${style__terminal_title}👉 ${verb} ${verb_total} of ${items_count} items 👈${style__terminal_title_end}"
2080+
terminal_title+="${style__terminal_title}👉 ${verb} ${verb_total} of ${items_count} items 👈${style__end__terminal_title}"
20812081
fi
20822082
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"
2083-
if [[ -n $menu_resized_to ]]; then
2083+
if [[ -n $menu_resized_lines ]]; then
20842084
refresh_terminal_size
20852085
if [[ $terminal_too_short == 'yes' ]]; then
2086-
terminal_title="${style__terminal_title}‼️ TERMINAL TOO SHORT ‼️${style__terminal_title_end}"
2087-
local additional_rows="$((menu_resized_to - terminal_lines))"
2088-
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"
2086+
terminal_title="${style__terminal_title}‼️ TERMINAL TOO SHORT ‼️${style__end__terminal_title}"
2087+
local additional_rows="$((menu_resized_lines - terminal_lines))"
2088+
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"
20892089
fi
20902090
fi
20912091
}
@@ -2144,7 +2144,7 @@ function choose_() (
21442144
printf '' >debug.txt
21452145
fi
21462146
message="$(printf '%q ' "$@" "c=${debug_counter}")"
2147-
printf '%s' "${style__terminal_title}${message}${style__terminal_title_end}" >"$terminal_device_file"
2147+
printf '%s' "${style__terminal_title}${message}${style__end__terminal_title}" >"$terminal_device_file"
21482148
printf '%s\n' "$message" >>debug.txt
21492149
debug_counter="$((debug_counter + 1))"
21502150
}

config/styles.bash

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,17 @@ style__backspace=$'\b'
5757
style__carriage_return=$'\r'
5858
style__escape=$'\e'
5959
style__home=$'\e[H'
60+
61+
# terminal
6062
style__terminal_title=$'\e]0;'
61-
style__terminal_title_end=$'\a'
63+
style__end__terminal_title=$'\a'
64+
65+
# echo-style --terminal-resize='100;80' # height and width
66+
# echo-style --terminal-resize='100;' # width only
67+
# echo-style --terminal-resize=';80' # width only
6268
style__terminal_resize=$'\e[8;'
63-
style__terminal_resize_end=';t'
69+
style__end__terminal_resize='t'
70+
6471

6572
# modes
6673
style__color_end__intensity=$'\e[22m' #

0 commit comments

Comments
 (0)