-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support output formatter wordwraping.
- Loading branch information
1 parent
0bcb15e
commit ef87a2d
Showing
9 changed files
with
234 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
namespace Consolidation\AnnotatedCommand\Options; | ||
|
||
use Consolidation\AnnotatedCommand\CommandData; | ||
use Consolidation\OutputFormatters\Options\FormatterOptions; | ||
|
||
interface PrepareFormatter | ||
{ | ||
public function prepare(CommandData $commandData, FormatterOptions $options); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
namespace Consolidation\AnnotatedCommand\Options; | ||
|
||
use Symfony\Component\Console\Application; | ||
use Consolidation\AnnotatedCommand\CommandData; | ||
use Consolidation\OutputFormatters\Options\FormatterOptions; | ||
|
||
class PrepareTerminalWidthOption implements PrepareFormatter | ||
{ | ||
/** var Application */ | ||
protected $application; | ||
|
||
/** var int */ | ||
protected $defaultWidth; | ||
|
||
/** var int */ | ||
protected $maxWidth = PHP_INT_MAX; | ||
|
||
/** var int */ | ||
protected $minWidth = 0; | ||
|
||
public function __construct($defaultWidth = 0) | ||
{ | ||
$this->defaultWidth = $defaultWidth; | ||
} | ||
|
||
public function setApplication(Application $application) | ||
{ | ||
$this->application = $application; | ||
} | ||
|
||
public function prepare(CommandData $commandData, FormatterOptions $options) | ||
{ | ||
$width = $this->getTerminalWidth(); | ||
if (!$width) { | ||
$width = $this->defaultWidth; | ||
} | ||
|
||
// Enforce minimum and maximum widths | ||
$width = min($width, $this->getMaxWidth($commandData)); | ||
$width = max($width, $this->getMinWidth($commandData)); | ||
|
||
$options->setWidth($width); | ||
} | ||
|
||
protected function getTerminalWidth() | ||
{ | ||
if (!$this->application) { | ||
return 0; | ||
} | ||
|
||
$dimensions = $this->application->getTerminalDimensions(); | ||
if ($dimensions[0] == null) { | ||
return 0; | ||
} | ||
|
||
return $dimensions[0]; | ||
} | ||
|
||
protected function getMaxWidth(CommandData $commandData) | ||
{ | ||
return $this->maxWidth; | ||
} | ||
|
||
protected function getMinWidth(CommandData $commandData) | ||
{ | ||
return $this->minWidth; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
namespace Consolidation\TestUtils; | ||
|
||
use Symfony\Component\Console\Application; | ||
|
||
class ApplicationWithTerminalWidth extends Application | ||
{ | ||
protected $width = 0; | ||
protected $height = 0; | ||
|
||
public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN') | ||
{ | ||
parent::__construct($name, $version); | ||
} | ||
|
||
public function setWidthAndHeight($width, $height) | ||
{ | ||
$this->width = $width; | ||
$this->height = $height; | ||
} | ||
|
||
public function getTerminalDimensions() | ||
{ | ||
return [ $this->width, $this->height ]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.