Documentation ¶
Overview ¶
Package ui provides terminal widgets for git-spice.
Index ¶
- Variables
- func AcceptField() tea.Msg
- func ComparableOptions[T comparable](selected T, opts ...T) func(*Select[T])
- func NewStyle() lipgloss.Style
- func Run(f Field, opts ...RunOption) error
- func SkipField() tea.Msg
- func WithInput(r io.Reader) func(*runOptions)
- func WithOutput(w io.Writer) func(*runOptions)
- type Confirm
- func (c *Confirm) Description() string
- func (c *Confirm) Err() error
- func (c *Confirm) Init() tea.Cmd
- func (c *Confirm) Render(w Writer)
- func (c *Confirm) Title() string
- func (c *Confirm) Update(msg tea.Msg) tea.Cmd
- func (c *Confirm) Value() bool
- func (c *Confirm) WithDescription(desc string) *Confirm
- func (c *Confirm) WithDescriptionf(format string, args ...interface{}) *Confirm
- func (c *Confirm) WithTitle(title string) *Confirm
- func (c *Confirm) WithTitlef(format string, args ...interface{}) *Confirm
- func (c *Confirm) WithValue(value *bool) *Confirm
- type ConfirmKeyMap
- type ConfirmStyle
- type Deferred
- type Editor
- type Field
- type Form
- type FormKeyMap
- type FormStyle
- type Input
- func (i *Input) Description() string
- func (i *Input) Err() error
- func (i *Input) Init() tea.Cmd
- func (i *Input) Render(w Writer)
- func (i *Input) Title() string
- func (i *Input) Update(msg tea.Msg) tea.Cmd
- func (i *Input) WithDescription(desc string) *Input
- func (i *Input) WithTitle(title string) *Input
- func (i *Input) WithValidate(f func(string) error) *Input
- func (i *Input) WithValue(value *string) *Input
- type InputKeyMap
- type InputStyle
- type List
- func (l *List[T]) Description() string
- func (l *List[T]) Err() error
- func (l *List[T]) Init() tea.Cmd
- func (l *List[T]) Render(w Writer)
- func (l *List[T]) Title() string
- func (l *List[T]) Update(msg tea.Msg) tea.Cmd
- func (l *List[T]) Value() *T
- func (l *List[T]) With(f func(l *List[T])) *List[T]
- func (l *List[T]) WithDescription(desc string) *List[T]
- func (l *List[T]) WithItems(items ...ListItem[T]) *List[T]
- func (l *List[T]) WithSelected(selected int) *List[T]
- func (l *List[T]) WithTitle(title string) *List[T]
- func (l *List[T]) WithValue(value *T) *List[T]
- type ListItem
- type ListKeyMap
- type ListStyle
- type MultiSelect
- func (s *MultiSelect[T]) Description() string
- func (s *MultiSelect[T]) Err() error
- func (s *MultiSelect[T]) Init() tea.Cmd
- func (s *MultiSelect[T]) Render(w Writer)
- func (s *MultiSelect[T]) Selected() []int
- func (s *MultiSelect[T]) Title() string
- func (s *MultiSelect[T]) Update(msg tea.Msg) tea.Cmd
- func (s *MultiSelect[T]) Value() []T
- func (s *MultiSelect[T]) WithDescription(desc string) *MultiSelect[T]
- func (s *MultiSelect[T]) WithOptions(opts ...MultiSelectOption[T]) *MultiSelect[T]
- func (s *MultiSelect[T]) WithTitle(title string) *MultiSelect[T]
- type MultiSelectKeyMap
- type MultiSelectOption
- type MultiSelectStyle
- type OpenEditor
- func (a *OpenEditor) Description() string
- func (a *OpenEditor) Err() error
- func (a *OpenEditor) Init() tea.Cmd
- func (a *OpenEditor) Render(w Writer)
- func (a *OpenEditor) Title() string
- func (a *OpenEditor) Update(msg tea.Msg) tea.Cmd
- func (a *OpenEditor) WithDescription(desc string) *OpenEditor
- func (a *OpenEditor) WithTitle(title string) *OpenEditor
- func (a *OpenEditor) WithValue(value *string) *OpenEditor
- type OpenEditorKeyMap
- type OpenEditorStyle
- type RunOption
- type Select
- func (s *Select[T]) Description() string
- func (s *Select[T]) Err() error
- func (s *Select[T]) Init() tea.Cmd
- func (s *Select[T]) Render(out Writer)
- func (s *Select[T]) Title() string
- func (s *Select[T]) Update(msg tea.Msg) tea.Cmd
- func (s *Select[T]) Value() T
- func (s *Select[T]) With(f func(*Select[T])) *Select[T]
- func (s *Select[T]) WithDescription(desc string) *Select[T]
- func (s *Select[T]) WithOptions(opts ...SelectOption[T]) *Select[T]
- func (s *Select[T]) WithSelected(selected int) *Select[T]
- func (s *Select[T]) WithTitle(title string) *Select[T]
- func (s *Select[T]) WithValue(value *T) *Select[T]
- func (s *Select[T]) WithVisible(visible int) *Select[T]
- type SelectKeyMap
- type SelectOption
- type SelectStyle
- type Writer
Constants ¶
This section is empty.
Variables ¶
var ( Yellow = lipgloss.AdaptiveColor{Light: "2", Dark: "11"} Red = lipgloss.AdaptiveColor{Light: "1", Dark: "9"} Green = lipgloss.AdaptiveColor{Light: "2", Dark: "10"} Plain = lipgloss.AdaptiveColor{Light: "0", Dark: "7"} Cyan = lipgloss.AdaptiveColor{Light: "6", Dark: "14"} Magenta = lipgloss.AdaptiveColor{Light: "5", Dark: "13"} Gray = lipgloss.AdaptiveColor{Light: "8", Dark: "8"} )
This file defines the common defaults and styles for the UI components.
var DefaultConfirmKeyMap = ConfirmKeyMap{ Yes: key.NewBinding( key.WithKeys("y", "Y"), key.WithHelp("y", "yes"), ), No: key.NewBinding( key.WithKeys("n", "N"), key.WithHelp("n", "no"), ), Accept: key.NewBinding( key.WithKeys("enter", "tab"), key.WithHelp("enter/tab", "accept"), ), }
DefaultConfirmKeyMap is the default key map for a Confirm field.
var DefaultConfirmStyle = ConfirmStyle{ Key: NewStyle().Foreground(Magenta), }
DefaultConfirmStyle is the default style for a Confirm field.
var DefaultFormKeyMap = FormKeyMap{ Cancel: key.NewBinding( key.WithKeys("ctrl+c"), key.WithHelp("ctrl+c", "cancel"), ), }
DefaultFormKeyMap is the default key map for a Form.
var DefaultFormStyle = FormStyle{ Error: NewStyle().Foreground(Red), Title: _titleStyle, Description: _descriptionStyle, AcceptedTitle: _acceptedTitleStyle, AcceptedField: NewStyle().Faint(true), }
DefaultFormStyle is the default style for a Form.
var DefaultInputKeyMap = InputKeyMap{ Accept: key.NewBinding( key.WithKeys("enter", "tab"), key.WithHelp("enter/tab", "accept"), ), }
DefaultInputKeyMap is the default key map for an input field.
var DefaultInputStyle = InputStyle{}
DefaultInputStyle is the default style for an input field.
var DefaultListKeyMap = ListKeyMap{ Up: key.NewBinding( key.WithKeys("up", "k"), key.WithHelp("up/k", "go up"), ), Down: key.NewBinding( key.WithKeys("down", "j"), key.WithHelp("down/j", "go down"), ), Accept: key.NewBinding( key.WithKeys("enter", "tab"), key.WithHelp("enter/tab", "accept"), ), }
DefaultListKeyMap specifies the default key bindings for List.
var DefaultListStyle = ListStyle{ Cursor: NewStyle().Foreground(Yellow).Bold(true).SetString("▶"), ItemTitle: NewStyle().Foreground(Gray), SelectedItemTitle: NewStyle().Foreground(Yellow), }
DefaultListStyle is the default style for a List.
var DefaultMultiSelectKeyMap = MultiSelectKeyMap{ Up: key.NewBinding( key.WithKeys("up", "k"), key.WithHelp("up/k", "move up"), ), Down: key.NewBinding( key.WithKeys("down", "j"), key.WithHelp("down/j", "move down"), ), Toggle: key.NewBinding( key.WithKeys(" ", "right"), key.WithHelp("space", "toggle split"), ), Accept: key.NewBinding( key.WithKeys("enter", "tab"), key.WithHelp("enter/tab", "accept"), ), }
DefaultMultiSelectKeyMap is the default key map for a MultiSelect.
var DefaultMultiSelectStyle = MultiSelectStyle{ Cursor: NewStyle().Foreground(Yellow).Bold(true).SetString("▶"), Done: NewStyle().Foreground(Green).SetString("Done"), ScrollUp: NewStyle().Foreground(Gray).SetString("▲▲▲"), ScrollDown: NewStyle().Foreground(Gray).SetString("▼▼▼"), }
DefaultMultiSelectStyle is the default style for a MultiSelect.
var DefaultOpenEditorKeyMap = OpenEditorKeyMap{ Edit: key.NewBinding( key.WithKeys("e"), key.WithHelp("e", "open editor"), ), Accept: key.NewBinding( key.WithKeys("enter", "tab"), key.WithHelp("enter/tab", "accept"), ), }
DefaultOpenEditorKeyMap is the default key map for an OpenEditor field.
var DefaultOpenEditorStyle = OpenEditorStyle{ Key: NewStyle().Foreground(Magenta), Editor: NewStyle().Foreground(Green), NoEditorMessage: "please set an editor", }
DefaultOpenEditorStyle is the default style for an OpenEditor field.
var DefaultSelectKeyMap = SelectKeyMap{ Up: key.NewBinding( key.WithKeys("up"), key.WithHelp("up", "go up"), ), Down: key.NewBinding( key.WithKeys("down"), key.WithHelp("down", "go down"), ), Accept: key.NewBinding( key.WithKeys("enter", "tab"), key.WithHelp("enter/tab", "accept"), ), DeleteFilterChar: key.NewBinding( key.WithKeys("backspace", "ctrl+h"), key.WithHelp("backspace", "delete filter character"), ), }
DefaultSelectKeyMap is the default key map for a Select.
var DefaultSelectStyle = SelectStyle{ Selected: NewStyle().Foreground(Yellow), Highlight: NewStyle().Foreground(Cyan), ScrollMarker: NewStyle().Foreground(Gray), }
DefaultSelectStyle is the default style for a Select.
var Renderer = lipgloss.NewRenderer(os.Stderr)
Renderer is a lipgloss renderer that writes to stderr.
We print prompts to stderr, so that's what we should use to check for colorization of lipgloss.
Functions ¶
func AcceptField ¶
AcceptField is a tea.Cmd to accept the currently focused field.
It should be returned by a field's [Update] method to accept the field and move to the next one.
func ComparableOptions ¶
func ComparableOptions[T comparable](selected T, opts ...T) func(*Select[T])
ComparableOptions creates a list of options from a list of comparable values and sets the selected option.
The defeault string representation of the value is used as the label.
func Run ¶
Run presents a single field to the user and blocks until it's accepted or canceled.
This is a convenience function for forms with just one field.
func WithOutput ¶
WithOutput sets the output stream for the form.
Types ¶
type Confirm ¶
type Confirm struct { KeyMap ConfirmKeyMap Style ConfirmStyle // contains filtered or unexported fields }
Confirm is a boolean confirmation field that takes a yes or no answer.
func NewConfirm ¶
func NewConfirm() *Confirm
NewConfirm builds a new confirm field that prompts the user with a yes or no question.
func (*Confirm) Description ¶
Description returns the description for the confirm field.
func (*Confirm) WithDescription ¶
WithDescription sets the desc for the confirm field.
func (*Confirm) WithDescriptionf ¶
WithDescriptionf is a variant of WithDescription that accepts a format string.
func (*Confirm) WithTitlef ¶
WithTitlef is a variant of WithTitle that accepts a format string.
type ConfirmKeyMap ¶
ConfirmKeyMap defines the key bindings for Confirm.
type ConfirmStyle ¶
ConfirmStyle configures the appearance of a Confirm field.
type Deferred ¶
type Deferred struct {
// contains filtered or unexported fields
}
Deferred is a field that is not constructed until initialization time.
This is useful for fields that depend on other fields.
func Defer ¶
Defer defers field construction using the given function. If the function returns nil, the field will be ignored.
func (*Deferred) Description ¶
Description returns the description of the deferred field.
type Editor ¶
type Editor struct { // Command is the editor command to run. // // This may be a shell command like: // // FOO=bar gvim --nofork // // or a binary name like: // // nvim // // For the former case, we'll use 'sh -c' to run the command. Command string // Ext is the extension to assign to the file // before opening the editor. // // Defaults to "md". Ext string }
Editor configures the editor to open.
func DefaultEditor ¶
func DefaultEditor() Editor
DefaultEditor returns the default editor configuration.
type Field ¶
type Field interface { // Init initializes the field. // This is called right before the field is first rendered, // not when the form is initialized. Init() tea.Cmd Update(msg tea.Msg) tea.Cmd Render(Writer) // Err reports any errors for the field at render time. // These will be rendered in red below the field. // // It is the field's responsibility to ensure // that it does not post [AcceptField] while in an error state. Err() error // Title is a short title for the field. // This is always visible. Title() string // Description is a longer description of the field. // This is visible only while the field is focused. Description() string }
Field is a single field in a form.
type Form ¶
type Form struct { KeyMap FormKeyMap Style FormStyle // contains filtered or unexported fields }
Form presents a series of fields for the user to fill.
func (*Form) Err ¶
Err reports any errors that occurred during the form's execution or from any of the fields.
func (*Form) Run ¶
Run runs the form and blocks until it's accepted or canceled. It returns a combination of all errors returned by the fields.
type FormKeyMap ¶
FormKeyMap defines the key bindings for a form. See DefaultFormKeyMap for default values.
type FormStyle ¶
type FormStyle struct { Error lipgloss.Style Title lipgloss.Style Description lipgloss.Style AcceptedTitle lipgloss.Style AcceptedField lipgloss.Style }
FormStyle configures the appearance of a Form.
type Input ¶
type Input struct { KeyMap InputKeyMap Style InputStyle // contains filtered or unexported fields }
Input is a text input field. It accepts a single line of text.
func (*Input) Description ¶
Description returns the description of the input field.
func (*Input) Err ¶
Err reports any errors encountered during the operation. The error is nil if the input was accepted.
func (*Input) WithDescription ¶
WithDescription sets the description of the input field.
func (*Input) WithValidate ¶
WithValidate sets a validation function for the input field.
The field will not accept the input until the validation function returns nil.
type InputKeyMap ¶
InputKeyMap defines the key bindings for an input field.
type List ¶
type List[T any] struct { KeyMap ListKeyMap Style ListStyle // contains filtered or unexported fields }
List is a prompt that allows selecting from a list of options. This is similar to Select but without the fuzzy filter. Each item in a List can have a title, description, and a value.
func (*List[T]) Description ¶
Description retrieves the description of the List.
func (*List[T]) Update ¶
Update receives a message from bubbletea and updates the internal state of the list.
func (*List[T]) WithDescription ¶
WithDescription sets the description of the List.
func (*List[T]) WithItems ¶
WithItems fills the list with items. By default the first of these items will be selected.
func (*List[T]) WithSelected ¶
WithSelected sets the index of the selected item.
type ListKeyMap ¶
ListKeyMap defines key bindings for List.
type ListStyle ¶
type ListStyle struct { Cursor lipgloss.Style ItemTitle lipgloss.Style SelectedItemTitle lipgloss.Style }
ListStyle defines the styles for List.
type MultiSelect ¶
type MultiSelect[T any] struct { KeyMap MultiSelectKeyMap Style MultiSelectStyle // contains filtered or unexported fields }
MultiSelect is a prompt that allows selecting one or more options.
func NewMultiSelect ¶
func NewMultiSelect[T any](render func(Writer, int, MultiSelectOption[T])) *MultiSelect[T]
NewMultiSelect constructs a new multi-select field.
func (*MultiSelect[T]) Description ¶
func (s *MultiSelect[T]) Description() string
Description returns the description of the multi-select field.
func (*MultiSelect[T]) Init ¶
func (s *MultiSelect[T]) Init() tea.Cmd
Init initializes the multi-select field.
func (*MultiSelect[T]) Render ¶
func (s *MultiSelect[T]) Render(w Writer)
Render renders the multi-select field.
func (*MultiSelect[T]) Selected ¶
func (s *MultiSelect[T]) Selected() []int
Selected returns the indexes of the selected options.
func (*MultiSelect[T]) Title ¶
func (s *MultiSelect[T]) Title() string
Title returns the title of the multi-select field.
func (*MultiSelect[T]) Update ¶
func (s *MultiSelect[T]) Update(msg tea.Msg) tea.Cmd
Update updates the multi-select field.
func (*MultiSelect[T]) Value ¶
func (s *MultiSelect[T]) Value() []T
Value returns a slice of the selected values.
func (*MultiSelect[T]) WithDescription ¶
func (s *MultiSelect[T]) WithDescription(desc string) *MultiSelect[T]
WithDescription sets the description of the multi-select field.
func (*MultiSelect[T]) WithOptions ¶
func (s *MultiSelect[T]) WithOptions(opts ...MultiSelectOption[T]) *MultiSelect[T]
WithOptions sets the options for the multi-select field. Options will be presented in the order they are provided. The existing options, if any, will be replaced.
func (*MultiSelect[T]) WithTitle ¶
func (s *MultiSelect[T]) WithTitle(title string) *MultiSelect[T]
WithTitle sets the title of the multi-select field.
type MultiSelectKeyMap ¶
MultiSelectKeyMap defines the key bindings for MultiSelect.
type MultiSelectOption ¶
type MultiSelectOption[T any] struct { // Value of the option. Value T // Selected indicates whether the option is already selected. Selected bool // Skip indicates whether the option should be skipped. // Skipped options are not selectable // and will never be included in the result. Skip bool }
MultiSelectOption is an option for a multi-select field.
type MultiSelectStyle ¶
type MultiSelectStyle struct { // Cursor is the string to use for the cursor. Cursor lipgloss.Style // Done is the string for the Done button. Done lipgloss.Style // ScrollUp is the string for the scroll up marker. ScrollUp lipgloss.Style // ScrollDown is the string for the scroll down marker. ScrollDown lipgloss.Style }
MultiSelectStyle defines the styles for MultiSelect.
type OpenEditor ¶
type OpenEditor struct { KeyMap OpenEditorKeyMap Style OpenEditorStyle Editor Editor // contains filtered or unexported fields }
OpenEditor is a dialog that asks the user to press a key to open an editor and write a message.
func NewOpenEditor ¶
func NewOpenEditor(editor Editor) *OpenEditor
NewOpenEditor builds an OpenEditor field. It will prompt the user to open an editor and write a message, or accept the current value.
func (*OpenEditor) Description ¶
func (a *OpenEditor) Description() string
Description returns the description for the field.
func (*OpenEditor) Err ¶
func (a *OpenEditor) Err() error
Err reports any errors encountered during the operation.
func (*OpenEditor) Render ¶
func (a *OpenEditor) Render(w Writer)
Render renders the field to the screen.
func (*OpenEditor) Title ¶
func (a *OpenEditor) Title() string
Title returns the title for the field.
func (*OpenEditor) Update ¶
func (a *OpenEditor) Update(msg tea.Msg) tea.Cmd
Update receives a new event from bubbletea and updates the field's internal state.
func (*OpenEditor) WithDescription ¶
func (a *OpenEditor) WithDescription(desc string) *OpenEditor
WithDescription sets the description for the field.
func (*OpenEditor) WithTitle ¶
func (a *OpenEditor) WithTitle(title string) *OpenEditor
WithTitle sets the title for the field.
func (*OpenEditor) WithValue ¶
func (a *OpenEditor) WithValue(value *string) *OpenEditor
WithValue specifies the value to edit. The current value will be used as the initial content of the editor. The value will be updated when the editor is closed, or left unchanged if the user skips the editor.
type OpenEditorKeyMap ¶
OpenEditorKeyMap defines the key bindings for OpenEditor.
type OpenEditorStyle ¶
type OpenEditorStyle struct { Key lipgloss.Style // how to highlight keys Editor lipgloss.Style NoEditorMessage string }
OpenEditorStyle defines the display style for OpenEditor.
type Select ¶
type Select[T any] struct { KeyMap SelectKeyMap Style SelectStyle // contains filtered or unexported fields }
Select is a prompt that allows selecting from a list of options using a fuzzy filter.
func (*Select[T]) Description ¶
Description returns the description of the select field.
func (*Select[T]) Value ¶
func (s *Select[T]) Value() T
Value reports the current value of the select field.
func (*Select[T]) WithDescription ¶
WithDescription sets the description for the select field.
func (*Select[T]) WithOptions ¶
func (s *Select[T]) WithOptions(opts ...SelectOption[T]) *Select[T]
WithOptions sets the available options for the select field. The options will be presented in the order they are provided. Existing options will be replaced.
func (*Select[T]) WithSelected ¶
WithSelected sets the selected option for the select field.
func (*Select[T]) WithValue ¶
WithValue sets the destination for the select field. The existing value, if any, will be selected by default.
func (*Select[T]) WithVisible ¶
WithVisible sets the number of visible options in the select field. If unset, a default is picked based on the terminal height.
type SelectKeyMap ¶
type SelectKeyMap struct { Up key.Binding Down key.Binding Accept key.Binding DeleteFilterChar key.Binding }
SelectKeyMap defines the key bindings for Select.
type SelectOption ¶
SelectOption is a single option for a select field.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package fliptree renders a tree of nodes as text in reverse: children first, then parent.
|
Package fliptree renders a tree of nodes as text in reverse: children first, then parent. |
Package widget implements more complex user interface components on top of the primitives offered in the ui package.
|
Package widget implements more complex user interface components on top of the primitives offered in the ui package. |