You are here

class shellColours in Chaos Tool Suite (ctools) 7

Class to deal with wrapping output strings with colour formatting for the shell.

Hierarchy

Expanded class hierarchy of shellColours

File

drush/ctools.drush.inc, line 964
CTools Drush commands.

View source
class shellColours {
  private static $foreground_colours = array(
    'black' => '0;30',
    'dark_gray' => '1;30',
    'blue' => '0;34',
    'light_blue' => '1;34',
    'green' => '0;32',
    'light_green' => '1;32',
    'cyan' => '0;36',
    'light_cyan' => '1;36',
    'red' => '0;31',
    'light_red' => '1;31',
    'purple' => '0;35',
    'light_purple' => '1;35',
    'brown' => '0;33',
    'yellow' => '1;33',
    'light_gray' => '0;37',
    'white' => '1;37',
  );
  private static $background_colours = array(
    'black' => '40',
    'red' => '41',
    'green' => '42',
    'yellow' => '43',
    'blue' => '44',
    'magenta' => '45',
    'cyan' => '46',
    'light_gray' => '47',
  );

  /**
   * shellColours constructor.
   */
  private function __construct() {
  }

  /**
   * Returns coloured string.
   */
  public static function getColouredOutput($string, $foreground_colour = NULL, $background_colour = NULL) {
    $coloured_string = "";

    // Check if given foreground colour found.
    if ($foreground_colour) {
      $coloured_string .= "\33[" . self::$foreground_colours[$foreground_colour] . "m";
    }

    // Check if given background colour found.
    if ($background_colour) {
      $coloured_string .= "\33[" . self::$background_colours[$background_colour] . "m";
    }

    // Add string and end colouring.
    $coloured_string .= $string . "\33[0m";
    return $coloured_string;
  }

  /**
   * Returns all foreground colour names.
   */
  public static function getForegroundColours() {
    return array_keys(self::$foreground_colours);
  }

  /**
   * Returns all background colour names.
   */
  public static function getBackgroundColours() {
    return array_keys(self::$background_colours);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
shellColours::$background_colours private static property
shellColours::$foreground_colours private static property
shellColours::getBackgroundColours public static function Returns all background colour names.
shellColours::getColouredOutput public static function Returns coloured string.
shellColours::getForegroundColours public static function Returns all foreground colour names.
shellColours::__construct private function shellColours constructor.