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 ¶
- func ExternalEditor(override string) string
- func ExternalEditorCmd(editor, id, initial string) tea.Cmd
- func NewTextArea(opts ...Option) textarea.Model
- type Area
- func (a *Area) BeforeCursor() string
- func (a *Area) Blur()
- func (a *Area) Focus()
- func (a *Area) ReplaceBeforeCursor(n int, s string)
- func (a *Area) SetCursorAt(row, col int)
- func (a *Area) SetValue(s string)
- func (a *Area) Update(msg tea.Msg) tea.Cmd
- func (a *Area) Value() string
- func (a *Area) View() string
- type AreaOption
- type BodyFetchFunc
- type Editor
- type EditorEntry
- type EditorOption
- type EditorResult
- type EditorStyles
- type ExternalEditorFinishedMsg
- type Line
- func (l *Line) BeforeCursor() string
- func (l *Line) Blur()
- func (l *Line) Focus()
- func (l *Line) ReplaceBeforeCursor(n int, s string)
- func (l *Line) SetCursorAt(col int)
- func (l *Line) SetSuggestions(values []string)
- func (l *Line) SetValue(s string)
- func (l *Line) SetWidth(w int)
- func (l *Line) Suggestions() []string
- func (l *Line) Update(msg tea.Msg) tea.Cmd
- func (l *Line) Value() string
- func (l *Line) View() string
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExternalEditor ¶ added in v0.2.0
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
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 ¶
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
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
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
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) Update ¶ added in v0.2.0
Update routes a message into the textarea (enter inserts a newline).
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 ¶
BodyFetchFunc fetches the body for an entry at the given index.
type Editor ¶
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) Results ¶
func (m Editor) Results() []EditorResult
Results returns the outcome for all entries.
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 ¶
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
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
NewLine builds a focused single-line input with the given prompt and placeholder.
func (*Line) BeforeCursor ¶ added in v0.2.0
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
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
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
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
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
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
Suggestions returns the current completion values.
type Option ¶
type Option func(*config)
Option configures a textarea created by NewTextArea.
func WithMaxHeight ¶
WithMaxHeight sets the maximum height of the textarea.
func WithMinHeight ¶
WithMinHeight sets the minimum height of the textarea.
func WithPlaceholder ¶
WithPlaceholder sets the placeholder text shown when the textarea is empty.