Skip to content

Commit c799acf

Browse files
authored
Merge pull request #93 from Lynesth/patch-11
Adds alternateText to AsciiArtItem
2 parents 821a81a + ff9df06 commit c799acf

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/CliMenuBuilder.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,9 @@ public function addLineBreak(string $breakChar = ' ', int $lines = 1) : self
136136
return $this;
137137
}
138138

139-
public function addAsciiArt(string $art, string $position = AsciiArtItem::POSITION_CENTER) : self
139+
public function addAsciiArt(string $art, string $position = AsciiArtItem::POSITION_CENTER, string $alt) : self
140140
{
141-
$asciiArtItem = new AsciiArtItem($art, $position);
142-
143-
if ($asciiArtItem->getArtLength() <= $this->getMenuStyle()->getContentWidth()) {
144-
$this->addMenuItem($asciiArtItem);
145-
}
141+
$this->addMenuItem(new AsciiArtItem($art, $position, $alt));
146142

147143
return $this;
148144
}

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)