Skip to content

Commit bfce25d

Browse files
authored
fix(prompt): support ESC to skip PR creation (#85)
fix(prompt): support ESC to skip PR creation in huh form huh v1.0.0's default `KeyMap.Quit` binding only includes `ctrl+c`; pressing ESC at the form level was silently ignored. Fix `InputWithSkip` to build the form manually with a custom keymap that adds `esc` alongside `ctrl+c` as quit keys, so both gestures trigger `huh.ErrUserAborted` and skip PR creation cleanly. Also corrects the fallout message from "(user pressed ESC)" to "(skipped)", which is accurate regardless of which key was used. `charmbracelet/bubbles` (already an indirect dep) is promoted to direct because we now import its `key` sub-package explicitly. Closes #78
1 parent d4fb1c8 commit bfce25d

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

cmd/submit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ func doSubmitPRs(g *git.Git, cfg *config.Config, root *tree.Node, branches []*tr
303303
prNum, adopted, err := createPRForBranch(g, ghClient, cfg, root, b.Name, parent, trunk, remoteBranches, s)
304304
switch {
305305
case errors.Is(err, ErrPRSkipped):
306-
fmt.Printf("Skipped PR for %s %s\n", s.Branch(b.Name), s.Muted("(user pressed ESC)"))
306+
fmt.Printf("Skipped PR for %s %s\n", s.Branch(b.Name), s.Muted("(skipped)"))
307307
case err != nil:
308308
fmt.Printf("%s failed to create PR for %s: %v\n", s.WarningIcon(), s.Branch(b.Name), err)
309309
case adopted:

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/boneskull/gh-stack
33
go 1.25.0
44

55
require (
6+
github.com/charmbracelet/bubbles v0.21.1-0.20250623103423-23b8fd6302d7
67
github.com/charmbracelet/huh v1.0.0
78
github.com/cli/go-gh/v2 v2.13.0
89
github.com/cli/safeexec v1.0.1
@@ -15,7 +16,6 @@ require (
1516
github.com/atotto/clipboard v0.1.4 // indirect
1617
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
1718
github.com/catppuccin/go v0.3.0 // indirect
18-
github.com/charmbracelet/bubbles v0.21.1-0.20250623103423-23b8fd6302d7 // indirect
1919
github.com/charmbracelet/bubbletea v1.3.6 // indirect
2020
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect
2121
github.com/charmbracelet/lipgloss v1.1.1-0.20250319133953-166f707985bc // indirect

internal/prompt/prompt.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os/exec"
99
"strings"
1010

11+
"github.com/charmbracelet/bubbles/key"
1112
"github.com/charmbracelet/huh"
1213
"github.com/cli/go-gh/v2/pkg/prompter"
1314
"github.com/cli/go-gh/v2/pkg/term"
@@ -51,11 +52,9 @@ func Input(prompt, defaultValue string) (string, error) {
5152
}
5253

5354
// InputWithSkip prompts the user for a single line of input with a default value,
54-
// allowing the user to skip by pressing ESC. Returns (value, skipped, error).
55+
// allowing the user to skip by pressing ESC or Ctrl+C. Returns (value, skipped, error).
5556
//
56-
// When the user presses ESC (or otherwise aborts via huh.ErrUserAborted),
57-
// skipped is true and err is nil. Ctrl+C will typically terminate the process
58-
// via SIGINT rather than returning here.
57+
// When the user presses ESC or Ctrl+C, skipped is true and err is nil.
5958
//
6059
// If not in an interactive terminal, the default is returned without prompting.
6160
func InputWithSkip(title, description, defaultValue string) (string, bool, error) {
@@ -65,14 +64,26 @@ func InputWithSkip(title, description, defaultValue string) (string, bool, error
6564

6665
value := defaultValue
6766

68-
err := huh.NewInput().
67+
// Build a keymap that treats both ctrl+c and esc as "quit/skip".
68+
// huh's default keymap only binds ctrl+c to Quit, leaving esc unhandled
69+
// at the form level, so ESC would otherwise do nothing.
70+
km := huh.NewDefaultKeyMap()
71+
km.Quit = key.NewBinding(
72+
key.WithKeys("ctrl+c", "esc"),
73+
key.WithHelp("esc/ctrl+c", "skip"),
74+
)
75+
76+
input := huh.NewInput().
6977
Title(title).
7078
Description(description).
71-
Value(&value).
79+
Value(&value)
80+
81+
err := huh.NewForm(huh.NewGroup(input)).
82+
WithShowHelp(false).
83+
WithKeyMap(km).
7284
Run()
7385

7486
if errors.Is(err, huh.ErrUserAborted) {
75-
// User pressed ESC to skip
7687
return "", true, nil
7788
}
7889
if err != nil {

0 commit comments

Comments
 (0)