Skip to content

Commit

Permalink
Merge 9afc8d7 into ee34bdb
Browse files Browse the repository at this point in the history
  • Loading branch information
kristuff committed May 22, 2020
2 parents ee34bdb + 9afc8d7 commit 95c6aba
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -43,7 +43,7 @@ Deploy with your project (in `composer.json`):
{
...
"require": {
"kristuff/mishell": ">=1.2-stable"
"kristuff/mishell": ">=1.3-stable"
}
}
```
Expand Down
52 changes: 48 additions & 4 deletions demo/demo.table.php
Expand Up @@ -44,16 +44,16 @@
];
$rows = [
[
Console::text('foo (on right)', 'white'),
Console::text('foo', 'white'),
Console::text('some centered text red for foo', 'red')
],
[
Console::text('bar (on right)', 'white'),
Console::text('bar', 'white'),
Console::text( 'some centered text green for bar', 'green')
],
[
Console::text('foobar (on right)', 'white'),
'some centered text ' .Console::text('on BLUE here', 'white', 'blue'). ' for foobar'
Console::text('foobar', 'white'),
'some text with unicode ✓ ' .Console::text('on BLUE here', 'white', 'blue')
]
];

Expand Down Expand Up @@ -87,4 +87,48 @@
Console::log(Console::tableSeparator($rowHeaders)); // saparator |----------------------- ...
console::resetDefaults();

// -------------------------------
// ------ ANOTHER STYLE ---------
// -------------------------------
Console::log();
Console::log(' ' . Console::text('Another style sample', 'white', 'underlined'));
Console::log();

$rowHeaders = [
Console::text('Item', 'darkgray') => 10,
Console::text('Status', 'darkgray') => 12,
Console::text('Description', 'darkgray') => 25
//✓✗
];
$rows = [
[Console::text('foo', 'white'), Console::text(' ONLINE ', 'white', 'green') , Console::text('some text for foo', 'white')],
[Console::text('bar', 'white'), Console::text(' ONLINE ', 'white', 'green') , Console::text('some text for bar', 'white')],
[Console::text('foobar ', 'white'), Console::text(' OFFLINE ', 'white', 'red') , Console::text('some text for foobar', 'white')]
];

Console::$horizontalSeparator = '-'; // change the horizontal separator
Console::$tableCellPadding = ''; // no padding
Console::$verticalInnerSeparator = ' '; // blank separator
Console::$verticalSeparator = ' '; // no top left/right separator except a margin..
// Console::$verticalHeaderSeparator = ''; // no top left/right separator (not needed)

// table start
Console::log(Console::tableRowSeparator($rowHeaders, 'drakgray')); // saparator --------- --------- ---
Console::log(Console::tableRow($rowHeaders, 'drakgray')); // columns headers foo bar f...
Console::log(Console::tableRowSeparator($rowHeaders, 'drakgray')); // saparator --------- --------- ---

// tables rows
foreach ($rows as $row){
Console::log(
Console::TableRowStart(). // start row with separator. Then, each cell will end with a separator
Console::TableRowCell($row[0] , 10). // keep align right left
Console::TableRowCell($row[1] , 12, Console::ALIGN_CENTER). // align center
Console::TableRowCell($row[2] , 25) // keep align right left
);
}
// table end
Console::log(Console::tableRowSeparator($rowHeaders, 'drakgray')); // saparator --------- --------- ---
console::resetDefaults();


?>
2 changes: 1 addition & 1 deletion demo/index.php
Expand Up @@ -24,7 +24,7 @@ function printLoader()
Console::log(' '. Console::text(" | | | | | | | ___) | | | | __/ | | ", 'red'));
Console::log(' '. Console::text(" |_| |_| |_|_||____/|_| |_|\___|_|_| ", 'red'));
Console::log(' '. Console::text(" ", 'red'));
Console::log(' '. Console::text(" Version 1.2 ", 'red'));
Console::log(' '. Console::text(" Version 1.3 ", 'red'));
Console::log(' '. Console::text(" © 2017-2020 Kristuff ", 'red'));
Console::log(' '. Console::text(" ", 'red'));
Console::log();
Expand Down
2 changes: 1 addition & 1 deletion lib/Console.php
Expand Up @@ -13,7 +13,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 1.2.0
* @version 1.3.0
* @copyright 2017-2020 Kristuff
*/

Expand Down
2 changes: 1 addition & 1 deletion lib/Program.php
Expand Up @@ -13,7 +13,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 1.2.0
* @version 1.3.0
* @copyright 2017-2020 Kristuff
*/

Expand Down
4 changes: 2 additions & 2 deletions lib/ShellColoredPrinter.php
Expand Up @@ -13,7 +13,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 1.2.0
* @version 1.3.0
* @copyright 2017-2020 Kristuff
*/

Expand Down Expand Up @@ -356,7 +356,7 @@ public static function relog()
*/
public function pad($input, $padLength, $padString = ' ', $padType = STR_PAD_RIGHT)
{
$diff = $padLength - strlen(preg_replace('#\\033\[[[0-9;*]{1,}m#', '', $input));
$diff = $padLength - mb_strlen(preg_replace('#\\033\[[[0-9;*]{1,}m#', '', $input));

if ($diff > 0){
switch ($padType){
Expand Down
2 changes: 1 addition & 1 deletion lib/ShellPrinter.php
Expand Up @@ -13,7 +13,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @version 1.2.0
* @version 1.3.0
* @copyright 2017-2020 Kristuff
*/

Expand Down
23 changes: 16 additions & 7 deletions lib/ShellTablePrinter.php
Expand Up @@ -98,6 +98,14 @@ abstract class ShellTablePrinter extends \Kristuff\Mishell\ShellColoredPrinter
*/
public static $verticalSeparator = '|';

/**
* The vertical header separator sign.
*
* @access public
* @var string
*/
public static $verticalHeaderSeparator = '+';

/**
* The vertical separator sign.
*
Expand Down Expand Up @@ -141,12 +149,12 @@ public static function tableRowSeparator()
array_shift($args);

$str = self::$verticalSeparator ;
$cellPaddingLenght = strlen(self::$tableCellPadding) *2;
$cellPaddingLenght = mb_strlen(self::$tableCellPadding) *2;
foreach ($columnsPads as $key => $pad){
$str .= str_repeat(self::$horizontalSeparator , $pad + $cellPaddingLenght) .self::$verticalInnerSeparator ;
$str .= str_repeat(self::$horizontalSeparator , $pad + $cellPaddingLenght) .self::$verticalInnerSeparator;
}

return self::getCliString(self::$verticalInnerSeparator === '' ? $str : substr($str, 0, strlen($str) -1). self::$verticalSeparator, $args);
return self::getCliString(self::$verticalInnerSeparator === '' ? $str : substr($str, 0, mb_strlen($str) -1). self::$verticalSeparator, $args);
}

/**
Expand All @@ -166,12 +174,13 @@ public static function tableSeparator()
$columnsPads = !empty($args) ? $args[0] : [];
array_shift($args);

$str = self::$verticalSeparator ;
$cellPaddingLenght = strlen(self::$tableCellPadding) *2;
$str = self::$verticalHeaderSeparator ;
$cellPaddingLenght = mb_strlen(self::$tableCellPadding) *2;
foreach ($columnsPads as $key => $pad){
$str .= str_repeat(self::$horizontalSeparator , $pad + $cellPaddingLenght) .self::$horizontalSeparator;
$str .= str_repeat(self::$horizontalSeparator , $pad + $cellPaddingLenght) .self::$verticalInnerSeparator ;
}
return self::getCliString(substr($str, 0, strlen($str) -1). self::$verticalSeparator, $args);
return self::getCliString(self::$verticalInnerSeparator === '' ? $str : substr($str, 0, mb_strlen($str) -1). self::$verticalHeaderSeparator, $args);

}

/**
Expand Down

0 comments on commit 95c6aba

Please sign in to comment.