File tree Expand file tree Collapse file tree 2 files changed +14
-7
lines changed Expand file tree Collapse file tree 2 files changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -136,13 +136,9 @@ public function addLineBreak(string $breakChar = ' ', int $lines = 1) : self
136
136
return $ this ;
137
137
}
138
138
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
140
140
{
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 ));
146
142
147
143
return $ this ;
148
144
}
Original file line number Diff line number Diff line change @@ -27,17 +27,23 @@ class AsciiArtItem implements MenuItemInterface
27
27
*/
28
28
private $ position ;
29
29
30
+ /**
31
+ * @var string
32
+ */
33
+ private $ alternateText ;
34
+
30
35
/**
31
36
* @var int
32
37
*/
33
38
private $ artLength ;
34
39
35
- public function __construct (string $ text , string $ position = self ::POSITION_CENTER )
40
+ public function __construct (string $ text , string $ position = self ::POSITION_CENTER , string $ alt = '' )
36
41
{
37
42
Assertion::inArray ($ position , [self ::POSITION_CENTER , self ::POSITION_RIGHT , self ::POSITION_LEFT ]);
38
43
39
44
$ this ->text = $ text ;
40
45
$ this ->position = $ position ;
46
+ $ this ->alternateText = $ alt ;
41
47
$ this ->artLength = max (array_map ('mb_strlen ' , explode ("\n" , $ text )));
42
48
}
43
49
@@ -46,6 +52,11 @@ public function __construct(string $text, string $position = self::POSITION_CENT
46
52
*/
47
53
public function getRows (MenuStyle $ style , bool $ selected = false ) : array
48
54
{
55
+ if ($ this ->artLength > $ style ->getContentWidth ()) {
56
+ $ alternate = new StaticItem ($ this ->alternateText );
57
+ return $ alternate ->getRows ($ style , false );
58
+ }
59
+
49
60
return array_map (function ($ row ) use ($ style ) {
50
61
$ length = mb_strlen ($ row );
51
62
You can’t perform that action at this time.
0 commit comments