Canvas
Classes in the Phui\Canvas namespace. A Canvas node paints through a Surface, which is a grid of mutable cells.
Surface
final class Phui\Canvas\Surface
public int $width
public int $heightThe surface's dimensions in cells.
public array $cellsThe grid of SurfaceCell objects, indexed by row then column.
__construct(int $width, int $height)Creates a surface of the given size, with every cell blank.
resize(int $width, int $height): voidResizes the surface, discarding the existing cells.
clear(?Colour $backgroundColour = null): voidResets every cell, optionally filling each with a background colour.
SurfaceCell
final class Phui\Canvas\SurfaceCell
One cell of a Surface. Written to directly.
public string $charThe character drawn in the cell. A space by default.
public ?Colour $foregroundColour
public ?Colour $backgroundColourThe cell's colours. null leaves the terminal's own.
clear(): voidResets the cell to a blank character with no colours.
StyledString
final class Phui\Text\StyledString implements Stringable
Text carrying colour and decoration, accepted anywhere a string is.
static make(
string $text = '',
?Colour $colour = null,
?Colour $background = null,
array $typography = [],
): selfCreates a styled string. $typography takes TextDecorationType cases.
StyledString::make('Ready', Hex::from('#a3be8c'))
->append(' to go');append(
string $text,
?Colour $colour = null,
?Colour $background = null,
array $typography = [],
): selfReturns a copy with a differently styled run appended.
isEmpty(): boolReturns whether the string has no text.
width(): intReturns the string's display width in cells, which differs from its byte and character counts for wide and combining characters.
measure(
int $maxWidth,
TextWrapType $wrapType = TextWrapType::Word,
): SizeReturns the Size the string occupies when wrapped to $maxWidth.
wrap(
int $maxWidth,
TextWrapType $wrapType = TextWrapType::Word,
): arrayReturns the string split into lines at $maxWidth.
isEquivalentTo(self $other): boolReturns whether both strings carry the same text and styling.
Enums
TextDecorationType
enum Phui\Style\TextDecorationType: string
The decorations passed in a StyledString typography array. Cases: Bold, Dim, Italic, Underline, Reverse, Strikethrough.
SparklineType
enum Phui\Style\SparklineType: string
Cases P15, P25, P40, P50, P65, P75, P90 and P100, backed by the block characters ▁▂▃▄▅▆▇█.
static all(): arrayReturns every case in ascending order.