Skip to content

Commit

Permalink
Apply fixes from StyleCI (#108)
Browse files Browse the repository at this point in the history
[ci skip] [skip ci]

Co-authored-by: Jitendra <[email protected]>
  • Loading branch information
adhocore and adhocore authored Nov 15, 2024
1 parent 6092763 commit a03fa80
Show file tree
Hide file tree
Showing 3 changed files with 191 additions and 188 deletions.
14 changes: 7 additions & 7 deletions src/Output/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function render(array $rows, array $styles = []): string
$title = $body = $dash = $positions = [];

[$start, $end] = $styles['head'];
$pos = 0;
$pos = 0;
foreach ($head as $col => $size) {
$dash[] = str_repeat('-', $size + 2);
$title[] = str_pad($this->toWords($col), $size, ' ');
Expand All @@ -68,11 +68,11 @@ public function render(array $rows, array $styles = []): string

if (isset($styles[$line . ':' . $colNumber])) { // cell, 1:1
$style = $styles[$line . ':' . $colNumber];
} else if (isset($styles[$col]) || isset($styles['*:' . $colNumber])) { // col, *:2 or b
} elseif (isset($styles[$col]) || isset($styles['*:' . $colNumber])) { // col, *:2 or b
$style = $styles['*:' . $colNumber] ?? $styles[$col];
} else if (isset($styles[$line . ':*'])) { // row, 2:*
} elseif (isset($styles[$line . ':*'])) { // row, 2:*
$style = $styles[$line . ':*'];
} else if (isset($styles['*:*'])) { // any cell, *:*
} elseif (isset($styles['*:*'])) { // any cell, *:*
$style = $styles['*:*'];
} else {
$style = $styles[['even', 'odd'][(int) $odd]];
Expand Down Expand Up @@ -121,7 +121,7 @@ protected function normalize(array $rows): array

foreach ($head as $col => &$value) {
$cols = array_column($rows, $col);
$cols = array_map(function($col) {
$cols = array_map(function ($col) {
$col ??= '';

if (preg_match('/(\\x1b(?:.+)m)/U', $col, $matches)) {
Expand Down Expand Up @@ -152,8 +152,8 @@ protected function normalizeStyles(array $styles): array
foreach ($styles as $for => $style) {
if (is_string($style) && $style !== '') {
$default[$for] = ['<' . trim($style, '<> ') . '>', '</end>'];
} else if (str_contains($for, ':') && is_callable($style)) {
$default[$for] = $style;
} elseif (str_contains($for, ':') && is_callable($style)) {
$default[$for] = $style;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Output/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,9 @@ public function justify(string $first, ?string $second = null, array $options =
'sep' => $options['sep'] ?? '.',
];

$second = (string) $second;
$second = (string) $second;
$terminalWidth = $this->terminal->width() ?? 80;
$dashWidth = $terminalWidth - (strlen($first) + strlen($second));
$dashWidth = $terminalWidth - (strlen($first) + strlen($second));
// remove left and right margins because we're going to add 1 space on each side (after/before the text).
// if we don't have a second element, we just remove the left margin
$dashWidth -= $second === '' ? 1 : 2;
Expand Down
Loading

0 comments on commit a03fa80

Please sign in to comment.