Skip to content

Commit 5c0b307

Browse files
authored
Merge pull request #102 from Lynesth/patch-15
Fix centering ascii art
2 parents dc3a2b7 + cbad9d2 commit 5c0b307

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/MenuItem/AsciiArtItem.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ public function getRows(MenuStyle $style, bool $selected = false) : array
7373
break;
7474
case self::POSITION_CENTER:
7575
default:
76-
$row = rtrim($row);
77-
$padding = $padding - ($this->artLength - mb_strlen($row));
76+
$padding = $padding - ($this->artLength - $length);
7877
$left = ceil($padding/2);
7978
$right = $padding - $left;
8079
$row = sprintf('%s%s%s', str_repeat(' ', $left), $row, str_repeat(' ', $right));

test/MenuItem/AsciiArtItemTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ public function testGetRowsCenterAligned() : void
9696
],
9797
$item->getRows($menuStyle)
9898
);
99+
100+
$item = new AsciiArtItem(" // \n//////////", AsciiArtItem::POSITION_CENTER);
101+
$this->assertEquals(
102+
[
103+
" // ",
104+
"//////////",
105+
],
106+
$item->getRows($menuStyle)
107+
);
99108
}
100109

101110
public function testGetRowsCenterAlignedWithOddWidth() : void
@@ -115,6 +124,15 @@ public function testGetRowsCenterAlignedWithOddWidth() : void
115124
],
116125
$item->getRows($menuStyle)
117126
);
127+
128+
$item = new AsciiArtItem(" // \n//////////", AsciiArtItem::POSITION_CENTER);
129+
$this->assertEquals(
130+
[
131+
" // ",
132+
" //////////",
133+
],
134+
$item->getRows($menuStyle)
135+
);
118136
}
119137

120138
public function testHideAndShowItemExtraHasNoEffect() : void

0 commit comments

Comments
 (0)