class

Phosphor::ParagraphMock

Inherits Phosphor::MockWidget < Reference < Object

A word-wrapped block of text.

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. Display only — it owns no mutable render state and does not handle input.

Scope limitation, documented per .claude/rules/widgets.md's convention for widgets with a bounded feature set:

  • Only ASCII and common Unicode (Latin, CJK) word breaking is supported. Latin text wraps at whitespace or hyphens; CJK text (cells with Width.of(char) == 2) wraps at any character boundary.
  • Right-to-left text is not supported.
  • The full Unicode line-breaking algorithm (UAX #14) is not implemented — this is a simple greedy wrapper, not a general-purpose typesetter.
  • Hyphenation algorithms (inserting new hyphens to break a word that has none) are not implemented; only hyphens already present in the text are treated as break points.

Constructors

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

Initialises the paragraph with props and an optional state. No extra render state is needed beyond the base WidgetState.

Source

Instance methods

handle_cmd(cmd : Cmd) : CmdResult

Display only — always returns CmdResult::None.

Source
preferred_height(width : Int32) : Int32 | Nil

The number of rows props.text word-wraps to at width — the same wrapping #render_content itself performs, so the two always agree.

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

Word-wraps props.text to frame.width cells and writes each resulting line into buf, clipped to frame.height rows.

Each line is positioned per props.alignment: Left at frame.x, Right at frame.x + (frame.width - line_width), Center at frame.x + (frame.width - line_width) // 2, where line_width is that line's own cell width (lines are shorter than frame.width whenever a word wouldn't fit, so alignment has visible effect).

Source

Nested types