-
Notifications
You must be signed in to change notification settings - Fork 124
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
fix: set YOffset + cursor based on first selected item #331
base: main
Are you sure you want to change the base?
Conversation
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.
|
We should test with 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. |
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 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)