Help us shape the future of Go! Take the 2026 Go Developer Survey

choose

package
v0.0.0-...-f98cc9a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultKeyMap = KeyMap{
		Help: key.NewBinding(
			key.WithKeys("?"),
			key.WithHelp("?", "toggle help"),
		),
		Confirm: key.NewBinding(
			key.WithKeys("enter"),
			key.WithHelp("enter", "confirm"),
		),
		Quit: key.NewBinding(
			key.WithKeys("q", "esc", "ctrl+c"),
			key.WithHelp("q", "quit"),
		),
		Prev: key.NewBinding(
			key.WithKeys("up", "k"),
			key.WithHelp("↑/k", "move up"),
		),
		Next: key.NewBinding(
			key.WithKeys("down", "j", "tab"),
			key.WithHelp("↓/j/tab", "move down"),
		),
	}

	HorizontalKeyMap = KeyMap{
		Help: key.NewBinding(
			key.WithKeys("?"),
			key.WithHelp("?", "toggle help"),
		),
		Confirm: key.NewBinding(
			key.WithKeys("enter"),
			key.WithHelp("enter", "confirm"),
		),
		Quit: key.NewBinding(
			key.WithKeys("q", "esc", "ctrl+c"),
			key.WithHelp("q", "quit"),
		),
		Prev: key.NewBinding(
			key.WithKeys("left", "h"),
			key.WithHelp("←/h", "move left"),
		),
		Next: key.NewBinding(
			key.WithKeys("right", "l", "tab", " "),
			key.WithHelp("→/l/tab/space", "move right"),
		),
	}
)
View Source
var ThemeArrow = func(choices []Choice, cursor int) string {
	s := strings.Builder{}
	s.WriteString("\n")

	maxLen := 0
	for _, choice := range choices {
		if maxLen < len([]rune(choice.Text)) {
			maxLen = len([]rune(choice.Text))
		}
	}

	for i := 0; i < len(choices); i++ {
		text := choices[i].Text
		note := choices[i].Note
		if note != "" {
			note = strings.Repeat(" ", maxLen-len([]rune(text))+2) + constants.DefaultNoteStyle.Render(note)
		}
		choice := text + note

		if cursor == i {
			s.WriteString(constants.DefaultSelectedItemStyle.Render(("❯ " + choice)))
		} else {
			s.WriteString(constants.DefaultItemStyle.Render("  " + choice))
		}
		s.WriteString("\n")
	}

	return s.String()
}
View Source
var ThemeDefault = func(choices []Choice, cursor int) string {
	s := strings.Builder{}
	s.WriteString("\n")

	maxLen := 0
	for _, choice := range choices {
		if maxLen < len([]rune(choice.Text)) {
			maxLen = len([]rune(choice.Text))
		}
	}

	for i := 0; i < len(choices); i++ {
		text := choices[i].Text
		note := choices[i].Note
		if note != "" {
			note = strings.Repeat(" ", maxLen-len([]rune(text))+2) + constants.DefaultNoteStyle.Render(note)
		}
		choice := text + note

		if cursor == i {
			s.WriteString(constants.DefaultSelectedItemStyle.Render("• " + choice))
		} else {
			s.WriteString(constants.DefaultItemStyle.Render("  " + choice))
		}
		s.WriteString("\n")
	}

	return s.String()
}
View Source
var ThemeLine = func(choices []Choice, cursor int) string {
	s := strings.Builder{}

	result := make([]string, len(choices))
	for index, choice := range choices {
		if index == cursor {
			result[index] = constants.DefaultSelectedItemStyle.Render(choice.Text)
		} else {
			result[index] = constants.DefaultItemStyle.Render(choice.Text)
		}
	}
	s.WriteString(strings.Join(result, " / "))
	s.WriteString("\n")

	return s.String()
}

Functions

This section is empty.

Types

type Choice

type Choice struct {
	Text string
	Note string
}

type KeyMap

type KeyMap struct {
	Prev    key.Binding
	Next    key.Binding
	Help    key.Binding
	Confirm key.Binding
	Quit    key.Binding
}

func (KeyMap) FullHelp

func (k KeyMap) FullHelp() [][]key.Binding

func (KeyMap) ShortHelp

func (k KeyMap) ShortHelp() []key.Binding

type Model

type Model struct {
	// contains filtered or unexported fields
}

func New

func New(choices []Choice, opts ...Option) *Model

func NewWithStrings

func NewWithStrings(choices []string, opts ...Option) *Model

func (Model) Data

func (m Model) Data() string

func (Model) DataString

func (m Model) DataString() string

func (Model) Error

func (m Model) Error() error

func (Model) Init

func (m Model) Init() tea.Cmd

func (Model) Quitting

func (m Model) Quitting() bool

func (Model) TeaProgramOpts

func (m Model) TeaProgramOpts() []tea.ProgramOption

func (Model) Update

func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (Model) View

func (m Model) View() string

type Option

type Option func(*Model)

func WithDefaultIndex

func WithDefaultIndex(index int) Option

func WithHelp

func WithHelp(show bool) Option

func WithKeyMap

func WithKeyMap(keyMap KeyMap) Option

func WithTeaProgramOpts

func WithTeaProgramOpts(opts ...tea.ProgramOption) Option

func WithTheme

func WithTheme(theme Theme) Option

type Theme

type Theme func([]Choice, int) string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL