getTerminalDimensions() public method

Returns the dimensions of the terminal.
public getTerminalDimensions ( ) : Rectangle
return Webmozart\Console\UI\Rectangle The terminal dimensions.
Esempio n. 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");
 }
Esempio n. 2
0
 private function printBox(IO $io, Exception $exception)
 {
     $screenWidth = $io->getTerminalDimensions()->getWidth() - 1;
     $boxWidth = 0;
     $boxLines = array_merge(array(sprintf('[%s]', get_class($exception))), explode("\n", wordwrap($exception->getMessage(), $screenWidth - 4)));
     foreach ($boxLines as $line) {
         $boxWidth = max($boxWidth, strlen($line));
     }
     // TODO handle $boxWidth > $screenWidth
     $emptyLine = sprintf('<error>%s</error>', str_repeat(' ', $boxWidth + 4));
     $io->errorLine('');
     $io->errorLine('');
     $io->errorLine($emptyLine);
     foreach ($boxLines as $boxLine) {
         $padding = str_repeat(' ', max(0, $boxWidth - strlen($boxLine)));
         $io->errorLine(sprintf('<error>  %s%s  </error>', $boxLine, $padding));
     }
     $io->errorLine($emptyLine);
     $io->errorLine('');
     $io->errorLine('');
 }
Esempio n. 3
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");
 }
Esempio n. 4
0
 /**
  * Renders the table.
  *
  * @param IO  $io          The I/O.
  * @param int $indentation The number of spaces to indent.
  */
 public function render(IO $io, $indentation = 0)
 {
     // Is the table empty?
     if (!$this->rows) {
         return;
     }
     $screenWidth = $io->getTerminalDimensions()->getWidth();
     $excessColumnWidth = max(StringUtil::getLength(sprintf($this->style->getHeaderCellFormat(), ''), $io), StringUtil::getLength(sprintf($this->style->getCellFormat(), ''), $io));
     $wrapper = $this->getCellWrapper($io, $screenWidth, $excessColumnWidth, $indentation);
     $this->renderRows($io, $wrapper->getWrappedRows(), $wrapper->getColumnLengths(), $excessColumnWidth, $indentation);
 }