Skip to content

Commit

Permalink
hide overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
knobik committed Mar 22, 2024
1 parent 7ae1ab6 commit 0a65e13
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/ExplorerPrompt.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ protected function calculateSelectedValue(): void
if (empty($keys)) {
$this->selectedValue = null;
} else {
$this->selectedValue = array_search($filteredItems[$keys[$this->highlighted]], $filteredItems);
$this->selectedValue = array_search($filteredItems[$keys[$this->highlighted]], $filteredItems, true);
}
}

Expand Down Expand Up @@ -350,7 +350,7 @@ protected function keyEnter(): void
$this->submit();
}

protected function keyForwardSlash()
protected function keyForwardSlash(): void
{
if ($this->filteringEnabled) {
$this->setFilteringState();
Expand Down Expand Up @@ -401,7 +401,7 @@ protected function setActiveState(): self
return $this;
}

protected function recalculateScroll()
protected function recalculateScroll(): void
{
$this->setVisibleItems($this->userScroll);
}
Expand Down
26 changes: 15 additions & 11 deletions src/Themes/Default/ExplorerPromptRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public function __invoke(ExplorerPrompt $prompt): string
return $this->prompt->highlighted === $index ? $this->inverse($label) : $label;
});

$this->minWidth = $this->prompt->terminal()->cols();

if ($this->prompt->header) {
$body->prepend(
$this->makeColumn(
Expand All @@ -59,8 +61,6 @@ public function __invoke(ExplorerPrompt $prompt): string
);
}

$this->minWidth = $this->prompt->terminal()->cols();

$this->when(
$this->prompt->showFilterBox(),
fn() => $this->box(
Expand All @@ -77,13 +77,17 @@ public function __invoke(ExplorerPrompt $prompt): string

protected function makeColumn(array $values): string
{
return collect($values)
->values()
->map(function ($item, $index) {
$width = $this->calculateColumnWidth($index);
return mb_str_pad($item ?? '', $width, ' ', $this->prompt->getColumnAlignment($index)->toPadding());
})
->join(' ');
return mb_substr(
collect($values)
->values()
->map(function ($item, $index) {
$width = $this->calculateColumnWidth($index);
return mb_str_pad($item ?? '', $width, ' ', $this->prompt->getColumnAlignment($index)->toPadding());
})
->join(' '),
0,
$this->widthToFill()
);
}

protected function getTitle(): string
Expand All @@ -98,7 +102,7 @@ protected function getTitle(): string

protected function widthToFill(): int
{
return $this->prompt->terminal()->cols() - 11;
return $this->prompt->terminal()->cols() - 8;
}

protected function calculateColumnWidth(int $column): int
Expand All @@ -113,7 +117,7 @@ protected function calculateColumnWidth(int $column): int
$columnsWithCustomWidth = $this->prompt->countColumnsWithFixedWidth();
$widthPerColumn = floor($widthToFill / ($this->columnCount($this->prompt) - $columnsWithCustomWidth));

return $this->prompt->getColumnMinWidth($column) + $widthPerColumn;
return $this->prompt->getColumnMinWidth($column) + ($widthPerColumn > 0 ? $widthPerColumn : 0);
}

protected function columnCount(): int
Expand Down

0 comments on commit 0a65e13

Please sign in to comment.