huh icon indicating copy to clipboard operation
huh copied to clipboard

Shift tab back helper should be hidden if on first group

Open lucasoares opened this issue 2 years ago • 4 comments

Describe the bug The helper shift+tab back should be hidden on the first group of a form because there is no group to back to.

To Reproduce

Create a form with a single group and execute it.

Screenshots

image

lucasoares avatar Apr 19 '24 02:04 lucasoares

You're absolutely correct! Thank you so much for this issue!

maaslalani avatar Apr 25 '24 18:04 maaslalani

Hey! @lucasoares What version / commit of huh? are you on. I can't reproduce with a simple example. Can you share the code that you're using:

image

maaslalani avatar Apr 25 '24 18:04 maaslalani

	github.com/charmbracelet/bubbles v0.18.0
	github.com/charmbracelet/bubbletea v0.25.0
	github.com/charmbracelet/huh v0.3.0
	github.com/charmbracelet/huh/spinner v0.0.0-20240321161533-278656239a9d
	github.com/charmbracelet/lipgloss v0.10.0

lucasoares avatar Apr 25 '24 20:04 lucasoares

The first time I execute the form: image

Then if I move my selection the help text changes: image

Also, if I press tab in the first option, it confirms the selection, but only enter should do it.

If I press any key when I'm in the first option, the help text changes too, and tab key will not confirm anymore. The following example I executed the form, pressed x and then tried to press tab image

Code example:

// Helper functions to create form

func NewForm(groups ...*huh.Group) *huh.Form {
	return ConfigureForm(huh.NewForm(groups...))
}

func ConfigureForm(form *huh.Form) *huh,Form {
	keymaps := huh.NewDefaultKeyMap()
	keymaps.Quit = key.NewBinding(key.WithKeys("ctrl+c", "esc"))
	keymaps.Select.SetFilter = key.NewBinding(key.WithKeys("'"), key.WithHelp("'", "set filter"), key.WithDisabled())
	keymaps.Select.ClearFilter = key.NewBinding(key.WithKeys("'"), key.WithHelp("'", "clear filter"), key.WithDisabled())
	keymaps.MultiSelect.SetFilter = key.NewBinding(key.WithKeys("enter", "'"), key.WithHelp("'", "set filter"), key.WithDisabled())
	keymaps.MultiSelect.ClearFilter = key.NewBinding(key.WithKeys("'"), key.WithHelp("'", "clear filter"), key.WithDisabled())

	huhForm := form.WithKeyMap(keymaps)

	return form: huhForm
}

And using it:

	form := NewForm(
		huh.NewGroup(
			huh.NewSelect[string]().
				Title(title).
				Description(description).
				Options(menuOptions...).
				Value(&selected),
		),
	)


	err := form.Run()

This simple example with single item in a single group form will have these issues I mentioned.

lucasoares avatar May 09 '24 22:05 lucasoares

Hey, we fixed this on main! We will do a release soon!

The problem was setting the keymaps and that was fixed in https://github.com/charmbracelet/huh/commit/8c5d66193f2b83a5b6ff2443dec16964d7fe2bb7

maaslalani avatar May 25 '24 17:05 maaslalani