Description
Maybe related to #748
When options are longer than the width (detected, or set with WithWidth), it looks like the per-option truncation is too long, causing each option to be more than one line high. Then given the detected height, it 'looks lke' the cursor is scrolling off screen, and the entire list is not viewable, because it is off screen.
I have a short(ish) example below (i've been trying to play with the width a bit):
// debug is a minimal program to reproduce and observe huh MultiSelect
// scroll/height behavior in isolation.
//
// Usage:
//
// go run ./cmd/debug # 20 options
// go run ./cmd/debug -n 50 # 50 options
package main
import (
"flag"
"fmt"
"os"
tea "charm.land/bubbletea/v2"
"charm.land/huh/v2"
"golang.org/x/term"
)
func main() {
n := flag.Int("n", 20, "number of options to generate")
flag.Parse()
width, _, err := term.GetSize(int(os.Stdout.Fd()))
if err != nil || width <= 0 {
width = 120
}
options := make([]huh.Option[int], *n)
selected := make([]int, *n)
for i := range *n {
options[i] = huh.NewOption(fmt.Sprintf("Option %d asdlfkj alskdjf asldkfj as;ldkfj als;dkfj asl;dkj as;ldkj as;ldkfjasl;dkfj d9vhe9ghc9sdhj", i+1), i+1).Selected(true)
selected[i] = i + 1
}
form := huh.NewForm(
huh.NewGroup(
huh.NewMultiSelect[int]().
Title(fmt.Sprintf("Select from %d options", *n)).
Description("Space to toggle, Enter to confirm, Ctrl+C to cancel.").
Options(options...).
Value(&selected),
),
).WithViewHook(func(v tea.View) tea.View {
v.AltScreen = true
return v
}).WithWidth(width - 8)
if err := form.Run(); err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
fmt.Printf("selected %d/%d options\n", len(selected), *n)
}
Initial intended fix would be to fix the per-option truncation so it doesn't mess with the view's line height. I'm rather new to this ecosystem so I'm not sure where the current truncation is happening.
Some things to think about adding as features might be truncation style (eg ...), and horizontal scroll (ala fzf)
Version
2.0.3
Environment
MacOS, ghostty
Description
Maybe related to #748
When options are longer than the width (detected, or set with WithWidth), it looks like the per-option truncation is too long, causing each option to be more than one line high. Then given the detected height, it 'looks lke' the cursor is scrolling off screen, and the entire list is not viewable, because it is off screen.
I have a short(ish) example below (i've been trying to play with the width a bit):
Initial intended fix would be to fix the per-option truncation so it doesn't mess with the view's line height. I'm rather new to this ecosystem so I'm not sure where the current truncation is happening.
Some things to think about adding as features might be truncation style (eg
...), and horizontal scroll (ala fzf)Version
2.0.3
Environment
MacOS, ghostty