diff --git a/meson.build b/meson.build index c072a482163..907b13db2c4 100644 --- a/meson.build +++ b/meson.build @@ -65,4 +65,7 @@ if get_option('json-schema-checks') endif if get_option('kaitai-struct-checks') subproject('kaitai-struct-checks') + +if get_option('color') + add_project_arguments('-DNIX_COLOR', language: ['c', 'cpp']) endif diff --git a/meson.options b/meson.options index 2739b0c7163..461280a9463 100644 --- a/meson.options +++ b/meson.options @@ -41,3 +41,10 @@ option( value : true, description : 'Check JSON schema validity of schemas and examples (requires jv)', ) + +option( + 'color', + type : 'boolean', + value : true, + description : 'Output ANSI escape sequences', +) diff --git a/src/libutil/include/nix/util/ansicolor.hh b/src/libutil/include/nix/util/ansicolor.hh index 2f0749e6ad4..e654c1081e1 100644 --- a/src/libutil/include/nix/util/ansicolor.hh +++ b/src/libutil/include/nix/util/ansicolor.hh @@ -8,6 +8,7 @@ namespace nix { +#ifdef NIX_COLOR #define ANSI_NORMAL "\e[0m" #define ANSI_BOLD "\e[1m" #define ANSI_FAINT "\e[2m" @@ -18,5 +19,17 @@ namespace nix { #define ANSI_BLUE "\e[34;1m" #define ANSI_MAGENTA "\e[35;1m" #define ANSI_CYAN "\e[36;1m" +#else +#define ANSI_NORMAL "" +#define ANSI_BOLD "" +#define ANSI_FAINT "" +#define ANSI_ITALIC "" +#define ANSI_RED "" +#define ANSI_GREEN "" +#define ANSI_WARNING "" +#define ANSI_BLUE "" +#define ANSI_MAGENTA "" +#define ANSI_CYAN "" +#endif } // namespace nix