Skip to content

Commit 87376b7

Browse files
committed
Add documentation to DrawsTabs trait
1 parent 2a8dc6d commit 87376b7

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/Themes/Default/Concerns/DrawsTabs.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,34 @@ protected function tabs(
2121
): string {
2222
$strippedWidth = fn (string $value): int => mb_strwidth($this->stripEscapeSequences($value));
2323

24+
// Build the top row for the tabs by adding whitespace equal
25+
// to the width of each tab plus padding, or by adding an
26+
// equal number of box characters for the selected tab.
2427
$top_row = $tabs->map(fn($value, $key) => $key === $selected
2528
? '' . str_repeat('', $strippedWidth($value) + 2) . ''
2629
: str_repeat(' ', $strippedWidth($value) + 4)
2730
)->implode('');
2831

32+
// Build the middle row for the tabs by adding the tab name
33+
// surrounded by some padding. But if the tab is selected
34+
// then highlight the tab and surround it in box chars.
2935
$middle_row = $tabs->map(fn($value, $key) => $key === $selected
3036
? "{$this->dim('')} {$this->{$color}($value)} {$this->dim('')}"
3137
: " {$value} "
3238
)->implode('');
3339

40+
// Build the bottom row for the tabs by adding box characters equal to the width
41+
// of each tab, plus padding. If the tab is selected, add the appropriate box
42+
// characters instead. Finally, pad the whole line to fill the width fully.
3443
$bottom_row = $tabs->map(fn($value, $key) => $key === $selected
3544
? '' . str_repeat('', $strippedWidth($value) + 2) . ''
3645
: str_repeat('', $strippedWidth($value) + 4)
3746
)->implode('');
3847
$bottom_row = $this->pad($bottom_row, $width, '');
3948

40-
// automatic horizontal tab scrolling
49+
// If the tabs are wider than the provided width, we need to trim the tabs to fit.
50+
// We remove the appropriate number of characters from the beginning and end of
51+
// each row by using the highlighted tab's index to get it's scroll position.
4152
if ($strippedWidth($top_row) > $width) {
4253
$scroll = $selected / ($tabs->count() - 1);
4354
$chars_to_kill = $strippedWidth($top_row) - $width;
@@ -47,6 +58,9 @@ protected function tabs(
4758
}
4859
}
4960

61+
// We wait until now to dim the top and bottom
62+
// rows, otherwise the horizontal scrolling
63+
// could easily strip those instructions.
5064
return collect([$this->dim($top_row), $middle_row, $this->dim($bottom_row)])->implode(PHP_EOL);
5165
}
5266
}

0 commit comments

Comments
 (0)