You are here

public function Console::centerText in Site Audit 8.3

Take text and center it horizontally in the console.

1 call to Console::centerText()
Console::render in src/Renderer/Console.php

File

src/Renderer/Console.php, line 92

Class

Console

Namespace

Drupal\site_audit\Renderer

Code

public function centerText(string $text) {
  $width = (new Terminal())
    ->getWidth();
  $strlen = $this->formatter
    ->strlenWithoutDecoration($this->output
    ->getFormatter(), $text);
  $spaceCount = ($width - $strlen) / 2;
  for ($i = 0; $i < $spaceCount; $i++) {
    $text = ' ' . $text;
  }
  $this->output
    ->writeln($text);
}