1818use PhpSchool \CliMenu \MenuStyle ;
1919use PhpSchool \CliMenu \Style \CheckboxStyle ;
2020use PhpSchool \CliMenu \Style \RadioStyle ;
21+ use PhpSchool \CliMenu \Style \SelectableStyle ;
2122use PhpSchool \CliMenu \Terminal \TerminalFactory ;
2223use PhpSchool \Terminal \Terminal ;
2324
@@ -89,12 +90,12 @@ public function __construct(Terminal $terminal = null)
8990 $ this ->style = new MenuStyle ($ this ->terminal );
9091 $ this ->menu = new CliMenu (null , [], $ this ->terminal , $ this ->style );
9192 }
92-
93+
9394 public static function newSubMenu (Terminal $ terminal ) : self
9495 {
9596 $ instance = new self ($ terminal );
9697 $ instance ->subMenu = true ;
97-
98+
9899 return $ instance ;
99100 }
100101
@@ -396,22 +397,25 @@ public function setMargin(int $margin) : self
396397 public function setUnselectedMarker (string $ marker ) : self
397398 {
398399 $ this ->style ->setUnselectedMarker ($ marker );
400+ $ this ->menu ->getSelectableStyle ()->setUnselectedMarker ($ marker );
399401
400402 return $ this ;
401403 }
402404
403405 public function setSelectedMarker (string $ marker ) : self
404406 {
405407 $ this ->style ->setSelectedMarker ($ marker );
408+ $ this ->menu ->getSelectableStyle ()->setSelectedMarker ($ marker );
406409
407410 return $ this ;
408411 }
409412
410413 public function setItemExtra (string $ extra ) : self
411414 {
412415 $ this ->style ->setItemExtra ($ extra );
416+ $ this ->menu ->getSelectableStyle ()->setItemExtra ($ extra );
413417
414- //if we customise item extra, it means we most likely want to display it
418+ // if we customise item extra, it means we most likely want to display it
415419 $ this ->displayExtra ();
416420
417421 return $ this ;
@@ -434,7 +438,7 @@ public function setBorder(int $top, $right = null, $bottom = null, $left = null,
434438 public function setBorderTopWidth (int $ width ) : self
435439 {
436440 $ this ->style ->setBorderTopWidth ($ width );
437-
441+
438442 return $ this ;
439443 }
440444
@@ -497,6 +501,7 @@ public function disableDefaultItems() : self
497501 public function displayExtra () : self
498502 {
499503 $ this ->style ->setDisplaysExtra (true );
504+ $ this ->menu ->getSelectableStyle ()->setDisplaysExtra (true );
500505
501506 return $ this ;
502507 }
@@ -507,7 +512,7 @@ private function itemsHaveExtra(array $items) : bool
507512 return $ item ->showsItemExtra ();
508513 }));
509514 }
510-
515+
511516 public function build () : CliMenu
512517 {
513518 if (!$ this ->disableDefaultItems ) {
@@ -563,6 +568,25 @@ public function modifyRadioStyle(callable $itemCallable) : self
563568 return $ this ;
564569 }
565570
571+ public function getSelectableStyle () : SelectableStyle
572+ {
573+ return $ this ->menu ->getSelectableStyle ();
574+ }
575+
576+ public function setSelectableStyle (SelectableStyle $ style ) : self
577+ {
578+ $ this ->menu ->setSelectableStyle ($ style );
579+
580+ return $ this ;
581+ }
582+
583+ public function modifySelectableStyle (callable $ itemCallable ) : self
584+ {
585+ $ itemCallable ($ this ->menu ->getSelectableStyle ());
586+
587+ return $ this ;
588+ }
589+
566590 /**
567591 * Pass styles from current menu to sub-menu
568592 * only if sub-menu style has not be customized
@@ -584,6 +608,12 @@ private function propagateStyles(CliMenu $menu, array $items = [])
584608 $ item ->setStyle (clone $ menu ->getRadioStyle ());
585609 }
586610
611+ if ($ item instanceof SelectableItem
612+ && !$ item ->getStyle ()->hasChangedFromDefaults ()
613+ ) {
614+ $ item ->setStyle (clone $ menu ->getSelectableStyle ());
615+ }
616+
587617 // Apply current style to children, if they are not customized
588618 if ($ item instanceof MenuMenuItem) {
589619 $ subMenu = $ item ->getSubMenu ();
@@ -600,6 +630,10 @@ private function propagateStyles(CliMenu $menu, array $items = [])
600630 $ subMenu ->setRadioStyle (clone $ menu ->getRadioStyle ());
601631 }
602632
633+ if (!$ subMenu ->getSelectableStyle ()->hasChangedFromDefaults ()) {
634+ $ subMenu ->setSelectableStyle (clone $ menu ->getSelectableStyle ());
635+ }
636+
603637 $ this ->propagateStyles ($ subMenu );
604638 }
605639
0 commit comments