1 | <?php |
||
33 | class AnsiColorFormatter extends FormatterAbstract |
||
34 | { |
||
35 | /** |
||
36 | * foreground color |
||
37 | * |
||
38 | * @const |
||
39 | */ |
||
40 | const FGCOLOR_BLACK = "\033[0;30m"; |
||
41 | const FGCOLOR_RED = "\033[0;31m"; |
||
42 | const FGCOLOR_GREEN = "\033[0;32m"; |
||
43 | const FGCOLOR_YELLOW = "\033[0;33m"; |
||
44 | const FGCOLOR_BLUE = "\033[0;34m"; |
||
45 | const FGCOLOR_MAGENTA = "\033[0;35m"; |
||
46 | const FGCOLOR_CYAN = "\033[0;36m"; |
||
47 | const FGCOLOR_GRAY = "\033[0;37m"; |
||
48 | const FGCOLOR_DARK_GRAY = "\033[1;30m"; |
||
49 | const FGCOLOR_BRIGHT_RED = "\033[1;31m"; |
||
50 | const FGCOLOR_BRIGHT_GREEN = "\033[1;32m"; |
||
51 | const FGCOLOR_BRIGHT_YELLOW = "\033[1;33m"; |
||
52 | const FGCOLOR_BRIGHT_BLUE = "\033[1;34m"; |
||
53 | const FGCOLOR_BRIGHT_MAGENTA = "\033[1;35m"; |
||
54 | const FGCOLOR_BRIGHT_CYAN = "\033[1;36m"; |
||
55 | const FGCOLOR_WHITE = "\033[1;37m"; |
||
56 | |||
57 | /** |
||
58 | * background color |
||
59 | * |
||
60 | * @const |
||
61 | */ |
||
62 | const BGCOLOR_BLACK = "\033[40m"; |
||
63 | const BGCOLOR_RED = "\033[41m"; |
||
64 | const BGCOLOR_GREEN = "\033[42m"; |
||
65 | const BGCOLOR_YELLOW = "\033[43m"; |
||
66 | const BGCOLOR_BLUE = "\033[44m"; |
||
67 | const BGCOLOR_MAGENTA = "\033[45m"; |
||
68 | const BGCOLOR_CYAN = "\033[46m"; |
||
69 | const BGCOLOR_WHITE = "\033[47m"; |
||
70 | const DECO_BOLD = "\033[1m"; |
||
71 | const DECO_UNDERLINE = "\033[4m"; |
||
72 | const DECO_BLINK = "\033[5m"; |
||
73 | const DECO_REVERSE = "\033[7m"; |
||
74 | const DECO_CROSS = "\033[9m"; |
||
75 | const DECO_END = "\033[0m"; |
||
76 | |||
77 | /** |
||
78 | * Color definitions for different log levels |
||
79 | * |
||
80 | * format [ fgColor, bgColor, textDeco ] |
||
81 | * |
||
82 | * @var array |
||
83 | * @access protected |
||
84 | */ |
||
85 | protected $colors = array( |
||
86 | LogLevel::DEBUG => [self::FGCOLOR_GRAY, '', ''], |
||
87 | LogLevel::INFO => ['', '', ''], |
||
88 | LogLevel::NOTICE => [self::FGCOLOR_BRIGHT_GREEN, '', ''], |
||
89 | LogLevel::WARNING => [self::FGCOLOR_BRIGHT_YELLOW, '', ''], |
||
90 | LogLevel::ERROR => [self::FGCOLOR_BRIGHT_RED, '', ''], |
||
91 | LogLevel::CRITICAL => [self::FGCOLOR_BRIGHT_RED, '', self::DECO_UNDERLINE], |
||
92 | LogLevel::ALERT => [self::FGCOLOR_BRIGHT_RED, self::BGCOLOR_WHITE, ''], |
||
93 | LogLevel::EMERGENCY => [self::FGCOLOR_BRIGHT_RED, self::BGCOLOR_WHITE, self::DECO_BLINK], |
||
94 | ); |
||
95 | |||
96 | /** |
||
97 | * Slave formatter |
||
98 | * |
||
99 | * @var FormatterInterface |
||
100 | * @access protected |
||
101 | */ |
||
102 | protected $slave; |
||
103 | |||
104 | /** |
||
105 | * Constructor |
||
106 | * @param FormatterInterface $formatter slave formatter |
||
107 | * @access public |
||
108 | */ |
||
109 | public function __construct(FormatterInterface $formatter = null) |
||
113 | |||
114 | /** |
||
115 | * Set slave formatter |
||
116 | * |
||
117 | * @param FormatterInterface $formatter the normal formatter |
||
118 | * @access public |
||
119 | * @api |
||
120 | */ |
||
121 | public function setSlave(FormatterInterface $formatter = null) |
||
125 | |||
126 | /** |
||
127 | * {@inheritDoc} |
||
128 | */ |
||
129 | protected function format( |
||
146 | |||
147 | /** |
||
148 | * add ansi color to text |
||
149 | * |
||
150 | * @param string $text text to color |
||
151 | * @param array $definition coloring definition |
||
152 | * @return string |
||
153 | * @access protected |
||
154 | */ |
||
155 | protected function addColor( |
||
166 | } |
||
167 |