From f8cf23371d0bdf86a87b8c919bd7c6bbd83e2bbb Mon Sep 17 00:00:00 2001 From: Max Elkins Date: Tue, 24 Mar 2026 19:04:06 +0000 Subject: [PATCH 1/2] feat: add ctrl+c support to quit --- hdi | 20 ++++++++++++++++---- src/header.sh | 10 +++++----- src/picker.sh | 18 +++++++++++++++--- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/hdi b/hdi index 12d1e13..19a12b6 100755 --- a/hdi +++ b/hdi @@ -21,7 +21,7 @@ # Tab/S-Tab Jump between sections # Enter Execute the highlighted command # c Copy highlighted command to clipboard -# q / Esc Quit +# q / Esc / ctrl+c Quit # # Aliases: "install" = "setup" = "i", "run" = "start" = "r", "test" = "t", # "deploy" = "d", "check" = "c" @@ -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() { @@ -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" @@ -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 @@ -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" @@ -1040,6 +1046,12 @@ run_interactive() { PICKER_LINES=0 return ;; + + ctrl-c) + clear_picker + PICKER_LINES=0 + exit 130 + ;; esac draw_picker "$selected" diff --git a/src/header.sh b/src/header.sh index 94101b2..a4e6b79 100644 --- a/src/header.sh +++ b/src/header.sh @@ -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" diff --git a/src/picker.sh b/src/picker.sh index 327ae6a..43f1866 100644 --- a/src/picker.sh +++ b/src/picker.sh @@ -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() { @@ -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" @@ -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 @@ -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" @@ -254,6 +260,12 @@ run_interactive() { PICKER_LINES=0 return ;; + + ctrl-c) + clear_picker + PICKER_LINES=0 + exit 130 + ;; esac draw_picker "$selected" From a415e66b498601fd3bb26d3ee215393ac113da53 Mon Sep 17 00:00:00 2001 From: Max Elkins Date: Tue, 24 Mar 2026 19:10:13 +0000 Subject: [PATCH 2/2] fix: build --- hdi | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hdi b/hdi index 19a12b6..d3006f8 100755 --- a/hdi +++ b/hdi @@ -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 / ctrl+c 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"