public static stripAnsiEscapeSequence ( string $str ) : string | ||
$str | string | |
return | string |
/** * 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); }
/** * @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)); }