input

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package input provides a single-line text input wrapped in a pane — a theme-styled, bordered text field with a title slot on the border.

Like every other tuilib component (filter, list, …), input owns its own pane: View() returns the bordered render. Don't wrap an input in another pane — set Options.Title to put the label on the border instead.

Use input as the building block for any text-entry need:

in := input.New(theme.Dark().Input())
in.SetTitle("Name")
// in your screen's Update: in, cmd = in.Update(msg)
// in your screen's View:   string := in.View()

Reach for pkg/filter when you want the same input wired with the "/-to-focus, enter-commits, esc-clears" key behavior.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Model

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

Model is the input's exported state. Focus state lives on both the embedded textinput (so keys route correctly) and the pane (so the border color reflects focus) — toggle them together via Focus/Blur.

func New

func New(opts Options) Model

New constructs an input. The cursor does not blink until Focus is called and its returned tea.Cmd is propagated.

func (*Model) Blur

func (m *Model) Blur()

Blur releases focus without touching the value.

func (*Model) Focus

func (m *Model) Focus() tea.Cmd

Focus grabs focus and returns the cursor-blink command. Always propagate the cmd — without it the cursor won't blink.

func (Model) Focused

func (m Model) Focused() bool

Focused reports whether the input is accepting keystrokes.

func (Model) Help

func (m Model) Help() []key.Binding

Help returns the keys this input "owns" — there are no special shortcuts (typing is implied), so the slice is empty. Kept for interface symmetry with other components.

func (Model) Init

func (m Model) Init() tea.Cmd

Init returns nil. Use Focus to start the cursor blink.

func (*Model) Reset

func (m *Model) Reset()

Reset clears the value and blurs.

func (*Model) SetActiveColor

func (m *Model) SetActiveColor(c lipgloss.TerminalColor)

SetActiveColor updates the border color used when focused.

func (*Model) SetCursorColor

func (m *Model) SetCursorColor(c lipgloss.TerminalColor)

SetCursorColor updates the foreground color of the blinking cursor.

func (*Model) SetInactiveColor

func (m *Model) SetInactiveColor(c lipgloss.TerminalColor)

SetInactiveColor updates the border color used when unfocused.

func (*Model) SetPlaceholderStyle

func (m *Model) SetPlaceholderStyle(s lipgloss.Style)

SetPlaceholderStyle updates the rendered style of placeholder text.

func (*Model) SetTextStyle

func (m *Model) SetTextStyle(s lipgloss.Style)

SetTextStyle updates the rendered style of typed text. Useful when reacting to a theme swap without rebuilding the model.

func (*Model) SetTitle

func (m *Model) SetTitle(s string)

SetTitle sets the title shown on the pane's top border.

func (*Model) SetValue

func (m *Model) SetValue(s string)

SetValue replaces the text.

func (*Model) SetWidth

func (m *Model) SetWidth(w int)

SetWidth resizes the surrounding pane. Height is fixed at 3.

func (Model) Update

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

Update forwards messages to the textinput. No keys are intercepted — commit/cancel semantics belong to the caller (see pkg/filter for the "enter commits, esc clears" pattern).

func (Model) Value

func (m Model) Value() string

Value returns the current text.

func (Model) View

func (m Model) View() string

View renders the input as a bordered three-line pane.

type Options

type Options struct {
	// Width sets the pane's outer width. Height is fixed at 3.
	Width int

	// Title sits on the top border of the pane. Defaults to "input" — set it
	// to the field's label (e.g. "Name", "Email").
	Title string
	// Placeholder shows when the input is empty.
	Placeholder string
	// Initial pre-fills the value.
	Initial string
	// Prompt is rendered inline before the cursor inside the input. Defaults
	// to "" — input is the bare-text variant; use pkg/filter when you want
	// a prompt glyph.
	Prompt string
	// CharLimit caps input length. Defaults to 0 (unlimited).
	CharLimit int

	// Text-input styling.
	PromptStyle      lipgloss.Style
	TextStyle        lipgloss.Style
	PlaceholderStyle lipgloss.Style
	CursorColor      lipgloss.TerminalColor

	// Pane pass-throughs. Unset fields fall back to NormalBorder both states
	// and SlotBracketsNone so the input reads as a plain bordered field.
	ActiveColor    lipgloss.TerminalColor
	InactiveColor  lipgloss.TerminalColor
	ActiveBorder   lipgloss.Border
	InactiveBorder lipgloss.Border
	SlotBrackets   pane.SlotBracketStyle
}

Options configures a new input. Zero-value fields fall back to sensible defaults so a caller can `input.New(input.Options{})` and get a working (un-themed) input. Mutate the typed-text styles via the *Style fields and the surrounding border via the pane pass-throughs.

Jump to

Keyboard shortcuts

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