Overview

Namespaces

  • None
  • splitbrain
    • phpcli
      • tests

Classes

  • CLI
  • Colors
  • Options
  • PSR3CLI
  • TableFormatter

Exceptions

  • Exception
  • Overview
  • Namespace
  • Class

Class Colors

Class Colors

Handles color output on (Linux) terminals

Namespace: splitbrain\phpcli
License: MIT
Author: Andreas Gohr andi@splitbrain.org
Located at src/Colors.php
Methods summary
public
# __construct( )

Constructor

Constructor

Tries to disable colors for non-terminals

public
# enable( )

enable color output

enable color output

public
# disable( )

disable color output

disable color output

public boolean
# isEnabled( )

Returns

boolean
is color support enabled?
public
# ptln( string $line, string $color, resource $channel = STDOUT )

Convenience function to print a line in a given color

Convenience function to print a line in a given color

Parameters

$line
the line to print, a new line is added automatically
$color
one of the available color names
$channel
file descriptor to write to

Throws

splitbrain\phpcli\Exception
public string
# wrap( string $text, string $color )

Returns the given text wrapped in the appropriate color and reset code

Returns the given text wrapped in the appropriate color and reset code

Parameters

$text
string to wrap
$color
one of the available color names

Returns

string
the wrapped string

Throws

splitbrain\phpcli\Exception
public string
# getColorCode( string $color )

Gets the appropriate terminal code for the given color

Gets the appropriate terminal code for the given color

Parameters

$color
one of the available color names

Returns

string
color code

Throws

splitbrain\phpcli\Exception
public
# set( string $color, resource $channel = STDOUT )

Set the given color for consecutive output

Set the given color for consecutive output

Parameters

$color
one of the supported color names
$channel
file descriptor to write to

Throws

splitbrain\phpcli\Exception
public
# reset( resource $channel = STDOUT )

reset the terminal color

reset the terminal color

Parameters

$channel
file descriptor to write to

Throws

splitbrain\phpcli\Exception
Constants summary
string C_RESET
# 'reset'
string C_BLACK
# 'black'
string C_DARKGRAY
# 'darkgray'
string C_BLUE
# 'blue'
string C_LIGHTBLUE
# 'lightblue'
string C_GREEN
# 'green'
string C_LIGHTGREEN
# 'lightgreen'
string C_CYAN
# 'cyan'
string C_LIGHTCYAN
# 'lightcyan'
string C_RED
# 'red'
string C_LIGHTRED
# 'lightred'
string C_PURPLE
# 'purple'
string C_LIGHTPURPLE
# 'lightpurple'
string C_BROWN
# 'brown'
string C_YELLOW
# 'yellow'
string C_LIGHTGRAY
# 'lightgray'
string C_WHITE
# 'white'
Properties summary
protected array $colors

known color names

known color names

# array( self::C_RESET => "\33[0m", self::C_BLACK => "\33[0;30m", self::C_DARKGRAY => "\33[1;30m", self::C_BLUE => "\33[0;34m", self::C_LIGHTBLUE => "\33[1;34m", self::C_GREEN => "\33[0;32m", self::C_LIGHTGREEN => "\33[1;32m", self::C_CYAN => "\33[0;36m", self::C_LIGHTCYAN => "\33[1;36m", self::C_RED => "\33[0;31m", self::C_LIGHTRED => "\33[1;31m", self::C_PURPLE => "\33[0;35m", self::C_LIGHTPURPLE => "\33[1;35m", self::C_BROWN => "\33[0;33m", self::C_YELLOW => "\33[1;33m", self::C_LIGHTGRAY => "\33[0;37m", self::C_WHITE => "\33[1;37m", )
protected boolean $enabled

should colors be used?

should colors be used?

# true
API documentation generated by ApiGen