File tree Expand file tree Collapse file tree 3 files changed +37
-9
lines changed Expand file tree Collapse file tree 3 files changed +37
-9
lines changed Original file line number Diff line number Diff line change @@ -376,13 +376,6 @@ protected function drawMenuItem(MenuItemInterface $item, bool $selected = false)
376
376
}
377
377
378
378
return array_map (function ($ row ) use ($ invertedColour , $ notInvertedColour , $ borderColour ) {
379
-
380
- $ rightPadding = $ this ->style ->getRightHandPadding (mb_strlen (s::stripAnsiEscapeSequence ($ row )));
381
-
382
- if ($ rightPadding < 0 ) {
383
- $ rightPadding = 0 ;
384
- }
385
-
386
379
return sprintf (
387
380
"%s%s%s%s%s%s%s%s%s%s%s%s%s \n" ,
388
381
str_repeat (' ' , $ this ->style ->getMargin ()),
@@ -392,7 +385,7 @@ protected function drawMenuItem(MenuItemInterface $item, bool $selected = false)
392
385
$ invertedColour ,
393
386
str_repeat (' ' , $ this ->style ->getPadding ()),
394
387
$ row ,
395
- str_repeat (' ' , $ rightPadding ),
388
+ str_repeat (' ' , $ this -> style -> getRightHandPadding ( mb_strlen (s:: stripAnsiEscapeSequence ( $ row ))) ),
396
389
$ notInvertedColour ,
397
390
$ borderColour ,
398
391
str_repeat (' ' , $ this ->style ->getBorderRightWidth ()),
Original file line number Diff line number Diff line change @@ -409,7 +409,13 @@ public function getContentWidth() : int
409
409
*/
410
410
public function getRightHandPadding (int $ contentLength ) : int
411
411
{
412
- return $ this ->getContentWidth () - $ contentLength + $ this ->getPadding ();
412
+ $ rightPadding = $ this ->getContentWidth () - $ contentLength + $ this ->getPadding ();
413
+
414
+ if ($ rightPadding < 0 ) {
415
+ $ rightPadding = 0 ;
416
+ }
417
+
418
+ return $ rightPadding ;
413
419
}
414
420
415
421
public function getSelectedMarker () : string
Original file line number Diff line number Diff line change @@ -301,6 +301,35 @@ public function testRightHandPaddingCalculation() : void
301
301
static ::assertSame (241 , $ style ->getRightHandPadding (50 ));
302
302
}
303
303
304
+ public function testRightHandPaddingReturnsZeroWhenContentLengthTooLong () : void
305
+ {
306
+ $ style = $ this ->getMenuStyle ();
307
+ $ style ->setPadding (0 );
308
+ $ style ->setMargin (0 );
309
+ $ style ->setBorder (0 );
310
+
311
+ $ style ->setWidth (100 );
312
+
313
+ self ::assertEquals (0 , $ style ->getRightHandPadding (100 ));
314
+ self ::assertEquals (0 , $ style ->getRightHandPadding (150 ));
315
+ }
316
+
317
+ public function testRightHandPaddingReturnsZeroWhenContentLengthTooLongBecauseOfBorder () : void
318
+ {
319
+ $ style = $ this ->getMenuStyle ();
320
+ $ style ->setPadding (10 );
321
+ $ style ->setMargin (0 );
322
+ $ style ->setBorder (10 );
323
+
324
+ $ style ->setWidth (100 );
325
+
326
+ self ::assertEquals (11 , $ style ->getRightHandPadding (59 ));
327
+ self ::assertEquals (10 , $ style ->getRightHandPadding (60 ));
328
+ self ::assertEquals (0 , $ style ->getRightHandPadding (70 ));
329
+ self ::assertEquals (0 , $ style ->getRightHandPadding (71 ));
330
+ self ::assertEquals (0 , $ style ->getRightHandPadding (100 ));
331
+ }
332
+
304
333
public function testMargin () : void
305
334
{
306
335
$ style = $ this ->getMenuStyle ();
You can’t perform that action at this time.
0 commit comments