-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/v0.9.7' into main
- Loading branch information
Showing
8 changed files
with
242 additions
and
54 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
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,20 @@ | ||
<?php | ||
|
||
/** | ||
* @package Terminus | ||
* @license http://opensource.org/licenses/MIT | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DecodeLabs\Terminus; | ||
|
||
interface Adapter | ||
{ | ||
public function hasStty(): bool; | ||
public function setStty(string $config): void; | ||
|
||
public function getShellWidth(): int; | ||
public function getShellHeight(): int; | ||
public function canColorShell(): bool; | ||
} |
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,103 @@ | ||
<?php | ||
|
||
/** | ||
* @package Terminus | ||
* @license http://opensource.org/licenses/MIT | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DecodeLabs\Terminus\Adapter; | ||
|
||
use DecodeLabs\Terminus\AdapterAbstract; | ||
|
||
class Unix extends AdapterAbstract | ||
{ | ||
/** | ||
* Can the shell support TTY | ||
*/ | ||
public function hasStty(): bool | ||
{ | ||
static $output; | ||
|
||
if (isset($output)) { | ||
return $output; | ||
} | ||
|
||
exec('which stty', $result); | ||
return $output = !empty(trim($result[0])); | ||
} | ||
|
||
/** | ||
* Set stty config | ||
*/ | ||
public function setStty(string $config): void | ||
{ | ||
system('stty \'' . $config . '\''); | ||
} | ||
|
||
|
||
/** | ||
* Get shell width | ||
*/ | ||
public function getShellWidth(): int | ||
{ | ||
static $output; | ||
|
||
if (isset($output)) { | ||
return $output; | ||
} | ||
|
||
exec('tput cols 2>/dev/null', $result); | ||
return $output = (int)($result[0] ?? 80); | ||
} | ||
|
||
/** | ||
* Get shell height | ||
*/ | ||
public function getShellHeight(): int | ||
{ | ||
static $output; | ||
|
||
if (isset($output)) { | ||
return $output; | ||
} | ||
|
||
exec('tput lines 2>/dev/null', $result); | ||
return $output = (int)($result[0] ?? 30); | ||
} | ||
|
||
/** | ||
* Get shell be coloured? | ||
*/ | ||
public function canColorShell(): bool | ||
{ | ||
static $output; | ||
|
||
if (isset($output)) { | ||
return $output; | ||
} | ||
|
||
if (!defined('STDOUT')) { | ||
return $output = false; | ||
} | ||
|
||
if (function_exists('stream_isatty')) { | ||
return $output = stream_isatty(\STDOUT); | ||
} | ||
|
||
if (function_exists('posix_isatty')) { | ||
return $output = posix_isatty(\STDOUT); | ||
} | ||
|
||
if (($_SERVER['TERM'] ?? null) === 'xterm-256color') { | ||
return $output = true; | ||
} | ||
|
||
if (($_SERVER['CLICOLOR'] ?? null) === '1') { | ||
return $output = true; | ||
} | ||
|
||
return $output = false; | ||
} | ||
} |
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,38 @@ | ||
<?php | ||
|
||
/** | ||
* @package Terminus | ||
* @license http://opensource.org/licenses/MIT | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DecodeLabs\Terminus; | ||
|
||
use DecodeLabs\Archetype; | ||
use DecodeLabs\Terminus\Adapter\Unix; | ||
|
||
abstract class AdapterAbstract implements Adapter | ||
{ | ||
/** | ||
* Load for current OS | ||
*/ | ||
public static function load(?string $name = null): Adapter | ||
{ | ||
if ($name === null) { | ||
$name = php_uname('s'); | ||
|
||
if (substr(strtolower($name), 0, 3) == 'win') { | ||
$name = 'Windows'; | ||
} | ||
} | ||
|
||
$class = Archetype::resolve( | ||
Adapter::class, | ||
$name, | ||
Unix::class | ||
); | ||
|
||
return new $class($name); | ||
} | ||
} |
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
Oops, something went wrong.