choose

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2023 License: MIT Imports: 6 Imported by: 16

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ThemeArrow = Theme{
	Direction: DirectionV,
	View: func(choices []string, cursor int) string {
		s := strings.Builder{}
		s.WriteString("\n")

		for i := 0; i < len(choices); i++ {
			if cursor == i {
				s.WriteString(constants.DefaultSelectedItemStyle.Render(fmt.Sprintf("❯ %s", choices[i])))
			} else {
				s.WriteString(constants.DefaultItemStyle.Render(fmt.Sprintf("  %s", choices[i])))
			}
			s.WriteString("\n")
		}

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

		for i := 0; i < len(choices); i++ {
			if cursor == i {
				s.WriteString(constants.DefaultSelectedItemStyle.Render(fmt.Sprintf("• %s", choices[i])))
			} else {
				s.WriteString(constants.DefaultItemStyle.Render(fmt.Sprintf("  %s", choices[i])))
			}
			s.WriteString("\n")
		}

		return s.String()
	},
}
View Source
var ThemeLine = Theme{
	Direction: DirectionH,
	View: func(choices []string, 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)
			} else {
				result[index] = constants.DefaultItemStyle.Render(choice)
			}
		}
		s.WriteString(strings.Join(result, " / "))
		s.WriteString("\n")

		return s.String()
	},
}

Functions

This section is empty.

Types

type Direction

type Direction int
const (
	DirectionAll Direction = iota
	DirectionH
	DirectionV
)

type Model

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

func New

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

func (Model) Data

func (m Model) Data() string

func (Model) DataString

func (m Model) DataString() string

func (Model) Error added in v0.8.0

func (m Model) Error() error

func (Model) Init

func (m Model) Init() tea.Cmd

func (Model) Quitting added in v0.8.0

func (m Model) Quitting() bool

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 WithHelp added in v0.8.0

func WithHelp(show bool) Option

func WithTheme

func WithTheme(theme Theme) Option

type Theme

type Theme struct {
	Direction Direction
	View      func([]string, int) string
}

Jump to

Keyboard shortcuts

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