Terminal::width()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 4
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 3
rs 10
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Cli\Tools\Core;
4
5
use AlecRabbit\Cli\Tools\Core\Contracts\StaticTerminalInterface;
6
use AlecRabbit\Cli\Tools\EnvCheck;
7
use AlecRabbit\Cli\Tools\Stream;
8
use const AlecRabbit\COLOR256_TERMINAL;
9
use const AlecRabbit\COLOR_TERMINAL;
10
use const AlecRabbit\NO_COLOR_TERMINAL;
11
use const AlecRabbit\TRUECOLOR_TERMINAL;
12
13
/**
14
 * Class Terminal
15
 * @author AlecRabbit
16
 */
17
class Terminal extends AbstractXTermTerminal implements StaticTerminalInterface
18
{
19
20
    /** {@inheritdoc} */
21 1
    public static function setTitle(string $title): string
22
    {
23
        return
24 1
            static::isXterm() ? "\033]0;{$title}\007" : '';
25
    }
26
27
    /** {@inheritdoc} */
28 6
    public static function width(bool $recheck = false): int
29
    {
30 6
        if (null !== static::$width && true !== $recheck) {
31 6
            return static::$width;
32
        }
33
        return
34 2
            static::$width = static::getWidth();
35
    }
36
37
    /** {@inheritdoc} */
38 6
    public static function height(bool $recheck = false): int
39
    {
40 6
        if (null !== static::$height && true !== $recheck) {
41 6
            return static::$height;
42
        }
43
        return
44 2
            static::$height = static::getHeight();
45
    }
46
47
    /** {@inheritdoc} */
48 6
    public static function colorSupport($stream = null): int
49
    {
50 6
        $colorSupport = NO_COLOR_TERMINAL;
51 6
        if (false === $stream) {
52 1
            return $colorSupport;
53
        }
54 6
        if (Stream::hasColorSupport($stream)) {
55 5
            $colorSupport = COLOR_TERMINAL;
56 5
            if (EnvCheck::has256ColorSupport()) {
57
                $colorSupport = COLOR256_TERMINAL;
58
            }
59 5
            if (EnvCheck::hasTrueColorSupport()) {
60
                $colorSupport = TRUECOLOR_TERMINAL;
61
            }
62
        }
63 5
        return $colorSupport;
64
    }
65
}
66