Completed
Push — master ( 3ebcb1...9e4cf7 )
by personal
16s queued 11s
created

CliOutput::writeln()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * (c) Jean-François Lépine <https://twitter.com/Halleck45>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Hal\Component\Output;
11
12
/**
13
 * @package Hal\Component\Issue
14
 */
15
class CliOutput implements Output
16
{
17
    /**
18
     * @var bool
19
     */
20
    private $quietMode = false;
21
22
    /**
23
     * @param string $message
24
     * @return $this
25
     */
26
    public function writeln($message)
27
    {
28
        $this->write(PHP_EOL . $message);
29
        return $this;
30
    }
31
32
    /**
33
     * @param string $message
34
     * @return $this
35
     */
36
    public function write($message)
37
    {
38
        $this->quietMode||file_put_contents('php://stdout', $message);
39
        return $this;
40
    }
41
42
    /**
43
     * @param string $message
44
     * @return $this
45
     */
46
    public function err($message)
47
    {
48
        file_put_contents('php://stderr', $message);
49
        return $this;
50
    }
51
52
    public function clearln()
53
    {
54
        $this->writeln("\x0D");
55
        $this->writeln("\x1B[2K");
56
        return $this;
57
    }
58
59
    /**
60
     * @param bool $quietMode
61
     * @return $this
62
     */
63
    public function setQuietMode($quietMode)
64
    {
65
        $this->quietMode = $quietMode;
66
        return $this;
67
    }
68
69
    /**
70
     * @inheritDoc
71
     */
72
    public function hasAnsi()
73
    {
74
        if (DIRECTORY_SEPARATOR === '\\') {
75
            return
76
                0 >= version_compare(
77
                    '10.0.10586',
78
                    PHP_WINDOWS_VERSION_MAJOR . '.' . PHP_WINDOWS_VERSION_MINOR . '.' . PHP_WINDOWS_VERSION_BUILD
79
                )
80
                || false !== getenv('ANSICON')
81
                || 'ON' === getenv('ConEmuANSI')
82
                || 'xterm' === getenv('TERM');
83
        }
84
85
        return function_exists('posix_isatty') && @posix_isatty(STDOUT);
86
    }
87
}
88