input

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package input is the shared text-entry substrate: thin wrappers over bubbles/textinput and textarea (Line, Area) plus a textarea factory with overlay-friendly defaults (NewTextArea) and a multi-entry title+body editor (Editor), and the external-editor hop (ExternalEditorCmd). Routing every prompt through one package keeps cursor movement, word-wise editing, and bracketed paste behaving identically everywhere.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExternalEditor added in v0.2.0

func ExternalEditor(override string) string

ExternalEditor resolves the external editor command: override wins (the seam an app hangs its own setting on), $EDITOR is the fallback, "" means none - multiline fields then use the in-TUI textarea instead. One rule, no per-field knobs.

func ExternalEditorCmd added in v0.2.0

func ExternalEditorCmd(editor, id, initial string) tea.Cmd

ExternalEditorCmd suspends the TUI and opens the external editor on a temp file seeded with initial; the result returns as an ExternalEditorFinishedMsg. editor is resolved through ExternalEditor (pass "" to use $EDITOR) and runs through the shell, so commands with flags ("nvim -f") work.

func NewTextArea

func NewTextArea(opts ...Option) textarea.Model

NewTextArea creates a textarea.Model with sensible defaults for use inside TUI overlays: no prompt prefix, no line numbers, and dynamic height. The caller should configure styles after creation.

Types

type Area added in v0.2.0

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

Area is a multiline input, the in-TUI fallback when no external editor is configured. The zero value is not usable; construct with NewArea.

func NewArea added in v0.2.0

func NewArea(placeholder string, width, height int, opts ...AreaOption) Area

NewArea builds a focused multiline input sized for a modal. Height is its minimum; the area grows with its content. Line numbers and the row prompt are hidden unless enabled with options.

func (*Area) BeforeCursor added in v0.2.0

func (a *Area) BeforeCursor() string

BeforeCursor returns the current logical line up to the cursor, for token detection. Words never span newlines, so one line is the whole search space.

func (*Area) Blur added in v0.2.0

func (a *Area) Blur()

Blur removes focus (the cursor stops rendering).

func (*Area) Focus added in v0.2.0

func (a *Area) Focus()

Focus and Blur hand keyboard ownership to or away from the area, for forms where two inputs share one modal.

func (*Area) ReplaceBeforeCursor added in v0.2.0

func (a *Area) ReplaceBeforeCursor(n int, s string)

ReplaceBeforeCursor swaps the n runes before the cursor for s. The textarea exposes no direct cursor repositioning after SetValue, so the cursor lands at the end of the buffer - exact for the dominant case of completing while typing at the end, approximate for a mid-text edit.

func (*Area) SetCursorAt added in v0.2.6

func (a *Area) SetCursorAt(row, col int)

SetCursorAt moves the cursor to the given display row and column, clamped to the content - how a mouse click lands in the textarea. Rows are walked with CursorDown so soft-wrapped lines land where the eye sees them.

func (*Area) SetValue added in v0.2.0

func (a *Area) SetValue(s string)

SetValue replaces the content (e.g. reopening a draft).

func (*Area) Update added in v0.2.0

func (a *Area) Update(msg tea.Msg) tea.Cmd

Update routes a message into the textarea (enter inserts a newline).

func (*Area) Value added in v0.2.0

func (a *Area) Value() string

Value returns the current content.

func (*Area) View added in v0.2.0

func (a *Area) View() string

View renders the textarea.

type AreaOption added in v0.2.3

type AreaOption func(*areaConfig)

AreaOption configures an Area created by NewArea.

func WithAreaLineNumbers added in v0.2.3

func WithAreaLineNumbers(show bool) AreaOption

WithAreaLineNumbers controls whether the textarea renders line numbers.

func WithAreaPrompt added in v0.2.3

func WithAreaPrompt(prompt string) AreaOption

WithAreaPrompt sets the prompt rendered at the start of every textarea row.

type BodyFetchFunc

type BodyFetchFunc func(index int) (string, error)

BodyFetchFunc fetches the body for an entry at the given index.

type Editor

type Editor struct {
	Submitted bool
	Aborted   bool
	// contains filtered or unexported fields
}

Editor is a Bubble Tea model for editing multiple title+body entries.

func NewEditor

func NewEditor(entries []EditorEntry, opts ...EditorOption) Editor

NewEditor creates an Editor for the given entries.

func (Editor) Init

func (m Editor) Init() tea.Cmd

Init implements tea.Model.

func (Editor) Results

func (m Editor) Results() []EditorResult

Results returns the outcome for all entries.

func (Editor) Update

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

Update implements tea.Model.

func (Editor) View

func (m Editor) View() tea.View

View implements tea.Model.

type EditorEntry

type EditorEntry struct {
	Label string // display label (e.g. "owner/repo#123")
	Title string // initial title value
}

EditorEntry defines an item to edit.

type EditorOption

type EditorOption func(*editorConfig)

EditorOption configures an Editor created by NewEditor.

func WithBodyFetch

func WithBodyFetch(fn BodyFetchFunc) EditorOption

WithBodyFetch sets the function used to lazily fetch entry bodies.

func WithEditorBodyMinHeight

func WithEditorBodyMinHeight(h int) EditorOption

WithEditorBodyMinHeight sets the minimum body textarea height.

func WithEditorStyles

func WithEditorStyles(s EditorStyles) EditorOption

WithEditorStyles sets the editor styles.

func WithEditorWidth

func WithEditorWidth(w int) EditorOption

WithEditorWidth sets the editor width.

type EditorResult

type EditorResult struct {
	Label   string
	Title   string
	Body    string
	Changed bool
}

EditorResult holds the outcome for a single edited entry.

func Run

func Run(entries []EditorEntry, opts ...EditorOption) ([]EditorResult, bool, error)

Run launches the editor as a standalone Bubble Tea program and returns results.

type EditorStyles

type EditorStyles struct {
	BlurredText lg.Style
	Counter     lg.Style
	Dirty       lg.Style
	DimLabel    lg.Style
	FocusedText lg.Style
	Header      lg.Style
	HelpKey     lg.Style
	HelpText    lg.Style
	Label       lg.Style
}

EditorStyles controls the visual appearance of the editor.

type ExternalEditorFinishedMsg added in v0.2.0

type ExternalEditorFinishedMsg struct {
	ID   string
	Text string
	Err  error
}

ExternalEditorFinishedMsg delivers the text written in the external editor. ID is the opener's routing tag (e.g. "comment:42") so the consumer knows which flow to resume. Err is set when the editor could not run or the buffer could not be read back.

type Line added in v0.2.0

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

Line is a single-line input. The zero value is not usable; construct with NewLine.

func NewLine added in v0.2.0

func NewLine(prompt, placeholder string) Line

NewLine builds a focused single-line input with the given prompt and placeholder.

func (*Line) BeforeCursor added in v0.2.0

func (l *Line) BeforeCursor() string

BeforeCursor returns the content up to the cursor, for token detection (e.g. an autocomplete trigger word being typed).

func (*Line) Blur added in v0.2.0

func (l *Line) Blur()

Blur removes focus (the cursor stops rendering).

func (*Line) Focus added in v0.2.0

func (l *Line) Focus()

Focus and Blur hand keyboard ownership to or away from the field, for forms where two inputs share one modal.

func (*Line) ReplaceBeforeCursor added in v0.2.0

func (l *Line) ReplaceBeforeCursor(n int, s string)

ReplaceBeforeCursor swaps the n runes before the cursor for s, leaving the cursor at the end of s - how an autocomplete acceptance lands.

func (*Line) SetCursorAt added in v0.2.6

func (l *Line) SetCursorAt(col int)

SetCursorAt moves the cursor to col, clamped to the content - how a mouse click lands in the field.

func (*Line) SetSuggestions added in v0.2.0

func (l *Line) SetSuggestions(values []string)

SetSuggestions enables ghost-text autocompletion over the given values: typing a prefix shows the rest faint, and the textinput's accept binding (tab / ctrl+e / right at end) completes it.

func (*Line) SetValue added in v0.2.0

func (l *Line) SetValue(s string)

SetValue replaces the content and moves the cursor to the end (the natural spot when prefilling, e.g. the current title for an edit).

func (*Line) SetWidth added in v0.2.0

func (l *Line) SetWidth(w int)

SetWidth makes the field render exactly w columns, clamped to at least one so a too-narrow pane can never push a negative width into the textinput (which panics on View). textinput.View draws one column wider than its set width - a trailing cell for the end-of-line cursor - so the set width is one less than w; a boxed caller budgets exactly w and the field fills it without overrunning the frame.

func (*Line) Suggestions added in v0.2.0

func (l *Line) Suggestions() []string

Suggestions returns the current completion values.

func (*Line) Update added in v0.2.0

func (l *Line) Update(msg tea.Msg) tea.Cmd

Update routes a message (keys, paste) into the input.

func (*Line) Value added in v0.2.0

func (l *Line) Value() string

Value returns the current content.

func (*Line) View added in v0.2.0

func (l *Line) View() string

View renders the input with its cursor.

type Option

type Option func(*config)

Option configures a textarea created by NewTextArea.

func WithMaxHeight

func WithMaxHeight(h int) Option

WithMaxHeight sets the maximum height of the textarea.

func WithMinHeight

func WithMinHeight(h int) Option

WithMinHeight sets the minimum height of the textarea.

func WithPlaceholder

func WithPlaceholder(s string) Option

WithPlaceholder sets the placeholder text shown when the textarea is empty.

func WithWidth

func WithWidth(w int) Option

WithWidth sets the width of the textarea.

Jump to

Keyboard shortcuts

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