Author: Michael Woodward (mikeymike.mw@gmail.com)
Ejemplo n.º 1
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) {
         if ($key === 0) {
             return $this->showItemExtra ? sprintf('%s%s  %s', $row, str_repeat(' ', $length - mb_strlen($row)), $style->getItemExtra()) : $row;
         }
         return $row;
     }, $rows, array_keys($rows));
 }
Ejemplo n.º 2
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()));
 }
Ejemplo n.º 3
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);
 }
Ejemplo n.º 4
0
 /**
  * @param OutputInterface $output
  * @param $string
  * @param array $style
  */
 private function fullWidthBlock(OutputInterface $output, $string, array $style)
 {
     $stringLength = mb_strlen(StringUtil::stripAnsiEscapeSequence($string));
     $stringHalfLength = $stringLength / 2;
     $widthHalfLength = ceil($this->terminal->getWidth() / 2);
     $start = ceil($widthHalfLength - $stringHalfLength);
     $output->writeLine($this->style(str_repeat(' ', $this->terminal->getWidth()), $style));
     $output->writeLine($this->style(sprintf('%s%s%s', str_repeat(' ', $start), $string, str_repeat(' ', $this->terminal->getWidth() - $stringLength - $start)), $style));
     $output->writeLine($this->style(str_repeat(' ', $this->terminal->getWidth()), $style));
 }