class

Phosphor::InputMock

Inherits Phosphor::MockWidget < Reference < Object

A single-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. The cursor position and horizontal scroll offset are owned by this widget's WidgetState; the text value lives in Props and is updated by Cmd::InsertChar / Cmd::DeleteChar.

Constructors

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

Initialises the input with props and an optional state.

Source

Instance methods

handle_cmd(cmd : Cmd) : CmdResult

Responds to cursor-movement and editing commands.

  • Cmd::MoveCursorLeft — cursor − 1, clamped at 0.
  • Cmd::MoveCursorRight — cursor + 1, clamped at props.value.size.
  • Cmd::InsertChar — inserts the character at the cursor, then advances cursor.
  • Cmd::InsertString — inserts the full string at the cursor in one operation, then advances the cursor by its length. Typically built from the DataEvent a Cmd::Paste produces, so a pasted block never triggers one re-render per character.
  • Cmd::DeleteChar — deletes the character before the cursor, then retreats cursor. Returns CmdResult::None when already at position 0.
  • Cmd::SelectAll — moves the cursor to props.value.size (full selection deferred).
  • Cmd::MoveCursorTo — cursor set directly to cmd.position, clamped to 0..props.value.size.
  • Any other command — returns CmdResult::None.

Every branch that moves the cursor also re-clamps scroll_offset against the most recently rendered frame width, if any, so state.scroll_offset 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 input field into buf within frame.

When props.value is empty and props.placeholder is set, the placeholder is displayed and no cursor is drawn. Otherwise, scroll_offset is adjusted so the cursor is visible, then the value from scroll_offset onward is rendered with props.text_style, clipped to frame.width. The character at the cursor position is overlaid with props.cursor_style. A space is used as the cursor glyph when the cursor is past the end of the value.

Source
reset

Restores state to its initial value — cursor at 0, no scroll offset. Call this rather than replacing the instance when reusing an InputMock for a new editing session.

Source
state

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

Source

Nested types