Skip to content

Working with Color Themes

Minicli supports the use of color themes to change the style of command line output. There is currently 1 built-in theme other than the default theme:

  • Unicorn

To set the theme, pass in a configuration array with a theme value when initializing App in the script. Built-in themes need a leading \ character:

$app = new App([
    'theme' => '\Unicorn'
]);

To use the default built-in theme, do not include the theme configuration setting, or set it to an empty string.

User-defined themes can also be created and defined in your project. In this case, set the theme name including its namespace without a leading \:

$app = new App([
    'theme' => 'App\Theme\Blue'
]);

The above setting would use the following example theme:

<?php
// File: app/Theme/BlueTheme.php

namespace App\Theme;

use Minicli\Output\Theme\DefaultTheme;
use Minicli\Output\CLIColors;

class BlueTheme extends DefaultTheme
{
    public function getThemeColors(): array
    {
        return [
            'default'     => [ CLIColors::$FG_BLUE ],
            'alt'         => [ CLIColors::$FG_BLACK, CLIColors::$BG_BLUE ],
            'info'        => [ CLIColors::$FG_WHITE],
            'info_alt'    => [ CLIColors::$FG_WHITE, CLIColors::$BG_BLUE ]
        ];
    }
}

User-defined themes only need to define styles which will override those in the default theme.