menu

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package menu provides a bubbletea model that makes it easy to expose forms and menus directly to CLI users.

Index

Constants

View Source
const (
	BlacklistIndicator = "BL"
	WhitelistIndicator = "WL"
)

these constants are used to indicate exception lists as blacklists or whitelists.

Variables

This section is empty.

Functions

func Black added in v1.1.0

func Black(list ...string) []string

Black accepts one or more strings and returns a slice of strings with an exception indicator for blacklisting appended to it.

It is a convenience wrapper used to define a blacklist to be passed to exception variadics in NewMenu functions. If the input list contains no elements, Black will panic, as the call is unnecessary.

func NewCursor

func NewCursor(context []menuField, index int) *cursor

NewCursor returns a new cursor instance. The cursor must be assigned to a non-nil context to persist. If the cursor could not be created, the pointer returned will be nil.

func White added in v1.1.0

func White(list ...string) []string

White accepts one or more strings and returns a slice of strings with an exception indicator for whitelisting appended to it.

It is a convenience wrapper used to define a whitelist to be passed to exception variadics in NewMenu functions. If the input list contains no elements, White will panic, as the call is unnecessary.

Types

type EndState

type EndState struct {
	QuitWithCancel bool // can be used to communicate whether changes ought be saved
}

type FieldKind

type FieldKind int
const (
	FieldString FieldKind = iota
	FieldBool
	FieldInt
)
type MenuOptions struct {
	NavCursorChar  string // cursor during navigation
	EditCursorChar string // cursor during edit
	IBeamChar      string // character shown right of text during edit
	TabAfterEntry  bool   // whether or not to jump to the next field after field value entry
	// contains filtered or unexported fields
}

func NewMenuOptions

func NewMenuOptions() *MenuOptions

NewMenuOptions returns a new Menu Options type, initialized with default values.

func (m MenuOptions) Defaults() MenuOptions

Defaults returns a copy of default MenuOption values.

func (m *MenuOptions) SetHeader(str string)

SetHeader sets the internal header to the value provided, trimming any leading or trailing whitespace.

type Model

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

Model is a menu that can be used to expose primitive struct fields to end users for input, as if they were elements of a menu.

func NewMenu

func NewMenu(structlyPtr any, exceptions ...string) (Model, error)

NewMenu attempts to validate the given interface object as a type compatible for rendering as a Structly menu, and, if successful, generates and returns a menu as a bubbletea model.

Interface 'i' MUST be a pointer to a struct that satisfies all requirements of a struct compatible with rendering as a Structly menu.

The optional 'exceptions' parameter may be provided one or more field names to blacklist from view within the resulting Menu instance. If used, the list's final element must match the value of either of the indicator constants used to define exception lists. The Black() and White() functions exist as convenience wrappers to provide this functionally.

func NewMenuWithOptions added in v1.1.0

func NewMenuWithOptions(structlyPtr any, options *MenuOptions, list ...string) (Model, error)

NewMenuWithOptions operates just as NewMenu does, but exposes a parameter for passing a list of options. Because a call of this function is necessarily deliberate, it will helpfully return an error if no options are passed in.

func (Model) Init

func (m Model) Init() tea.Cmd

func (Model) ParseStruct

func (m Model) ParseStruct(structlyPtr any) error

func (Model) Update

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

func (Model) View

func (m Model) View() string

Jump to

Keyboard shortcuts

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