Reader
final class Phui\Components\Reader
A scrolling view of a long string, word-wrapped to its measured width and virtualised a line at a time. Wrapping runs off the render pass, so loadingText shows until the first pass finishes; the text is re-wrapped when either it or the width changes, and changing the text scrolls back to the top. Takes focus.

php
use Phui\Components\Reader;
Reader::mount()->props(
text: $this->document,
smoothScroll: true,
lineColour: fn (string $line) => str_starts_with($line, '#')
? $this->themes->palette()->accent
: null,
);Props
| Prop | Type | Default | Description |
|---|---|---|---|
text | string | '' | The body to display. Newlines start a new paragraph. |
loadingText | string | 'Loading text...' | Shown while the text is being wrapped. |
showStatus | bool | true | Whether to render the position line under the text. |
smoothScroll | bool | false | Whether a held arrow key scrolls continuously. |
smoothScrollStep | int | 1 | Lines per tick while smooth-scrolling. |
lineColour | ?Closure(string): ?Colour | null | Called with each visible line to colour it. Return null for the default. |
With showStatus on, the bottom right reads first – last / total for the lines currently in view.
Input
| Input | Action |
|---|---|
| ↑ k | Scroll up |
| ↓ j | Scroll down |
| PgUp | Page up |
| PgDn Space | Page down |
| g Home | Top |
| G End | Bottom |
| Scroll wheel | Scroll by the wheel's amount |
With smoothScroll on, ↑ and ↓ start a 16ms interval that scrolls by smoothScrollStep and stops 150ms after the last keypress. The paging and jump keys are unaffected.
Colours
Phui\Components\Colours\ReaderColours
| Colour | Palette default | Used for |
|---|---|---|
text | text | Lines with no colour from lineColour. |
loading | muted | The loadingText line. |
border | muted | The left rule at rest. |
borderFocused | accent | The left rule while focused. |
status | muted | The position line at rest. |
statusFocused | accent | The position line while focused. |
scrollThumb | accent | The scrollbar thumb. |
scrollTrack | surface | The scrollbar track. |