Skip to content

Commit 74c1e9b

Browse files
authored
Adding alternateText to AsciiArtItem
1 parent 821a81a commit 74c1e9b

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/MenuItem/AsciiArtItem.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,23 @@ class AsciiArtItem implements MenuItemInterface
2727
*/
2828
private $position;
2929

30+
/**
31+
* @var string
32+
*/
33+
private $alternateText;
34+
3035
/**
3136
* @var int
3237
*/
3338
private $artLength;
3439

35-
public function __construct(string $text, string $position = self::POSITION_CENTER)
40+
public function __construct(string $text, string $position = self::POSITION_CENTER, string $alt = '')
3641
{
3742
Assertion::inArray($position, [self::POSITION_CENTER, self::POSITION_RIGHT, self::POSITION_LEFT]);
3843

3944
$this->text = $text;
4045
$this->position = $position;
46+
$this->alternateText = $alt;
4147
$this->artLength = max(array_map('mb_strlen', explode("\n", $text)));
4248
}
4349

@@ -46,6 +52,11 @@ public function __construct(string $text, string $position = self::POSITION_CENT
4652
*/
4753
public function getRows(MenuStyle $style, bool $selected = false) : array
4854
{
55+
if ($this->artLength > $style->getContentWidth()) {
56+
$alternate = new StaticItem($this->alternateText);
57+
return $alternate->getRows($style, false);
58+
}
59+
4960
return array_map(function ($row) use ($style) {
5061
$length = mb_strlen($row);
5162

0 commit comments

Comments
 (0)