Skip to content

Commit cdface4

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

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

meson.build

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,13 @@ if get_option('unit-tests')
6060
subproject('libflake-tests')
6161
endif
6262
subproject('nix-functional-tests')
63+
6364
if get_option('json-schema-checks')
6465
subproject('json-schema-checks')
6566
endif
6667
if get_option('kaitai-struct-checks')
6768
subproject('kaitai-struct-checks')
69+
70+
if get_option('color')
71+
add_project_arguments('-DNIX_COLOR', language: ['c', 'cpp'])
6872
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)