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.
public string $textThe colour's source text.
public int $red
public int $green
public int $blueThe colour's channel values, from 0 to 255.
Hex
final class Phui\Colours\Hex extends Colour
static from(string $hex): selfCreates a colour from a hex string.
Hex::from('#88c0d0')Rgb
final class Phui\Colours\Rgb extends Colour
static from(int $red, int $green, int $blue): selfCreates a colour from three channel values, each from 0 to 255.
DefaultBackground
final class Phui\Colours\DefaultBackground extends Colour
__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.
public GradientDirection $directionThe axis the gradient runs along.
public float $phaseThe offset applied to every sample position.
static horizontal(Colour ...$stops): selfCreates a gradient running left to right through $stops.
Gradient::horizontal(Hex::from('#88c0d0'), Hex::from('#b48ead'))static vertical(Colour ...$stops): selfCreates a gradient running top to bottom through $stops.
withPhase(float $phase): selfReturns 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.
at(float $t): ColourReturns 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().
ColourMode::TrueColour24-bit colour, written as exact RGB values.
ColourMode::Colour256Colours reduced to the nearest entry in the 256-colour palette.
ColourMode::Ansi16Colours reduced to the nearest of the 16 base ANSI colours.
ColourMode::NoneNo colour written at all.
static fromDepth(ColourDepth $depth): selfReturns 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.