Skip to content

Commit 0a65e13

Browse files
committed
hide overflow
1 parent 7ae1ab6 commit 0a65e13

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

src/ExplorerPrompt.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ protected function calculateSelectedValue(): void
307307
if (empty($keys)) {
308308
$this->selectedValue = null;
309309
} else {
310-
$this->selectedValue = array_search($filteredItems[$keys[$this->highlighted]], $filteredItems);
310+
$this->selectedValue = array_search($filteredItems[$keys[$this->highlighted]], $filteredItems, true);
311311
}
312312
}
313313

@@ -350,7 +350,7 @@ protected function keyEnter(): void
350350
$this->submit();
351351
}
352352

353-
protected function keyForwardSlash()
353+
protected function keyForwardSlash(): void
354354
{
355355
if ($this->filteringEnabled) {
356356
$this->setFilteringState();
@@ -401,7 +401,7 @@ protected function setActiveState(): self
401401
return $this;
402402
}
403403

404-
protected function recalculateScroll()
404+
protected function recalculateScroll(): void
405405
{
406406
$this->setVisibleItems($this->userScroll);
407407
}

src/Themes/Default/ExplorerPromptRenderer.php

+15-11
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public function __invoke(ExplorerPrompt $prompt): string
5050
return $this->prompt->highlighted === $index ? $this->inverse($label) : $label;
5151
});
5252

53+
$this->minWidth = $this->prompt->terminal()->cols();
54+
5355
if ($this->prompt->header) {
5456
$body->prepend(
5557
$this->makeColumn(
@@ -59,8 +61,6 @@ public function __invoke(ExplorerPrompt $prompt): string
5961
);
6062
}
6163

62-
$this->minWidth = $this->prompt->terminal()->cols();
63-
6464
$this->when(
6565
$this->prompt->showFilterBox(),
6666
fn() => $this->box(
@@ -77,13 +77,17 @@ public function __invoke(ExplorerPrompt $prompt): string
7777

7878
protected function makeColumn(array $values): string
7979
{
80-
return collect($values)
81-
->values()
82-
->map(function ($item, $index) {
83-
$width = $this->calculateColumnWidth($index);
84-
return mb_str_pad($item ?? '', $width, ' ', $this->prompt->getColumnAlignment($index)->toPadding());
85-
})
86-
->join(' ');
80+
return mb_substr(
81+
collect($values)
82+
->values()
83+
->map(function ($item, $index) {
84+
$width = $this->calculateColumnWidth($index);
85+
return mb_str_pad($item ?? '', $width, ' ', $this->prompt->getColumnAlignment($index)->toPadding());
86+
})
87+
->join(' '),
88+
0,
89+
$this->widthToFill()
90+
);
8791
}
8892

8993
protected function getTitle(): string
@@ -98,7 +102,7 @@ protected function getTitle(): string
98102

99103
protected function widthToFill(): int
100104
{
101-
return $this->prompt->terminal()->cols() - 11;
105+
return $this->prompt->terminal()->cols() - 8;
102106
}
103107

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

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

119123
protected function columnCount(): int

0 commit comments

Comments
 (0)