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

If WithFilter is enabled and you try to set a custom key MultiSelect immediately exits. #517

Closed
croyleje opened this issue May 30, 2023 · 3 comments · Fixed by #519
Closed
Labels
bug Something isn't working

Comments

@croyleje
Copy link

croyleje commented May 30, 2023

If you use the the multiselect example code and either enable filter or add a custom key to the example both run and immediately exit out with out allowing user input.

Example with filter enabled.

import (
	"fmt"

	"atomicgo.dev/keyboard/keys"
	"github.com/pterm/pterm"
)
func main() {
	var options []string

	for i := 0; i < 5; i++ {
		options = append(options, fmt.Sprintf("Option %d", i))
	}

	printer := pterm.DefaultInteractiveMultiselect.WithOptions(options)
	printer.Filter = true
	printer.KeyConfirm = keys.Enter
	printer.KeySelect = keys.Space
	selectedOptions, _ := printer.Show()
	pterm.Info.Printfln("Selected options: %s", pterm.Green(selectedOptions))
}

I can also confirm this behavior also occurs if you attempt to add a custom key via the KeySelect or KeyConfirm options to the example MultiSelect code that has filtering enabled by default also.

Jason C.

@croyleje croyleje added the bug Something isn't working label May 30, 2023
@croyleje
Copy link
Author

It appears the issue is with keys.Space if you use Tab or any other of the default keys assigned by keyboard/keys.go it seems to work.

@MarvinJWendt
Copy link
Member

Interesting, thanks for reporting! I'll take a look to fix this as soon as I can.

@MarvinJWendt MarvinJWendt added critical Critical issues and removed critical Critical issues labels May 31, 2023
@MarvinJWendt
Copy link
Member

MarvinJWendt commented Jun 3, 2023

Hi, I took a look at it. Seems like you're not handling returned errors.

If you modify your code to this:

selectedOptions, err := printer.Show()
pterm.Fatal.PrintOnError(err)

this error would occur:
image


This behavior is by design. When using the filter function, it is not advisable to combine it with the space character. The reason is that the filter considers any text input, including spaces, which creates ambiguity. If a user types a space, it becomes challenging to determine if they intend to include it as part of the filter or if they are trying to confirm or select something else.

I will update the docs to include this behavior.

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

Successfully merging a pull request may close this issue.

2 participants