Documentation
¶
Overview ¶
Package input holds the terminal input primitives: the raw key sequences the TUI recognizes, a raw-bytes-to-semantic-event key map, and the grapheme-aware single-line/multi-line text editor used by the prompt and by form fields.
Go port of Ruby's lib/term_form/text.rb (Text + TextEditor), the key-byte table from lib/term_form/event.rb, and lib/tui/text_input.rb (which is only a compatibility alias in Ruby and needs no separate Go type).
This package deliberately does NOT decode terminal input: no raw-mode CSI parser, no escape-versus-alt timing heuristic, no bracketed-paste framing, no UTF-8 continuation buffer. Bubble Tea owns all of that. What is left — and what Bubble Tea does not provide — is the editing model: grapheme-indexed cursor motion, word kills, and paste sanitizing. KeyBytes names the sequences the editor recognizes, so a framework key message can be mapped onto them.
Index ¶
- Constants
- Variables
- func CellSlice(value string, start, width int) string
- func CellWidth(value string) int
- func Graphemes(value string) []string
- func Normalize(value string) string
- func Printable(key string) bool
- type Editor
- func (e *Editor) Clear()
- func (e *Editor) Cursor() int
- func (e *Editor) Empty() bool
- func (e *Editor) HandleKey(key string) Result
- func (e *Editor) Insert(raw string) Result
- func (e *Editor) Length() int
- func (e *Editor) Replace(raw string)
- func (e *Editor) SetCursor(position int)
- func (e *Editor) String() string
- func (e *Editor) Text() string
- type Options
- type Result
Constants ¶
const ( CtrlA = "\x01" CtrlB = "\x02" CtrlD = "\x04" CtrlE = "\x05" CtrlF = "\x06" CtrlH = "\x08" CtrlK = "\x0b" CtrlU = "\x15" CtrlW = "\x17" )
Control bytes the editor understands.
Variables ¶
var KeyBytes = map[string]string{
"tab": "\t", "shift_tab": "\x1b[Z", "return": "\r", "escape": "\x1b",
"up": "\x1b[A", "down": "\x1b[B", "left": "\x1b[D", "right": "\x1b[C",
"home": "\x1b[H", "end": "\x1b[F", "delete": "\x1b[3~", "backspace": "\x7f",
}
KeyBytes maps a named key to the byte sequence a terminal sends for it.
Functions ¶
func CellSlice ¶
CellSlice slices a plain string by terminal cells. Partial wide graphemes become spaces, preserving the columns of content on either side.
func Graphemes ¶
Graphemes splits a value into grapheme clusters — the units the cursor moves over, never bytes or codepoints.
Types ¶
type Editor ¶
type Editor struct {
// contains filtered or unexported fields
}
Editor is mutable editing state. Cursor offsets count grapheme clusters.
func (*Editor) Insert ¶
Insert types text at the cursor. It reports None when the sanitized input is empty, so a host can distinguish "nothing happened" from an edit.