|
7 | 7 | "strconv" |
8 | 8 | "strings" |
9 | 9 |
|
10 | | - "github.com/AlecAivazis/survey/v2/terminal" |
11 | | - "github.com/cli/go-gh/v2/pkg/prompter" |
| 10 | + "github.com/github/gh-stack/internal/prompter" |
12 | 11 | "github.com/github/gh-stack/internal/config" |
13 | 12 | "github.com/github/gh-stack/internal/git" |
14 | 13 | "github.com/github/gh-stack/internal/github" |
@@ -54,36 +53,18 @@ func (e *ExitError) Is(target error) bool { |
54 | 53 | // Callers should exit silently (the friendly message is already printed). |
55 | 54 | var errInterrupt = errors.New("interrupt") |
56 | 55 |
|
57 | | -// isInterruptError reports whether err is (or wraps) the survey interrupt, |
| 56 | +// isInterruptError reports whether err is (or wraps) the prompt interrupt, |
58 | 57 | // which is raised when the user presses Ctrl+C during a prompt. |
59 | 58 | func isInterruptError(err error) bool { |
60 | | - return errors.Is(err, terminal.InterruptErr) |
| 59 | + return errors.Is(err, prompter.ErrInterrupt) |
61 | 60 | } |
62 | 61 |
|
63 | 62 | // printInterrupt prints a friendly message and should be called exactly once |
64 | | -// per interrupted operation. The leading newline ensures the message starts |
65 | | -// on its own line even if the cursor was mid-prompt. |
| 63 | +// per interrupted operation. |
66 | 64 | func printInterrupt(cfg *config.Config) { |
67 | | - fmt.Fprintln(cfg.Err) |
68 | 65 | cfg.Infof("Received interrupt, aborting operation") |
69 | 66 | } |
70 | 67 |
|
71 | | -// selectPromptPageSize matches the PageSize used by the go-gh prompter. |
72 | | -const selectPromptPageSize = 20 |
73 | | - |
74 | | -// clearSelectPrompt erases the rendered Select prompt from the terminal. |
75 | | -// survey/v2 does not call Cleanup on interrupt, leaving the question and |
76 | | -// option lines visible. This function moves the cursor up past those lines |
77 | | -// and clears to the end of the screen. |
78 | | -func clearSelectPrompt(cfg *config.Config, numOptions int) { |
79 | | - visible := numOptions |
80 | | - if visible > selectPromptPageSize { |
81 | | - visible = selectPromptPageSize |
82 | | - } |
83 | | - // 1 line for the question/filter + visible option lines |
84 | | - lines := 1 + visible |
85 | | - fmt.Fprintf(cfg.Out, "\033[%dA\033[J", lines) |
86 | | -} |
87 | 68 |
|
88 | 69 | // loadStackResult holds everything returned by loadStack. |
89 | 70 | type loadStackResult struct { |
@@ -206,7 +187,6 @@ func resolveStack(sf *stack.StackFile, branch string, cfg *config.Config) (*stac |
206 | 187 | selected, err := p.Select("Which stack would you like to use?", "", options) |
207 | 188 | if err != nil { |
208 | 189 | if isInterruptError(err) { |
209 | | - clearSelectPrompt(cfg, len(options)) |
210 | 190 | printInterrupt(cfg) |
211 | 191 | return nil, errInterrupt |
212 | 192 | } |
|
0 commit comments