Open bashbunni opened 2 months ago
Nice! This is a great UX improvement!
Totally, would almost call this a feature versus a fix. @bashbunni, can you add example Go code we can use to vet this?
@meowgorithm Just added some instructions. I mainly tested it with Gum.
seq 22 | go run . choose --selected=2,21 --limit=2
We should test with huh
the library itself as well. It looks like there's still a bug when navigating through groups with tab. Example here:
package main
import (
"fmt"
"os"
"github.com/charmbracelet/huh"
)
func main() {
f := huh.NewForm(
huh.NewGroup(
huh.NewSelect[string]().
Options(
huh.NewOption("A", "a"),
huh.NewOption("B", "b"),
huh.NewOption("C", "c"),
huh.NewOption("D", "d"),
huh.NewOption("E", "e"),
huh.NewOption("F", "f"),
huh.NewOption("G", "g"),
huh.NewOption("H", "h"),
huh.NewOption("I", "i"),
huh.NewOption("J", "j"),
huh.NewOption("K", "k").Selected(true),
huh.NewOption("L", "l"),
huh.NewOption("M", "m"),
huh.NewOption("N", "n"),
huh.NewOption("O", "o"),
huh.NewOption("P", "p"),
),
).WithHeight(8),
huh.NewGroup(
huh.NewMultiSelect[string]().
Options(
huh.NewOption("A", "a"),
huh.NewOption("B", "b"),
huh.NewOption("C", "c"),
huh.NewOption("D", "d"),
huh.NewOption("E", "e"),
huh.NewOption("F", "f"),
huh.NewOption("G", "g"),
huh.NewOption("H", "h"),
huh.NewOption("I", "i"),
huh.NewOption("K", "k").Selected(true),
huh.NewOption("L", "l"),
huh.NewOption("M", "m"),
huh.NewOption("N", "n"),
huh.NewOption("O", "o").Selected(true),
huh.NewOption("P", "p"),
),
).WithHeight(8),
)
if err := f.Run(); err != nil {
fmt.Fprintf(os.Stderr, "Oof: %v", err)
}
}
Going to test more edge cases before merging this one :)
Yeah, please do look at the example I posted above as well
You may also need to test with Dynamic Huh? That is, what happens when options are swapped out and some are selected.
The group-related issue is actually caused by a different bug I found and documented here. WithHeight
wasn't setting the viewport height and was instead just cutting content. That's why the calculations in this branch weren't working properly. Will continue trying to break it though :)
Maybe I'm doing something wrong, but I can't seem to get pre-selected options to work in dynamic huh. You can try for yourself by checking out the dynamic-selection-example
branch and running the dynamic/dynamic-selections
example.
https://github.com/charmbracelet/huh/blob/dynamic-selection-example/examples/dynamic/dynamic-selections/main.go
I created this example to test pre-selected elements in dynamic huh, but the cursor always starts at the top of the options anyway. Let me know if this is by design!
tested against gum @
main-huh
(basically just made it depend on this branch of huh)examples all work normally
you can test with Gum (after a lil go get -u github.com/charmbracelet/huh@refactor-select) then try seq 22 | go run . choose --selected=2,21 --limit=2 (or set limit to one or none for single select)