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

Select option with a custom key? (such as numbers) #511

Open
David-Lor opened this issue Jan 17, 2025 · 1 comment
Open

Select option with a custom key? (such as numbers) #511

David-Lor opened this issue Jan 17, 2025 · 1 comment

Comments

@David-Lor
Copy link

Hello there! I've been trying huh and looks pretty promising! I'm looking for a concrete feature and could not find it in many similar libraries (except tview but looks a bit complex for my usecase).

I want to create a Select, but with the possibility to choose an option with either the arrows + enter, or by pressing a number key. For example, given a Select with 5 options, being able to choose an option directly by pressing a number key (1,2,3,4,5,6,7,8,9). Is this possible with huh?

My current test code is:

package main

import (
	"fmt"
	"github.com/charmbracelet/huh"
)

func main() {
	if err := MenuMainHuh(); err != nil {
		fmt.Println("Error:", err)
		os.Exit(1)
	}
}

func MenuMainHuh() error {
	for {
		var selection string
		selectForm := huh.NewSelect[string]().
			Title("choose:").
			Options(
				huh.NewOption("OPT1", "opt1"),
				huh.NewOption("OPT2", "opt2")).
			Value(&selection)

		groupForm := huh.NewForm(huh.NewGroup(selectForm))
		if err := groupForm.Run(); err != nil {
			return err
		}
		fmt.Println("Chosen:", selection)
	}
}

Regards!

@jonas-grgt
Copy link

jonas-grgt commented Jan 18, 2025

Don't think this is a real issue but rather a question as such it would've been better to have posted this in the discussions forum.

That aside, you can search for a specific option using / or enable to by default using Filtering(true) on Select

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants