class

Phosphor::TextAreaMock

Inherits Phosphor::MockWidget < Reference < Object

A multi-line text input primitive.

Generic and app-agnostic: no knowledge of AppState, Msg, or the application theme. The Widget wrapper resolves theme → Style values and sets them in Props before each render. Extends InputMock's conventions to multiple rows: the cursor position and vertical scroll offset are owned by this widget's WidgetState; the text lives in props.lines and is updated by Cmd::InsertChar / Cmd::DeleteChar.

Reuses Cmd::MoveUp / Cmd::MoveDown (from ListMock) and Cmd::MoveCursorLeft / Cmd::MoveCursorRight / Cmd::InsertChar / Cmd::DeleteChar (from InputMock) — each Cmd is a generic token; TextAreaMock interprets it with row/column-clamping semantics instead of ListMock's wrap-around semantics.

Constructors

new(props : Props, state : WidgetState = WidgetState.new)

Initialises the text area with props and an optional state.

Source

Instance methods

handle_cmd(cmd : Cmd) : CmdResult

Responds to cursor-movement and editing commands.

  • Cmd::MoveCursorLeftcursor_col − 1; wraps to the end of the previous line when already at column 0.
  • Cmd::MoveCursorRightcursor_col + 1; wraps to the start of the next line when already at the end of the line.
  • Cmd::MoveUpcursor_row − 1, clamped at 0; cursor_col is clamped to the new line's length.
  • Cmd::MoveDowncursor_row + 1, clamped at the last line; cursor_col is clamped to the new line's length.
  • Cmd::InsertChar — inserts the character at cursor_col on the current line, then advances cursor_col.
  • Cmd::InsertString — inserts the full string at cursor_row/ cursor_col in one operation, then advances cursor_col by its length. Typically built from the DataEvent a Cmd::Paste produces, so a pasted block never triggers one re-render per character. Inserted directly into the current line — embedded newlines are not split into new rows.
  • Cmd::DeleteChar — deletes the character before cursor_col. At column 0, merges the current line into the previous one instead. Returns CmdResult::None at row 0, column 0 — nothing to delete.
  • Any other command, or an empty props.lines — returns CmdResult::None.

Every branch that moves the cursor also re-clamps scroll_row against the most recently rendered frame height, if any, so state.scroll_row stays correct even when inspected before the next render.

Source
props
Source
props=(props : Props)
Source
render_content(frame : Frame, buf : Buffer) : Void

Renders the visible window of props.lines into buf within frame.

scroll_row is adjusted first so cursor_row is visible, then up to frame.height lines starting at scroll_row are drawn. When props.line_number_style is set, each line is preceded by a right-aligned line number wide enough for the largest number in props.lines, plus one column of padding; the text itself is truncated to whatever width remains via max_width. The character at cursor_row/cursor_col is overlaid with props.cursor_style.

Source
state

Narrows the inherited state getter to TextAreaMock::WidgetState. Safe: initialize only ever stores a WidgetState into the base @state ivar.

Source

Nested types