Security update for Core, with self-updated composer
[yaffs-website] / vendor / consolidation / annotated-command / src / Options / PrepareTerminalWidthOption.php
index ef5527d1644689b8595e09cd3252ce2b9403e5a2..6c70b7c2400d8206a365823e81b87b668a4c3319 100644 (file)
@@ -10,6 +10,8 @@ class PrepareTerminalWidthOption implements PrepareFormatter
     /** var Application */
     protected $application;
 
+    protected $terminal;
+
     /** var int */
     protected $defaultWidth;
 
@@ -19,6 +21,9 @@ class PrepareTerminalWidthOption implements PrepareFormatter
     /** var int */
     protected $minWidth = 0;
 
+    /* var boolean */
+    protected $shouldWrap = true;
+
     public function __construct($defaultWidth = 0)
     {
         $this->defaultWidth = $defaultWidth;
@@ -29,6 +34,24 @@ class PrepareTerminalWidthOption implements PrepareFormatter
         $this->application = $application;
     }
 
+    public function setTerminal($terminal)
+    {
+        $this->terminal = $terminal;
+    }
+
+    public function getTerminal()
+    {
+        if (!$this->terminal && class_exists('\Symfony\Component\Console\Terminal')) {
+            $this->terminal = new \Symfony\Component\Console\Terminal();
+        }
+        return $this->terminal;
+    }
+
+    public function enableWrap($shouldWrap)
+    {
+        $this->shouldWrap = $shouldWrap;
+    }
+
     public function prepare(CommandData $commandData, FormatterOptions $options)
     {
         $width = $this->getTerminalWidth();
@@ -45,10 +68,24 @@ class PrepareTerminalWidthOption implements PrepareFormatter
 
     protected function getTerminalWidth()
     {
-        if (!$this->application) {
+        // Don't wrap if wrapping has been disabled.
+        if (!$this->shouldWrap) {
             return 0;
         }
 
+        $terminal = $this->getTerminal();
+        if ($terminal) {
+            return $terminal->getWidth();
+        }
+
+        return $this->getTerminalWidthViaApplication();
+    }
+
+    protected function getTerminalWidthViaApplication()
+    {
+        if (!$this->application) {
+            return 0;
+        }
         $dimensions = $this->application->getTerminalDimensions();
         if ($dimensions[0] == null) {
             return 0;