Skip to content

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.

A wrapped block of text with a scrollbar and a position line

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

PropTypeDefaultDescription
textstring''The body to display. Newlines start a new paragraph.
loadingTextstring'Loading text...'Shown while the text is being wrapped.
showStatusbooltrueWhether to render the position line under the text.
smoothScrollboolfalseWhether a held arrow key scrolls continuously.
smoothScrollStepint1Lines per tick while smooth-scrolling.
lineColour?Closure(string): ?ColournullCalled 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

InputAction
kScroll up
jScroll down
PgUpPage up
PgDn SpacePage down
g HomeTop
G EndBottom
Scroll wheelScroll 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

ColourPalette defaultUsed for
texttextLines with no colour from lineColour.
loadingmutedThe loadingText line.
bordermutedThe left rule at rest.
borderFocusedaccentThe left rule while focused.
statusmutedThe position line at rest.
statusFocusedaccentThe position line while focused.
scrollThumbaccentThe scrollbar thumb.
scrollTracksurfaceThe scrollbar track.

Released under the MIT License.