|
59 | 59 | Autoload::initialize(realpath('../src')); |
60 | 60 | Autoload::initialize(realpath('../../Net_Transmitter.git/src')); |
61 | 61 | Autoload::initialize(realpath('../../Cache_SHM.git/src')); |
| 62 | + Autoload::initialize(realpath('../../Console_Color.git/src')); |
62 | 63 | } else { |
63 | 64 | fwrite( |
64 | 65 | STDERR, |
|
116 | 117 | $cmdParser->displayUsage(13); |
117 | 118 | } |
118 | 119 |
|
| 120 | +$cmd->options['colors'] = $cmd->options['colors'] ?: 'auto'; |
| 121 | +$cmd->options['size'] = $cmd->options['size'] ?: 80; |
| 122 | +$cmd->options['commandMode'] = $cmd->options['commandMode'] ?: 's'; |
| 123 | +$cmd->options['replyMode'] = $cmd->options['replyMode'] ?: 's'; |
| 124 | +$comTimeout = null === $cmd->options['conTime'] |
| 125 | + ? (null === $cmd->options['time'] |
| 126 | + ? (int)ini_get('default_socket_timeout') |
| 127 | + : $cmd->options['time']) |
| 128 | + : $cmd->options['conTime']; |
| 129 | +$cmd->options['time'] = $cmd->options['time'] ?: 3; |
| 130 | +$comContext = null === $cmd->options['caPath'] |
| 131 | + ? null |
| 132 | + : stream_context_create( |
| 133 | + is_file($cmd->options['caPath']) |
| 134 | + ? array( |
| 135 | + 'ssl' => array( |
| 136 | + 'verify_peer' => true, |
| 137 | + 'cafile' => $cmd->options['caPath']) |
| 138 | + ) |
| 139 | + : array( |
| 140 | + 'ssl' => array( |
| 141 | + 'verify_peer' => true, |
| 142 | + 'capath' => $cmd->options['caPath']) |
| 143 | + ) |
| 144 | + ); |
| 145 | + |
119 | 146 | $c_colors = array( |
120 | 147 | 'SEND' => '', |
121 | 148 | 'SENT' => '', |
|
124 | 151 | 'NOTE' => '', |
125 | 152 | '' => '' |
126 | 153 | ); |
127 | | -if ($cmd->options['colors']) { |
| 154 | +if ('auto' === $cmd->options['colors']) { |
| 155 | + $cmd->options['colors'] = (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' |
| 156 | + || getenv('ANSICON_VER') != false) ? 'yes' : 'no'; |
| 157 | +} |
| 158 | +if ('yes' === $cmd->options['colors']) { |
128 | 159 | $c_colors['SENT'] = new Color( |
129 | 160 | Color\Fonts::BLACK, |
130 | 161 | Color\Backgrounds::PURPLE |
|
150 | 181 | } |
151 | 182 | } |
152 | 183 |
|
153 | | -$cmd->options['size'] = $cmd->options['size'] ?: 80; |
154 | | -$cmd->options['commandMode'] = $cmd->options['commandMode'] ?: 's'; |
155 | | -$cmd->options['replyMode'] = $cmd->options['replyMode'] ?: 's'; |
156 | | -$comTimeout = null === $cmd->options['conTime'] |
157 | | - ? (null === $cmd->options['time'] |
158 | | - ? (int)ini_get('default_socket_timeout') |
159 | | - : $cmd->options['time']) |
160 | | - : $cmd->options['conTime']; |
161 | | -$cmd->options['time'] = $cmd->options['time'] ?: 3; |
162 | | -$comContext = null === $cmd->options['caPath'] |
163 | | - ? null |
164 | | - : stream_context_create( |
165 | | - is_file($cmd->options['caPath']) |
166 | | - ? array( |
167 | | - 'ssl' => array( |
168 | | - 'verify_peer' => true, |
169 | | - 'cafile' => $cmd->options['caPath']) |
170 | | - ) |
171 | | - : array( |
172 | | - 'ssl' => array( |
173 | | - 'verify_peer' => true, |
174 | | - 'capath' => $cmd->options['caPath']) |
175 | | - ) |
176 | | - ); |
177 | | - |
178 | 184 | try { |
179 | 185 | $com = new RouterOS\Communicator( |
180 | 186 | $cmd->args['hostname'], |
|
327 | 333 | for ($i = 0, $l = count($wordFragments); $i < $l; $i += 2) { |
328 | 334 | unset($wordFragments[$i]); |
329 | 335 | } |
| 336 | + if ('' !== $c_colors['']) { |
| 337 | + $wordFragments = str_replace("\033", "\033[27@", $wordFragments); |
| 338 | + } |
330 | 339 |
|
331 | 340 | $isAbnormal = 'ERR' === $mode || 'NOTE' === $mode; |
332 | 341 | if ($isAbnormal) { |
|
385 | 394 | ); |
386 | 395 | } |
387 | 396 | : function ($mode, $word, $msg = '') use ($c_colors) { |
| 397 | + if ('' !== $c_colors['']) { |
| 398 | + $word = str_replace("\033", "\033[27@", $word); |
| 399 | + $msg = str_replace("\033", "\033[27@", $msg); |
| 400 | + } |
| 401 | + |
388 | 402 | if ('ERR' === $mode || 'NOTE' === $mode) { |
389 | 403 | fwrite(STDERR, "{$c_colors[$mode]}-- {$msg}"); |
390 | 404 | if ('' !== $word) { |
|
0 commit comments