Author: Michael Woodward (mikeymike.mw@gmail.com)
Example #1
0
 /**
  * The output text for the item
  *
  * @param MenuStyle $style
  * @param bool $selected
  * @return array
  */
 public function getRows(MenuStyle $style, $selected = false)
 {
     return array_map(function ($row) use($style) {
         $length = mb_strlen($row);
         $padding = $style->getContentWidth() - $length;
         switch ($this->position) {
             case self::POSITION_LEFT:
                 return $row;
                 break;
             case self::POSITION_RIGHT:
                 $row = rtrim($row);
                 $padding = $padding - ($this->artLength - mb_strlen($row));
                 $row = sprintf('%s%s', str_repeat(' ', $padding), $row);
                 break;
             case self::POSITION_CENTER:
             default:
                 $row = rtrim($row);
                 $padding = $padding - ($this->artLength - mb_strlen($row));
                 $left = ceil($padding / 2);
                 $right = $padding - $left;
                 $row = sprintf('%s%s%s', str_repeat(' ', $left), $row, str_repeat(' ', $right));
                 break;
         }
         return $row;
     }, explode("\n", $this->text));
 }
Example #2
0
 /**
  * Draw a menu item
  *
  * @param MenuItemInterface $item
  * @param bool|false $selected
  * @return array
  */
 protected function drawMenuItem(MenuItemInterface $item, $selected = false)
 {
     $rows = $item->getRows($this->style, $selected);
     $setColour = $selected ? $this->style->getSelectedSetCode() : $this->style->getUnselectedSetCode();
     $unsetColour = $selected ? $this->style->getSelectedUnsetCode() : $this->style->getUnselectedUnsetCode();
     return array_map(function ($row) use($setColour, $unsetColour) {
         return sprintf("%s%s%s%s%s%s%s\n\r", str_repeat(' ', $this->style->getMargin()), $setColour, str_repeat(' ', $this->style->getPadding()), $row, str_repeat(' ', $this->style->getRightHandPadding(mb_strlen(s::stripAnsiEscapeSequence($row)))), $unsetColour, str_repeat(' ', $this->style->getMargin()));
     }, $rows);
 }
Example #3
0
 /**
  * Draw a menu item
  *
  * @param MenuItemInterface $item
  * @param bool|false $selected
  */
 protected function drawMenuItem(MenuItemInterface $item, $selected = false)
 {
     $rows = $item->getRows($this->style, $selected);
     $setColour = $selected ? $this->style->getSelectedSetCode() : $this->style->getUnselectedSetCode();
     $unsetColour = $selected ? $this->style->getSelectedUnsetCode() : $this->style->getUnselectedUnsetCode();
     foreach ($rows as $row) {
         echo sprintf("%s%s%s%s%s%s%s", str_repeat(' ', $this->style->getMargin()), $setColour, str_repeat(' ', $this->style->getPadding()), $row, str_repeat(' ', $this->style->getRightHandPadding(mb_strlen($row))), $unsetColour, str_repeat(' ', $this->style->getMargin()));
         echo "\n\r";
     }
 }
Example #4
0
 /**
  * The output text for the item
  *
  * @param MenuStyle $style
  * @param bool $selected
  * @return array
  */
 public function getRows(MenuStyle $style, $selected = false)
 {
     $marker = sprintf("%s ", $style->getMarker($selected));
     $length = $style->getDisplaysExtra() ? $style->getContentWidth() - (mb_strlen($style->getItemExtra()) + 2) : $style->getContentWidth();
     $rows = explode("\n", StringUtil::wordwrap(sprintf('%s%s', $marker, $this->text), $length, sprintf("\n%s", str_repeat(' ', mb_strlen($marker)))));
     return array_map(function ($row, $key) use($style, $marker, $length) {
         $text = $this->disabled ? $style->getDisabledItemText($row) : $row;
         if ($key === 0) {
             return $this->showItemExtra ? sprintf('%s%s  %s', $text, str_repeat(' ', $length - mb_strlen($row)), $style->getItemExtra()) : $text;
         }
         return $text;
     }, $rows, array_keys($rows));
 }
Example #5
0
 /**
  * The output text for the item
  *
  * @param MenuStyle $style
  * @param bool $selected
  * @return array
  */
 public function getRows(MenuStyle $style, $selected = false)
 {
     return explode("\n", StringUtil::wordwrap($this->text, $style->getContentWidth()));
 }
Example #6
0
 /**
  * The output text for the item
  *
  * @param MenuStyle $style
  * @param bool $selected
  * @return array
  */
 public function getRows(MenuStyle $style, $selected = false)
 {
     return explode("\n", rtrim(str_repeat(sprintf("%s\n", mb_substr(str_repeat($this->breakChar, $style->getContentWidth()), 0, $style->getContentWidth())), $this->lines)));
 }
Example #7
0
 /**
  * @param string $colour
  * @return $this
  */
 public function setForegroundColour($colour)
 {
     Assertion::inArray($colour, MenuStyle::getAvailableColours());
     $this->style['fg'] = $colour;
     return $this;
 }
Example #8
0
 /**
  * Recursively drop back to the parents menu style
  * when the current menu has a parent and has no changes
  *
  * @return MenuStyle
  */
 private function getMenuStyle()
 {
     if (null === $this->parent) {
         return $this->buildStyle();
     }
     if ($this->style !== MenuStyle::getDefaultStyleValues()) {
         return $this->buildStyle();
     }
     return $this->parent->getMenuStyle();
 }
Example #9
0
 /**
  * Write an empty row
  */
 protected function emptyRow()
 {
     $this->write(sprintf("%s%s%s%s%s\n", $this->style->getUnselectedSetCode(), str_repeat(' ', $this->style->getPadding()), str_repeat(' ', mb_strlen($this->text)), str_repeat(' ', $this->style->getPadding()), $this->style->getUnselectedUnsetCode()));
 }