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

nette / command-line / 22289667037

23 Feb 2026 01:20AM UTC coverage: 96.226%. Remained the same
22289667037

push

github

dg
removed deprecated stuff

153 of 159 relevant lines covered (96.23%)

0.96 hits per line

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

90.0
/src/CommandLine/Console.php
1
<?php declare(strict_types=1);
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
namespace Nette\CommandLine;
9

10

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

18

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

24

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

30

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

49
                return (string) $s;
×
50
        }
51

52

53
        public static function detectColors(): bool
54
        {
55
                return (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg')
1✔
56
                        && getenv('NO_COLOR') === false // https://no-color.org
1✔
57
                        && (getenv('FORCE_COLOR')
1✔
58
                                || (function_exists('sapi_windows_vt100_support')
1✔
59
                                        ? sapi_windows_vt100_support(STDOUT)
×
60
                                        : @stream_isatty(STDOUT)) // @ may trigger error 'cannot cast a filtered stream on this system'
1✔
61
                        );
62
        }
63
}
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

© 2026 Coveralls, Inc