1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace AlecRabbit\Cli\Tools\Core; |
4
|
|
|
|
5
|
|
|
use AlecRabbit\Cli\Tools\Core\Contracts\TerminalStaticInterface; |
6
|
|
|
use const AlecRabbit\COLOR256_TERMINAL; |
7
|
|
|
use const AlecRabbit\COLOR_TERMINAL; |
8
|
|
|
use const AlecRabbit\NO_COLOR_TERMINAL; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class Terminal |
12
|
|
|
* @author AlecRabbit |
13
|
|
|
*/ |
14
|
|
|
class TerminalStatic extends AbstractColorSupportingTerminal implements TerminalStaticInterface |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
/** {@inheritdoc} */ |
18
|
9 |
|
public static function supports256Color(bool $recheck = false): bool |
19
|
|
|
{ |
20
|
9 |
|
if (null !== static::$supports256Color && true !== $recheck) { |
21
|
9 |
|
return static::$supports256Color; |
22
|
|
|
} |
23
|
|
|
return |
24
|
1 |
|
static::$supports256Color = static::has256ColorSupport(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** {@inheritdoc} */ |
28
|
9 |
|
public static function supportsColor(bool $recheck = false): bool |
29
|
|
|
{ |
30
|
9 |
|
if (null !== static::$supportsColor && false === $recheck) { |
31
|
9 |
|
return static::$supportsColor; |
32
|
|
|
} |
33
|
|
|
return |
34
|
1 |
|
static::$supportsColor = static::hasColorSupport(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** {@inheritdoc} */ |
38
|
1 |
|
public static function setTitle(string $title): string |
39
|
|
|
{ |
40
|
1 |
|
if (static::isXterm()) { |
41
|
1 |
|
return "\033]0;{$title}\007"; |
42
|
|
|
} |
43
|
|
|
// @codeCoverageIgnoreStart |
44
|
|
|
return (string)null; |
45
|
|
|
// @codeCoverageIgnoreEnd |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** {@inheritdoc} */ |
49
|
10 |
|
public static function width(bool $recheck = false): int |
50
|
|
|
{ |
51
|
10 |
|
if (null !== static::$width && true !== $recheck) { |
52
|
10 |
|
return static::$width; |
53
|
|
|
} |
54
|
|
|
return |
55
|
2 |
|
static::$width = static::getWidth(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** {@inheritdoc} */ |
59
|
10 |
|
public static function height(bool $recheck = false): int |
60
|
|
|
{ |
61
|
10 |
|
if (null !== static::$height && true !== $recheck) { |
62
|
10 |
|
return static::$height; |
63
|
|
|
} |
64
|
|
|
return |
65
|
2 |
|
static::$height = static::getHeight(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** {@inheritdoc} */ |
69
|
8 |
|
public static function colorSupport(): int |
70
|
|
|
{ |
71
|
8 |
|
if (static::supportsColor()) { |
72
|
|
|
return |
73
|
8 |
|
static::supports256Color() ? |
74
|
|
|
COLOR256_TERMINAL : |
75
|
8 |
|
COLOR_TERMINAL; |
76
|
|
|
} |
77
|
|
|
// @codeCoverageIgnoreStart |
78
|
|
|
return NO_COLOR_TERMINAL; |
79
|
|
|
// @codeCoverageIgnoreEnd |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|