write() public method

The string is formatted before it is written to the output.
public write ( string $string, integer $flags = null )
$string string The string to write.
$flags integer The flags. One of {@link VERBOSE}, {@link VERY_VERBOSE} and {@link DEBUG}.
Beispiel #1
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);
     $textWidth = $io->getTerminalDimensions()->getWidth() - 1 - $indentation;
     // TODO replace wordwrap() by implementation that is aware of format codes
     $text = preg_replace("~\n(?!\n)~", "\n" . $linePrefix, wordwrap($this->text, $textWidth));
     $io->write($linePrefix . rtrim($text) . "\n");
 }
 /**
  * {@inheritdoc}
  */
 public function handle(Args $args, IO $io)
 {
     if ($this->processLauncher->isSupported()) {
         if (!$this->lessBinary) {
             $this->lessBinary = $this->executableFinder->find('less');
         }
         if ($this->lessBinary) {
             return $this->processLauncher->launchProcess(escapeshellcmd($this->lessBinary) . ' %path%', array('path' => $this->path), false);
         }
     }
     $io->write(file_get_contents($this->path));
     return 0;
 }
Beispiel #3
0
 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;
     }
 }
Beispiel #4
0
 private static function drawBorder(IO $io, array $columnLengths, $indentation, $lineChar, $crossingLChar, $crossingCChar, $crossingRChar, Style $style = null)
 {
     $line = str_repeat(' ', $indentation);
     $line .= $crossingLChar;
     for ($i = 0, $l = count($columnLengths); $i < $l; ++$i) {
         $line .= str_repeat($lineChar, $columnLengths[$i]);
         $line .= $i < $l - 1 ? $crossingCChar : $crossingRChar;
     }
     // Remove trailing space
     $line = rtrim($line);
     // Render only non-empty separators
     if ($line) {
         $io->write($io->format($line, $style) . "\n");
     }
 }
Beispiel #5
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");
 }
Beispiel #6
0
 /**
  * Renders the empty line.
  *
  * @param IO  $io          The I/O.
  * @param int $indentation The number of spaces to indent.
  */
 public function render(IO $io, $indentation = 0)
 {
     // Indentation is ignored for empty lines
     $io->write("\n");
 }