Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #221 from niels-nijens/improve-terminal-width-dete…
Browse files Browse the repository at this point in the history
…ction

Improve terminal width detection
  • Loading branch information
niels-nijens committed Nov 16, 2016
2 parents 9e6cbed + 722615a commit 9291256
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
17 changes: 17 additions & 0 deletions src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,23 @@ public function getHelp()
return Accompli::LOGO.parent::getHelp();
}

/**
* Returns the terminal width.
*
* @return int
*/
public function getTerminalWidth()
{
$terminalDimensions = $this->getTerminalDimensions();

$width = 120;
if (isset($terminalDimensions[0]) && $terminalDimensions[0] > 0) {
$width = $terminalDimensions[0];
}

return $width;
}

/**
* Returns the array with default commands.
*
Expand Down
10 changes: 2 additions & 8 deletions src/Console/Helper/TitleBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Accompli\Console\Helper;

use Symfony\Component\Console\Application;
use Accompli\Console\Application;
use Symfony\Component\Console\Helper\Helper;
use Symfony\Component\Console\Output\OutputInterface;

Expand Down Expand Up @@ -103,13 +103,7 @@ public function render()
private function getTerminalWidth()
{
$application = new Application();
$terminalDimensions = $application->getTerminalDimensions();

$width = 120;
if (isset($terminalDimensions[0])) {
$width = $terminalDimensions[0];
}

return $width;
return $application->getTerminalWidth();
}
}
10 changes: 2 additions & 8 deletions src/Console/Logger/ConsoleLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Accompli\Console\Logger;

use Accompli\Console\Application;
use Accompli\Console\Formatter\OutputFormatter;
use Accompli\Task\TaskInterface;
use Psr\Log\AbstractLogger;
use Psr\Log\InvalidArgumentException;
use Psr\Log\LogLevel;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Helper\FormatterHelper;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -195,14 +195,8 @@ public function getOperatingSystemName()
public function getTerminalWidth()
{
$application = new Application();
$terminalDimensions = $application->getTerminalDimensions();

$width = 120;
if (isset($terminalDimensions[0])) {
$width = $terminalDimensions[0];
}

return $width;
return $application->getTerminalWidth();
}

/**
Expand Down

0 comments on commit 9291256

Please sign in to comment.