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

Update InteractiveMultiselectPrinter to optionally show selected options #621

Open
prnvbn opened this issue Jan 22, 2024 · 4 comments · May be fixed by #625
Open

Update InteractiveMultiselectPrinter to optionally show selected options #621

prnvbn opened this issue Jan 22, 2024 · 4 comments · May be fixed by #625
Labels
proposal Proposal to add a new feature to pterm proposal-accepted Proposals which are accepted for implementation in the future

Comments

@prnvbn
Copy link

prnvbn commented Jan 22, 2024

When selecting multiple options, it will be useful for the end user of the terminal app to see the options that have been selected so far.

@prnvbn prnvbn added the proposal Proposal to add a new feature to pterm label Jan 22, 2024
@prnvbn prnvbn changed the title Update MultiSelectPrinter to optionally show selected options Update InteractiveMultiselectPrinter to optionally show selected options Jan 22, 2024
@MarvinJWendt MarvinJWendt added the proposal-accepted Proposals which are accepted for implementation in the future label Jan 23, 2024
@MarvinJWendt
Copy link
Member

I agree, that would be nice.

@prnvbn
Copy link
Author

prnvbn commented Jan 26, 2024

Great! I will send a PR across :)

@prnvbn
Copy link
Author

prnvbn commented Jan 26, 2024

PR ready for review - #625

@devnyxie
Copy link

devnyxie commented Mar 7, 2024

Hey! I'm new to pterm, but doesn't .DefaultOptions() do this?

*I may be confused, but I could not find a proper description of this option. If that's the case, I would like to help with this PR +-+

Let me show you my junior example of this implementation. Let's say we are building CLI in order to choose web components:

	componentNames := []string{}
	selectedComponentNames := []string{}
	
	for i := range components {
		name := components[i].Name
		selected := IsSelectedFunc(config, selectedPageName, name) //check if it's already selected
		if selected {
			selectedComponentNames = append(selectedComponentNames, name)
		}
		componentNames = append(componentNames, name)
	}
	
	printer := pterm.DefaultInteractiveMultiselect.
		WithOptions(componentNames).
		WithDefaultOptions(selectedComponentNames).
		WithFilter(false)
	selectedOptions, err := printer.Show()
	
	if err != nil {
		panic(err)
	}

	// Reset chosen components
	page := config.Pages[selectedPageName]
	page.Components = make(map[string]Component)
	config.Pages[selectedPageName] = page
	// Add selected components to the page
	for i := range selectedOptions {
		var selectedOption string = selectedOptions[i]
		addComponent(config, config.Pages[selectedPageName], selectedOption)
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Proposal to add a new feature to pterm proposal-accepted Proposals which are accepted for implementation in the future
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants