Skip to content

Commit 1a0b862

Browse files
committed
Add color option for disabling ANSI escape codes
Fix #14017
1 parent ed176cb commit 1a0b862

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

meson.build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,7 @@ if get_option('json-schema-checks')
6565
endif
6666
if get_option('kaitai-struct-checks')
6767
subproject('kaitai-struct-checks')
68+
69+
if get_option('color')
70+
add_project_arguments('-DNIX_COLOR', language: ['c', 'cpp'])
6871
endif

meson.options

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,10 @@ option(
4141
value : true,
4242
description : 'Check JSON schema validity of schemas and examples (requires jv)',
4343
)
44+
45+
option(
46+
'color',
47+
type : 'boolean',
48+
value : true,
49+
description : 'Output ANSI escape sequences',
50+
)

src/libutil/include/nix/util/ansicolor.hh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace nix {
1010

11+
#ifdef NIX_COLOR
1112
#define ANSI_NORMAL "\e[0m"
1213
#define ANSI_BOLD "\e[1m"
1314
#define ANSI_FAINT "\e[2m"
@@ -18,5 +19,17 @@ namespace nix {
1819
#define ANSI_BLUE "\e[34;1m"
1920
#define ANSI_MAGENTA "\e[35;1m"
2021
#define ANSI_CYAN "\e[36;1m"
22+
#else
23+
#define ANSI_NORMAL ""
24+
#define ANSI_BOLD ""
25+
#define ANSI_FAINT ""
26+
#define ANSI_ITALIC ""
27+
#define ANSI_RED ""
28+
#define ANSI_GREEN ""
29+
#define ANSI_WARNING ""
30+
#define ANSI_BLUE ""
31+
#define ANSI_MAGENTA ""
32+
#define ANSI_CYAN ""
33+
#endif
2134

2235
} // namespace nix

0 commit comments

Comments
 (0)