diff --git a/src/Printer/Console.php b/src/Printer/Console.php index 4747c24..b831148 100644 --- a/src/Printer/Console.php +++ b/src/Printer/Console.php @@ -25,7 +25,7 @@ public function __construct(Highlighter $highlighter) public function printData(OutputInterface $output, HintList $hintList, array $detections): void { - $length = (int) (`tput cols` ?: self::DEFAULT_LINE_LENGTH); + $length = (int) ($this->getCurrentShellWidth() ?: self::DEFAULT_LINE_LENGTH); $separator = str_repeat('-', $length); $output->writeln(PHP_EOL . $separator . PHP_EOL); @@ -83,4 +83,16 @@ private function groupDetectionResultPerFile(array $detections): array return $groupedResult; } + + private function getCurrentShellWidth(): ?int + { + $shellOutput = ''; + $returnCode = 0; + exec("tput cols 2>&1", $shellOutput, $returnCode); + if (empty($shellOutput)) { + return null; + } + + return (int) current($shellOutput); + } }