Skip to content

Commit e8344e1

Browse files
committed
clear interactive selector on interrupt
1 parent d1acbf0 commit e8344e1

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

cmd/checkout.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ func handleCompositionConflict(
361361
selected, err := p.Select("How would you like to resolve this?", "", options)
362362
if err != nil {
363363
if isInterruptError(err) {
364+
clearSelectPrompt(cfg, len(options))
364365
printInterrupt(cfg)
365366
return nil, errInterrupt
366367
}
@@ -551,6 +552,7 @@ func interactiveStackPicker(cfg *config.Config, sf *stack.StackFile) (*stack.Sta
551552
)
552553
if err != nil {
553554
if isInterruptError(err) {
555+
clearSelectPrompt(cfg, len(options))
554556
printInterrupt(cfg)
555557
return nil, errInterrupt
556558
}

cmd/push.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ func pickRemote(cfg *config.Config, branch, remoteOverride string) (string, erro
145145
selected, promptErr := p.Select("Multiple remotes found. Which remote should be used?", "", multi.Remotes)
146146
if promptErr != nil {
147147
if isInterruptError(promptErr) {
148+
clearSelectPrompt(cfg, len(multi.Remotes))
148149
printInterrupt(cfg)
149150
return "", errInterrupt
150151
}

cmd/utils.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,23 @@ func printInterrupt(cfg *config.Config) {
6565
cfg.Infof("Received interrupt, aborting operation")
6666
}
6767

68+
// selectPromptPageSize matches the PageSize used by the go-gh prompter.
69+
const selectPromptPageSize = 20
70+
71+
// clearSelectPrompt erases the rendered Select prompt from the terminal.
72+
// survey/v2 does not call Cleanup on interrupt, leaving the question and
73+
// option lines visible. This function moves the cursor up past those lines
74+
// and clears to the end of the screen.
75+
func clearSelectPrompt(cfg *config.Config, numOptions int) {
76+
visible := numOptions
77+
if visible > selectPromptPageSize {
78+
visible = selectPromptPageSize
79+
}
80+
// 1 line for the question/filter + visible option lines
81+
lines := 1 + visible
82+
fmt.Fprintf(cfg.Err, "\033[%dA\033[J", lines)
83+
}
84+
6885
// loadStackResult holds everything returned by loadStack.
6986
type loadStackResult struct {
7087
GitDir string
@@ -186,6 +203,7 @@ func resolveStack(sf *stack.StackFile, branch string, cfg *config.Config) (*stac
186203
selected, err := p.Select("Which stack would you like to use?", "", options)
187204
if err != nil {
188205
if isInterruptError(err) {
206+
clearSelectPrompt(cfg, len(options))
189207
printInterrupt(cfg)
190208
return nil, errInterrupt
191209
}

0 commit comments

Comments
 (0)