Skip to content

Commit e76f979

Browse files
author
Samuel Akopyan
committed
Added padding to command line commands output
1 parent a28fc02 commit e76f979

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

framework/console/CConsole.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,26 @@ public static function yellow($string = '')
7373

7474
/**
7575
* Draw line with red background
76+
*
7677
* @param string $string
78+
* @param bool $padding
79+
*
7780
* @return string
7881
*/
79-
public static function redbg($string = '')
82+
public static function redbg($string = '', $padding = true)
8083
{
81-
return "\e[0;41m".$string."\e[0m";
82-
}
84+
$length = strlen($string) + 4;
85+
$output = '';
86+
87+
if ($padding) {
88+
$output .= "\e[0;41m".str_pad(' ', $length, " ", STR_PAD_LEFT)."\e[0m" . PHP_EOL;
89+
}
90+
$output .= "\e[0;41m".($padding ? ' ' : '').$string.($padding ? ' ' : '')."\e[0m".PHP_EOL;
91+
if ($padding) {
92+
$output .= "\e[0;41m".str_pad(' ', $length, " ", STR_PAD_LEFT)."\e[0m" . PHP_EOL;
93+
}
8394

95+
return $output;
96+
}
8497

8598
}

0 commit comments

Comments
 (0)