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)
{
$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();
foreach(explode(';', $ansi) as $controlCode)
{
switch($controlCode)
{
case static::FG_BLACK: $style = array('color' => '#000000'); break;
case static::FG_BLUE: $style = array('color' => '#000078'); break;
case static::FG_CYAN: $style = array('color' => '#007878'); break;
case static::FG_GREEN: $style = array('color' => '#007800'); break;
case static::FG_GREY: $style = array('color' => '#787878'); break;
case static::FG_PURPLE: $style = array('color' => '#780078'); break;
case static::FG_RED: $style = array('color' => '#780000'); break;
case static::FG_YELLOW: $style = array('color' => '#787800'); 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;
foreach (explode(';', $ansi) as $controlCode) {
switch ($controlCode) {
case static::FG_BLACK:
$style = array('color' => '#000000');
break;
case static::FG_BLUE:
$style = array('color' => '#000078');
break;
case static::FG_CYAN:
$style = array('color' => '#007878');
break;
case static::FG_GREEN:
$style = array('color' => '#007800');
break;
case static::FG_GREY:
$style = array('color' => '#787878');
break;
case static::FG_PURPLE:
$style = array('color' => '#780078');
break;
case static::FG_RED:
$style = array('color' => '#780000');
break;
case static::FG_YELLOW:
$style = array('color' => '#787800');
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::CONCEALED:
case static::ENCIRCLED:
@ -357,7 +401,9 @@ class Console
}
$tags++;
return '<span' . (!empty($styleString) ? 'style="' . implode(';', $styleString) : '') . '>';
}, $string);
},
$string
);
}
/**
@ -493,8 +539,11 @@ class Console
if ($colored) {
$string = str_replace('%%', '% ', $string);
foreach ($conversions as $key => $value) {
$string = str_replace($key, static::color($value),
$string);
$string = str_replace(
$key,
static::color($value),
$string
);
}
$string = str_replace('% ', '%', $string);
@ -692,13 +741,16 @@ class Console
*/
public static function prompt($text, $options = array())
{
$options = ArrayHelper::merge($options, array(
$options = ArrayHelper::merge(
$options,
array(
'required' => false,
'default' => null,
'pattern' => null,
'validator' => null,
'error' => 'Invalid input.',
));
)
);
$error = null;
top:
@ -717,7 +769,8 @@ class Console
static::output($options['error']);
goto top;
} 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']);
goto top;
}
@ -763,7 +816,9 @@ class Console
}
echo " ? - Show help\n";
goto top;
} elseif (!in_array($input, array_keys($options))) goto top;
} elseif (!in_array($input, array_keys($options))) {
goto top;
}
return $input;
}

Loading…
Cancel
Save