removeFormat() public method

public removeFormat ( $string )
コード例 #1
0
ファイル: IOOutput.php プロジェクト: webmozart/console
 private function doWrite($message, $type)
 {
     switch ($type) {
         case self::OUTPUT_PLAIN:
             $this->io->write($this->io->removeFormat($message));
             break;
         case self::OUTPUT_RAW:
             $this->io->writeRaw($message);
             break;
         default:
             $this->io->write($message);
             break;
     }
 }
コード例 #2
0
 /**
  * Renders the paragraph.
  *
  * @param IO  $io          The I/O.
  * @param int $indentation The number of spaces to indent.
  */
 public function render(IO $io, $indentation = 0)
 {
     $linePrefix = str_repeat(' ', $indentation);
     $visibleLabel = $io->removeFormat($this->label);
     $styleTagLength = strlen($this->label) - strlen($visibleLabel);
     $textOffset = $this->aligned && $this->alignment ? $this->alignment->getTextOffset() - $indentation : 0;
     $textOffset = max($textOffset, strlen($visibleLabel) + $this->padding);
     $textPrefix = str_repeat(' ', $textOffset);
     // 1 trailing space
     $textWidth = $io->getTerminalDimensions()->getWidth() - 1 - $textOffset - $indentation;
     // TODO replace wordwrap() by implementation that is aware of format codes
     $text = str_replace("\n", "\n" . $linePrefix . $textPrefix, wordwrap($this->text, $textWidth));
     // Add the total length of the style tags ("<b>", ...)
     $labelWidth = $textOffset + $styleTagLength;
     $io->write(rtrim(sprintf("%s%-{$labelWidth}s%s", $linePrefix, $this->label, rtrim($text))) . "\n");
 }