Skip to content

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

php
public int $width
public int $height

The surface's dimensions in cells.

php
public array $cells

The grid of SurfaceCell objects, indexed by row then column.

php
__construct(int $width, int $height)

Creates a surface of the given size, with every cell blank.

php
resize(int $width, int $height): void

Resizes the surface, discarding the existing cells.

php
clear(?Colour $backgroundColour = null): void

Resets every cell, optionally filling each with a background colour.

SurfaceCell

final class Phui\Canvas\SurfaceCell

One cell of a Surface. Written to directly.

php
public string $char

The character drawn in the cell. A space by default.

php
public ?Colour $foregroundColour
public ?Colour $backgroundColour

The cell's colours. null leaves the terminal's own.

php
clear(): void

Resets 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.

php
static make(
    string $text = '',
    ?Colour $colour = null,
    ?Colour $background = null,
    array $typography = [],
): self

Creates a styled string. $typography takes TextDecorationType cases.

php
StyledString::make('Ready', Hex::from('#a3be8c'))
    ->append(' to go');
php
append(
    string $text,
    ?Colour $colour = null,
    ?Colour $background = null,
    array $typography = [],
): self

Returns a copy with a differently styled run appended.

php
isEmpty(): bool

Returns whether the string has no text.

php
width(): int

Returns the string's display width in cells, which differs from its byte and character counts for wide and combining characters.

php
measure(
    int $maxWidth,
    TextWrapType $wrapType = TextWrapType::Word,
): Size

Returns the Size the string occupies when wrapped to $maxWidth.

php
wrap(
    int $maxWidth,
    TextWrapType $wrapType = TextWrapType::Word,
): array

Returns the string split into lines at $maxWidth.

php
isEquivalentTo(self $other): bool

Returns 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 ▁▂▃▄▅▆▇█.

php
static all(): array

Returns every case in ascending order.

Released under the MIT License.