Documentation
¶
Overview ¶
Package ui provides terminal widgets for git-spice.
Index ¶
- Variables
- func AcceptField() tea.Msg
- func Run(f Field) error
- type Confirm
- func (c *Confirm) Description() string
- func (c *Confirm) Err() error
- 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) WithTitle(title string) *Confirm
- func (c *Confirm) WithValue(value *bool) *Confirm
- type ConfirmKeyMap
- type ConfirmStyle
- 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) 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 OpenEditor
- func (a *OpenEditor) Description() string
- func (a *OpenEditor) Err() error
- 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 Select
- func (s *Select) Description() string
- func (s *Select) Err() error
- func (s *Select) Render(out Writer)
- func (s *Select) Title() string
- func (s *Select) Update(msg tea.Msg) tea.Cmd
- func (s *Select) Value() string
- func (s *Select) WithDescription(desc string) *Select
- func (s *Select) WithOptions(opts ...string) *Select
- func (s *Select) WithTitle(title string) *Select
- func (s *Select) WithValue(value *string) *Select
- func (s *Select) WithVisible(visible int) *Select
- type SelectKeyMap
- type SelectStyle
- type Writer
Constants ¶
This section is empty.
Variables ¶
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: lipgloss.NewStyle().Foreground(_magentaColor), }
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: lipgloss.NewStyle().Foreground(_redColor), Title: _titleStyle, Description: _descriptionStyle, AcceptedTitle: _acceptedTitleStyle, AcceptedField: lipgloss.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 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: lipgloss.NewStyle().Foreground(_magentaColor), Editor: lipgloss.NewStyle().Foreground(_greenColor), }
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: lipgloss.NewStyle().Foreground(_yellowColor), Highlight: lipgloss.NewStyle().Foreground(_cyanColor), ScrollMarker: lipgloss.NewStyle().Foreground(_grayColor), }
DefaultSelectStyle is the default style for a Select.
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.
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.
type ConfirmKeyMap ¶
ConfirmKeyMap defines the key bindings for Confirm.
type ConfirmStyle ¶
ConfirmStyle configures the appearance of a Confirm field.
type Editor ¶
type Editor struct { // Command is the editor command to run. // // Defaults to "$EDITOR". Command string // Args are the arguments to pass to the editor command // before the file name. Args []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 { 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 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() *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 ¶
OpenEditorStyle defines the display style for OpenEditor.
type Select ¶
type Select 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) Description ¶
Description returns the description of the select field.
func (*Select) WithDescription ¶
WithDescription sets the description for the select field.
func (*Select) WithOptions ¶
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) WithValue ¶
WithValue sets the destination for the select field. The existing value, if any, will be selected by default.
func (*Select) 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.