Ansi Color

Ansi Color #

PhpTui\Tui\Color\AnsiColor

All colors from the ANSI color table are supported (though some names are not exactly the same).

Color NameColorForegroundBackground
blackAnsiColor::Black3040
redAnsiColor::Red3141
greenAnsiColor::Green3242
yellowAnsiColor::Yellow3343
blueAnsiColor::Blue3444
magentaAnsiColor::Magenta3545
cyanAnsiColor::Cyan3646
gray*AnsiColor::Gray3747
darkgray*AnsiColor::DarkGray90100
lightredAnsiColor::LightRed91101
lightgreenAnsiColor::LightGreen92102
lightyellowAnsiColor::LightYellow93103
lightblueAnsiColor::LightBlue94104
lightmagentaAnsiColor::LightMagenta95105
lightcyanAnsiColor::LightCyan96106
white*AnsiColor::White97107
  • gray is sometimes called white - this is not supported as we use white for bright white
  • gray is sometimes called silver - this is supported
  • darkgray is sometimes called light black or bright black (both are supported)
  • white is sometimes called light white or bright white (both are supported)
  • we support bright and light prefixes for all colors
  • we support - and _ and as separators for all colors
  • we support both gray and grey spellings

Example #

Show code
<?php

declare(strict_types=1);

use PhpTui\Tui\Color\AnsiColor;
use PhpTui\Tui\DisplayBuilder;
use PhpTui\Tui\Extension\Core\Widget\BlockWidget;
use PhpTui\Tui\Style\Style;
use PhpTui\Tui\Widget\Borders;

require 'vendor/autoload.php';

$display = DisplayBuilder::default()->build();
$display->draw(
    BlockWidget::default()
        ->borders(Borders::ALL)
        ->style(
            Style::default()
                ->fg(AnsiColor::Blue)
                ->bg(AnsiColor::Red)
        )
);