Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Versions > v0.12.59: DefaultInteractiveSelect doesn't allow for exiting while in the middle of a selection #591

Closed
emmahsax opened this issue Dec 13, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@emmahsax
Copy link

On pterm version v0.12.66 and higher, using CTRL-C while in a selection using DefaultInteractiveSelect doesn't exit the program.

Code snippet below:

package main

import (
	"fmt"

	"github.com/pterm/pterm"
)


func main() {
	list := []string{"hello", "world", "example"}

	selectedItem, _ := pterm.DefaultInteractiveSelect.
		WithDefaultText("Select an item").
		WithMaxHeight(20).
		WithOptions(list).
		Show()

	fmt.Println("selected item:", selectedItem)
}

When using v0.12.59 or lower, this is the response (and this is what I'd expect):

$ go run main.go
Select an item [type to search]: 
> hello
  world
  example
exit status 1

When using v0.12.66 or higher (the versions that don't error*), this is the response:

$ go run main.go
Select an item [type to search]: 
> hello
  world
  example
selected item: hello

*Versions v0.12.60-v0.12.65 seem to error with the following message:

# github.com/pterm/pterm
../../../.asdf/installs/golang/1.21.0/packages/pkg/mod/github.com/pterm/pterm@v0.12.61/progressbar_printer.go:275:48: cannot use func() {…} (value of type func()) as func() bool value in argument to schedule.Every
@emmahsax emmahsax added the bug Something isn't working label Dec 13, 2023
@emmahsax emmahsax changed the title Versions > v0.12.59: DefaultInteractiveSelect` doesn't allow for exiting while in the middle of a selection Versions > v0.12.59: DefaultInteractiveSelect doesn't allow for exiting while in the middle of a selection Dec 13, 2023
@MarvinJWendt
Copy link
Member

Thanks for reporting the issue! I'll take a look.

@panbanda
Copy link
Contributor

@emmahsax It's because the new versions require you use WithOnInterruptFunc to handle graceful sigterms

#507

	selectedPod, err := pterm.DefaultInteractiveSelect.
		WithDefaultText("Select a pod").
		WithOptions([]string{"test", "what"}).
		WithOnInterruptFunc(func() {
			os.Exit(1)
		}).
		Show()

@MarvinJWendt should that be the default as to not break previous implementations?

@emmahsax
Copy link
Author

That was it. Thanks! Seems like more of a breaking change as it is, but... 🤷🏼‍♀️

@MarvinJWendt
Copy link
Member

MarvinJWendt commented Dec 15, 2023

should that be the default as to not break previous implementations?

Yep, I think by default it should exit the program. Do you want to make an issue for that, or should I @panbanda?

@emmahsax sorry for the inconvenience, I think I overlooked this change, even tho it was mentioned in the PR .-.

@panbanda
Copy link
Contributor

Created one with details from Emma.

#592

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants