Skip to content

Commit

Permalink
Display count of selected items when scrolling (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
jessarcher authored Sep 8, 2023
1 parent 79bff71 commit 9f7800c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Themes/Default/Concerns/DrawsBoxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ protected function box(
string $body,
string $footer = '',
string $color = 'gray',
string $info = '',
): self {
$this->minWidth = min($this->minWidth, Prompt::terminal()->cols() - 6);

Expand All @@ -31,23 +32,23 @@ protected function box(
);

$topBorder = str_repeat('', $width - mb_strwidth($this->stripEscapeSequences($title)));
$bottomBorder = str_repeat('', $width + 2);

$this->line("{$this->{$color}('')} {$title} {$this->{$color}($topBorder.'')}");

$bodyLines->each(function ($line) use ($width, $color) {
$this->line("{$this->{$color}('')} {$this->pad($line, $width)} {$this->{$color}('')}");
});

if ($footerLines->isNotEmpty()) {
$this->line($this->{$color}(''.$bottomBorder.''));
$this->line($this->{$color}(''.str_repeat('', $width + 2).''));

$footerLines->each(function ($line) use ($width, $color) {
$this->line("{$this->{$color}('')} {$this->pad($line, $width)} {$this->{$color}('')}");
});
}

$this->line($this->{$color}(''.$bottomBorder.''));
$this->line($this->{$color}(''.str_repeat(
'', $info ? ($width - mb_strwidth($this->stripEscapeSequences($info))) : ($width + 2)
).($info ? " {$info} " : '').''));

return $this;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Themes/Default/MultiSelectPromptRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ public function __invoke(MultiSelectPrompt $prompt): string
$this->truncate($prompt->label, $prompt->terminal()->cols() - 6),
$this->renderOptions($prompt),
color: 'yellow',
info: count($prompt->options) > $prompt->scroll ? (count($prompt->value()).' selected') : '',
)
->warning($this->truncate($prompt->error, $prompt->terminal()->cols() - 5)),

default => $this
->box(
$this->cyan($this->truncate($prompt->label, $prompt->terminal()->cols() - 6)),
$this->renderOptions($prompt),
info: count($prompt->options) > $prompt->scroll ? (count($prompt->value()).' selected') : '',
)
->when(
$prompt->hint,
Expand Down

0 comments on commit 9f7800c

Please sign in to comment.