Skip to content

Commit 33282df

Browse files
authored
fix(overlay): arrow-key dialog, human-readable input, dynamic popup height (#18)
1 parent e028ce3 commit 33282df

4 files changed

Lines changed: 20 additions & 7 deletions

File tree

scripts/overlay-dialog.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ propose_rule() {
9595

9696
# ANSI helpers.
9797
BOLD='\033[1m'
98-
DIM='\033[2m'
98+
DIM='\033[34m'
9999
REVERSE='\033[7m'
100100
GREEN='\033[32m'
101101
RED='\033[31m'
@@ -229,7 +229,7 @@ render_main_menu() {
229229
printf " %s\n" "${MENU_LABELS[$i]}"
230230
fi
231231
done
232-
printf "\n${DIM}Use arrow keys or press a letter key${RESET}\n"
232+
printf "\n\033[2mUse arrow keys or press a letter key\033[0m\n"
233233
}
234234

235235
render_main_menu
@@ -322,7 +322,7 @@ render_confirm_menu() {
322322
printf " %s\n" "${CONFIRM_LABELS[$i]}"
323323
fi
324324
done
325-
printf "\n${DIM}Use arrow keys or press a letter key${RESET}\n"
325+
printf "\n\033[2mUse arrow keys or press a letter key\033[0m\n"
326326
}
327327

328328
render_confirm_menu

scripts/overlay.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,23 @@ _write_env_file() {
137137
}
138138
_write_env_file
139139

140+
# Compute popup height dynamically based on content.
141+
_term_cols="$(tput cols 2>/dev/null || echo 120)"
142+
_popup_cols=$(( _term_cols * 80 / 100 ))
143+
[ "$_popup_cols" -lt 40 ] && _popup_cols=40
144+
_input_str="${PASSTHRU_OVERLAY_TOOL_INPUT_JSON:-}"
145+
_input_len="${#_input_str}"
146+
if [ "$_input_len" -gt 120 ]; then _input_len=120; fi
147+
_input_lines=$(( (_input_len + 7) / (_popup_cols - 8) + 1 ))
148+
[ "$_input_lines" -lt 1 ] && _input_lines=1
149+
_popup_height=$(( 12 + _input_lines ))
150+
[ "$_popup_height" -lt 13 ] && _popup_height=13
151+
[ "$_popup_height" -gt 30 ] && _popup_height=30
152+
140153
launch_tmux() {
141154
# display-popup -E: close when the inner command exits.
142155
# -w 80% -h 60%: large enough for the menu + rule preview, still overlay-y.
143-
tmux display-popup -E -w 80% -h 60% -- \
156+
tmux display-popup -E -w 80% -h "$_popup_height" -- \
144157
bash -c ". '$_ENV_FILE' && rm -f '$_ENV_FILE' && exec bash '$DIALOG'"
145158
}
146159

tests/overlay.bats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ setup() {
3131
local cmd
3232
for cmd in jq perl bash cat sed awk printf tr sort uniq comm head tail \
3333
mkdir rm cp mv ln ls chmod date mktemp find grep wc tee touch \
34-
dirname basename realpath readlink env sha256sum shasum; do
34+
dirname basename realpath readlink env sha256sum shasum tput; do
3535
local src
3636
src="$(command -v "$cmd" 2>/dev/null || true)"
3737
if [ -n "$src" ] && [ -x "$src" ]; then
@@ -102,7 +102,7 @@ restricted_path() {
102102
grep -q 'display-popup' "$TMP/tmux.log"
103103
grep -q -- '-E' "$TMP/tmux.log"
104104
grep -q -- '-w 80%' "$TMP/tmux.log"
105-
grep -q -- '-h 60%' "$TMP/tmux.log"
105+
grep -qE -- '-h [0-9]+' "$TMP/tmux.log"
106106
# Dialog ran -> result file has the verdict.
107107
[ -f "$TMP/result.txt" ]
108108
run cat "$TMP/result.txt"

tests/overlay_config.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ setup() {
2727
local cmd
2828
for cmd in jq perl bash cat sed awk printf tr sort uniq comm head tail \
2929
mkdir rm cp mv ln ls chmod date mktemp find grep wc tee touch \
30-
dirname basename realpath readlink env sha256sum shasum; do
30+
dirname basename realpath readlink env sha256sum shasum tput; do
3131
local src
3232
src="$(command -v "$cmd" 2>/dev/null || true)"
3333
if [ -n "$src" ] && [ -x "$src" ]; then

0 commit comments

Comments
 (0)