• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nette / command-line / 3678425886

pending completion
3678425886

push

github

David
constants are PascalCase

19 of 19 new or added lines in 1 file covered. (100.0%)

96 of 102 relevant lines covered (94.12%)

0.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.0
/src/CommandLine/Console.php
1
<?php
2

3
/**
4
 * This file is part of the Nette Framework (https://nette.org)
5
 * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6
 */
7

8
declare(strict_types=1);
9

10
namespace Nette\CommandLine;
11

12

13
/**
14
 * Stupid console writer.
15
 */
16
class Console
17
{
18
        private bool $useColors;
19

20

21
        public function __construct()
22
        {
23
                $this->useColors = self::detectColors();
1✔
24
        }
1✔
25

26

27
        public function useColors(bool $state = true): void
1✔
28
        {
29
                $this->useColors = $state;
1✔
30
        }
1✔
31

32

33
        public function color(?string $color, ?string $s = null): string
1✔
34
        {
35
                $colors = [
1✔
36
                        'black' => '0;30', 'gray' => '1;30', 'silver' => '0;37', 'white' => '1;37',
37
                        'navy' => '0;34', 'blue' => '1;34', 'green' => '0;32', 'lime' => '1;32',
38
                        'teal' => '0;36', 'aqua' => '1;36', 'maroon' => '0;31', 'red' => '1;31',
39
                        'purple' => '0;35', 'fuchsia' => '1;35', 'olive' => '0;33', 'yellow' => '1;33',
40
                        null => '0',
41
                ];
42
                if ($this->useColors) {
1✔
43
                        $c = explode('/', $color ?: '/');
1✔
44
                        return "\033["
45
                                . ($c[0] ? $colors[$c[0]] : '')
1✔
46
                                . (empty($c[1]) ? '' : ';4' . substr($colors[$c[1]], -1))
1✔
47
                                . 'm' . $s
1✔
48
                                . ($s === null ? '' : "\033[0m");
1✔
49
                }
50

51
                return (string) $s;
×
52
        }
53

54

55
        public static function detectColors(): bool
56
        {
57
                return (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg')
1✔
58
                        && getenv('NO_COLOR') === false // https://no-color.org
1✔
59
                        && (getenv('FORCE_COLOR')
1✔
60
                                || (function_exists('sapi_windows_vt100_support')
1✔
61
                                        ? sapi_windows_vt100_support(STDOUT)
×
62
                                        : @stream_isatty(STDOUT)) // @ may trigger error 'cannot cast a filtered stream on this system'
1✔
63
                        );
64
        }
65
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc