Skip to content

Colours

Classes in the Phui\Colours namespace. Anywhere a Colour is accepted, a string is too, and is resolved as a hex value.

Colour

abstract class Phui\Colours\Colour implements Stringable

Extended by Hex, Rgb, Gradient and DefaultBackground.

php
public string $text

The colour's source text.

php
public int $red
public int $green
public int $blue

The colour's channel values, from 0 to 255.

Hex

final class Phui\Colours\Hex extends Colour

php
static from(string $hex): self

Creates a colour from a hex string.

php
Hex::from('#88c0d0')

Rgb

final class Phui\Colours\Rgb extends Colour

php
static from(int $red, int $green, int $blue): self

Creates a colour from three channel values, each from 0 to 255.

DefaultBackground

final class Phui\Colours\DefaultBackground extends Colour

php
__construct()

Creates a colour that emits the terminal's own default background rather than a specific value, letting whatever is behind it show through.

Gradient

final class Phui\Colours\Gradient extends Colour

A colour that varies across the space it fills, interpolating between two or more stops.

php
public GradientDirection $direction

The axis the gradient runs along.

php
public float $phase

The offset applied to every sample position.

php
static horizontal(Colour ...$stops): self

Creates a gradient running left to right through $stops.

php
Gradient::horizontal(Hex::from('#88c0d0'), Hex::from('#b48ead'))
php
static vertical(Colour ...$stops): self

Creates a gradient running top to bottom through $stops.

php
withPhase(float $phase): self

Returns a copy with the sample offset set to $phase, expressed as a fraction of the gradient: 0.5 shifts every sample half way along, and values outside 0–1 wrap — so an integer phase is a visual no-op.

php
at(float $t): Colour

Returns the colour at position $t, from 0 to 1, after adding the phase. Positions outside that range wrap by dropping the whole part — -0.25 samples at 0.75, and any integer samples at 0. Pass a fraction of your span ($x / $width), never a raw column or tick count.

Enums

ColourMode

enum Phui\Colours\ColourMode

How colours are encoded when written to the terminal. Detected at startup, or forced with colours().

php
ColourMode::TrueColour

24-bit colour, written as exact RGB values.

php
ColourMode::Colour256

Colours reduced to the nearest entry in the 256-colour palette.

php
ColourMode::Ansi16

Colours reduced to the nearest of the 16 base ANSI colours.

php
ColourMode::None

No colour written at all.

php
static fromDepth(ColourDepth $depth): self

Returns the mode matching a reported terminal ColourDepth. None has no matching depth and is never returned.

GradientDirection

enum Phui\Colours\GradientDirection: string

Cases: Horizontal, Vertical.

Released under the MIT License.