Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions hdi
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
# hdi [mode] /path/to/file.md Parse a specific markdown file
#
# Interactive controls:
# ↑/↓ k/j Navigate commands
# Tab/S-Tab Jump between sections
# Enter Execute the highlighted command
# c Copy highlighted command to clipboard
# q / Esc Quit
# ↑/↓ k/j Navigate commands
# Tab/S-Tab Jump between sections
# Enter Execute the highlighted command
# c Copy highlighted command to clipboard
# q / Esc / ctrl+c Quit
#
# Aliases: "install" = "setup" = "i", "run" = "start" = "r", "test" = "t",
# "deploy" = "d", "check" = "c"
Expand Down Expand Up @@ -882,7 +882,7 @@ run_interactive() {
local cursor=0
local selected="${CMD_INDICES[$cursor]}"

# Save terminal state (global so cleanup trap can access after function returns)
# Save terminal state (global so cleanup trap can access after function returns)
SAVED_TTY=$(stty -g)

cleanup() {
Expand All @@ -893,7 +893,8 @@ run_interactive() {
printf '\033[%dA\033[J' "$PICKER_LINES"
fi
}
trap cleanup EXIT INT TERM

trap cleanup EXIT TERM

printf '%s' "$HIDE_CURSOR"
draw_picker "$selected"
Expand Down Expand Up @@ -937,6 +938,8 @@ run_interactive() {
KEY="enter"
elif [[ "$byte" == $'\t' ]]; then
KEY="tab"
elif [[ "$byte" == $'\x03' ]]; then
KEY="ctrl-c"
else
KEY="$byte"
fi
Expand Down Expand Up @@ -1011,10 +1014,13 @@ run_interactive() {
stty "$SAVED_TTY" 2>/dev/null

if [[ "$resume" == "q" ]]; then
echo ""
# Disable cleanup's clear since we're already clean
PICKER_LINES=0
return 0
elif [[ "$resume" == $'\x03' ]]; then
# Disable cleanup's clear since we're already clean
PICKER_LINES=0
exit 130
fi

printf '%s' "$HIDE_CURSOR"
Expand All @@ -1040,6 +1046,12 @@ run_interactive() {
PICKER_LINES=0
return
;;

ctrl-c)
clear_picker
PICKER_LINES=0
exit 130
;;
esac

draw_picker "$selected"
Expand Down
10 changes: 5 additions & 5 deletions src/header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
# hdi [mode] /path/to/file.md Parse a specific markdown file
#
# Interactive controls:
# ↑/↓ k/j Navigate commands
# Tab/S-Tab Jump between sections
# Enter Execute the highlighted command
# c Copy highlighted command to clipboard
# q / Esc Quit
# ↑/↓ k/j Navigate commands
# Tab/S-Tab Jump between sections
# Enter Execute the highlighted command
# c Copy highlighted command to clipboard
# q / Esc / ctrl+c Quit
#
# Aliases: "install" = "setup" = "i", "run" = "start" = "r", "test" = "t",
# "deploy" = "d", "check" = "c"
Expand Down
18 changes: 15 additions & 3 deletions src/picker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ run_interactive() {
local cursor=0
local selected="${CMD_INDICES[$cursor]}"

# Save terminal state (global so cleanup trap can access after function returns)
# Save terminal state (global so cleanup trap can access after function returns)
SAVED_TTY=$(stty -g)

cleanup() {
Expand All @@ -107,7 +107,8 @@ run_interactive() {
printf '\033[%dA\033[J' "$PICKER_LINES"
fi
}
trap cleanup EXIT INT TERM

trap cleanup EXIT TERM

printf '%s' "$HIDE_CURSOR"
draw_picker "$selected"
Expand Down Expand Up @@ -151,6 +152,8 @@ run_interactive() {
KEY="enter"
elif [[ "$byte" == $'\t' ]]; then
KEY="tab"
elif [[ "$byte" == $'\x03' ]]; then
KEY="ctrl-c"
else
KEY="$byte"
fi
Expand Down Expand Up @@ -225,10 +228,13 @@ run_interactive() {
stty "$SAVED_TTY" 2>/dev/null

if [[ "$resume" == "q" ]]; then
echo ""
# Disable cleanup's clear since we're already clean
PICKER_LINES=0
return 0
elif [[ "$resume" == $'\x03' ]]; then
# Disable cleanup's clear since we're already clean
PICKER_LINES=0
exit 130
fi

printf '%s' "$HIDE_CURSOR"
Expand All @@ -254,6 +260,12 @@ run_interactive() {
PICKER_LINES=0
return
;;

ctrl-c)
clear_picker
PICKER_LINES=0
exit 130
;;
esac

draw_picker "$selected"
Expand Down