src/Util/ColourUtil.php
public static function validateColour(Terminal $terminal, string $colour, string $fallback = null) : string
    {
        if (!ctype_digit($colour)) {
            return static::validateColourName($colour);
        }
        
        Assertion::between($colour, 0, 255, 'Invalid colour code');
        
        if ($terminal->getColourSupport() >= 256) {
            return $colour;
        }

        if ($fallback !== null) {
            return static::validateColourName($fallback);
        }
        
        return static::map256To8((int) $colour);
    }
public static function validateColour(Terminal $terminal, string $colour, string $fallback = null) : string
    {
        if (!ctype_digit($colour)) {
            return static::validateColourName($colour);
        }
        
        Assertion::between($colour, 0, 255, 'Invalid colour code');
        
        if ($terminal->getColourSupport() >= 256) {
            return $colour;
        }

        if ($fallback !== null) {
            return static::validateColourName($fallback);
        }
        
        return static::map256To8((int) $colour);
    }
Check if $colour exists
If it's a 256-colours code and $terminal doesn't support it, returns a fallback value