Browse Source

Fixed formatting

tags/2.0.0-beta
Antonio Ramirez 12 years ago
parent
commit
a20bd45645
  1. 123
      framework/helpers/base/Console.php

123
framework/helpers/base/Console.php

@ -304,34 +304,78 @@ class Console
public static function ansiToHtml($string) public static function ansiToHtml($string)
{ {
$tags = 0; $tags = 0;
return preg_replace_callback('/\033\[[\d;]+m/', function($ansi) use (&$tags) { return preg_replace_callback(
'/\033\[[\d;]+m/',
function ($ansi) use (&$tags) {
$styleA = array(); $styleA = array();
foreach(explode(';', $ansi) as $controlCode) foreach (explode(';', $ansi) as $controlCode) {
{ switch ($controlCode) {
switch($controlCode) case static::FG_BLACK:
{ $style = array('color' => '#000000');
case static::FG_BLACK: $style = array('color' => '#000000'); break; break;
case static::FG_BLUE: $style = array('color' => '#000078'); break; case static::FG_BLUE:
case static::FG_CYAN: $style = array('color' => '#007878'); break; $style = array('color' => '#000078');
case static::FG_GREEN: $style = array('color' => '#007800'); break; break;
case static::FG_GREY: $style = array('color' => '#787878'); break; case static::FG_CYAN:
case static::FG_PURPLE: $style = array('color' => '#780078'); break; $style = array('color' => '#007878');
case static::FG_RED: $style = array('color' => '#780000'); break; break;
case static::FG_YELLOW: $style = array('color' => '#787800'); break; case static::FG_GREEN:
case static::BG_BLACK: $style = array('background-color' => '#000000'); break; $style = array('color' => '#007800');
case static::BG_BLUE: $style = array('background-color' => '#000078'); break; break;
case static::BG_CYAN: $style = array('background-color' => '#007878'); break; case static::FG_GREY:
case static::BG_GREEN: $style = array('background-color' => '#007800'); break; $style = array('color' => '#787878');
case static::BG_GREY: $style = array('background-color' => '#787878'); break; break;
case static::BG_PURPLE: $style = array('background-color' => '#780078'); break; case static::FG_PURPLE:
case static::BG_RED: $style = array('background-color' => '#780000'); break; $style = array('color' => '#780078');
case static::BG_YELLOW: $style = array('background-color' => '#787800'); break; break;
case static::BOLD: $style = array('font-weight' => 'bold'); break; case static::FG_RED:
case static::ITALIC: $style = array('font-style' => 'italic'); break; $style = array('color' => '#780000');
case static::UNDERLINE: $style = array('text-decoration' => array('underline')); break; break;
case static::OVERLINED: $style = array('text-decoration' => array('overline')); break; case static::FG_YELLOW:
case static::CROSSED_OUT:$style = array('text-decoration' => array('line-through')); break; $style = array('color' => '#787800');
case static::BLINK: $style = array('text-decoration' => array('blink')); break; break;
case static::BG_BLACK:
$style = array('background-color' => '#000000');
break;
case static::BG_BLUE:
$style = array('background-color' => '#000078');
break;
case static::BG_CYAN:
$style = array('background-color' => '#007878');
break;
case static::BG_GREEN:
$style = array('background-color' => '#007800');
break;
case static::BG_GREY:
$style = array('background-color' => '#787878');
break;
case static::BG_PURPLE:
$style = array('background-color' => '#780078');
break;
case static::BG_RED:
$style = array('background-color' => '#780000');
break;
case static::BG_YELLOW:
$style = array('background-color' => '#787800');
break;
case static::BOLD:
$style = array('font-weight' => 'bold');
break;
case static::ITALIC:
$style = array('font-style' => 'italic');
break;
case static::UNDERLINE:
$style = array('text-decoration' => array('underline'));
break;
case static::OVERLINED:
$style = array('text-decoration' => array('overline'));
break;
case static::CROSSED_OUT:
$style = array('text-decoration' => array('line-through'));
break;
case static::BLINK:
$style = array('text-decoration' => array('blink'));
break;
case static::NEGATIVE: // ??? case static::NEGATIVE: // ???
case static::CONCEALED: case static::CONCEALED:
case static::ENCIRCLED: case static::ENCIRCLED:
@ -357,7 +401,9 @@ class Console
} }
$tags++; $tags++;
return '<span' . (!empty($styleString) ? 'style="' . implode(';', $styleString) : '') . '>'; return '<span' . (!empty($styleString) ? 'style="' . implode(';', $styleString) : '') . '>';
}, $string); },
$string
);
} }
/** /**
@ -493,8 +539,11 @@ class Console
if ($colored) { if ($colored) {
$string = str_replace('%%', '% ', $string); $string = str_replace('%%', '% ', $string);
foreach ($conversions as $key => $value) { foreach ($conversions as $key => $value) {
$string = str_replace($key, static::color($value), $string = str_replace(
$string); $key,
static::color($value),
$string
);
} }
$string = str_replace('% ', '%', $string); $string = str_replace('% ', '%', $string);
@ -692,13 +741,16 @@ class Console
*/ */
public static function prompt($text, $options = array()) public static function prompt($text, $options = array())
{ {
$options = ArrayHelper::merge($options, array( $options = ArrayHelper::merge(
$options,
array(
'required' => false, 'required' => false,
'default' => null, 'default' => null,
'pattern' => null, 'pattern' => null,
'validator' => null, 'validator' => null,
'error' => 'Invalid input.', 'error' => 'Invalid input.',
)); )
);
$error = null; $error = null;
top: top:
@ -717,7 +769,8 @@ class Console
static::output($options['error']); static::output($options['error']);
goto top; goto top;
} elseif ($options['validator'] && } elseif ($options['validator'] &&
!call_user_func_array($options['validator'], array($input, &$error))) { !call_user_func_array($options['validator'], array($input, &$error))
) {
static::output(isset($error) ? $error : $options['error']); static::output(isset($error) ? $error : $options['error']);
goto top; goto top;
} }
@ -763,7 +816,9 @@ class Console
} }
echo " ? - Show help\n"; echo " ? - Show help\n";
goto top; goto top;
} elseif (!in_array($input, array_keys($options))) goto top; } elseif (!in_array($input, array_keys($options))) {
goto top;
}
return $input; return $input;
} }

Loading…
Cancel
Save