From ae8dc3bc9789b7077e0e2569058e15987e4be42c Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 14 Feb 2019 22:53:27 +0100 Subject: [PATCH] libtextstyle: In the examples, actually respect the --color option. Reported by Akim Demaille . * libtextstyle/examples/color-filter/filter.c (main): Set style_file_name to NULL when styling should be disabled. * libtextstyle/examples/color-hello/hello.c (main): Likewise. --- libtextstyle/examples/color-filter/filter.c | 25 +++++++++++++-------- libtextstyle/examples/color-hello/hello.c | 25 +++++++++++++-------- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/libtextstyle/examples/color-filter/filter.c b/libtextstyle/examples/color-filter/filter.c index 1a539383d..c2e88c40d 100644 --- a/libtextstyle/examples/color-filter/filter.c +++ b/libtextstyle/examples/color-filter/filter.c @@ -87,16 +87,23 @@ main (int argc, char *argv[]) } } - /* Find the style file. */ - style_file_prepare ("FILTER_STYLE", "FILTER_STYLESDIR", STYLESDIR, - "filter-default.css"); - /* As a fallback, use the default in the current directory. */ - { - struct stat statbuf; + if (color_mode == color_yes + || (color_mode == color_tty && isatty (STDOUT_FILENO))) + { + /* Find the style file. */ + style_file_prepare ("FILTER_STYLE", "FILTER_STYLESDIR", STYLESDIR, + "filter-default.css"); + /* As a fallback, use the default in the current directory. */ + { + struct stat statbuf; - if (style_file_name == NULL || stat (style_file_name, &statbuf) < 0) - style_file_name = "filter-default.css"; - } + if (style_file_name == NULL || stat (style_file_name, &statbuf) < 0) + style_file_name = "filter-default.css"; + } + } + else + /* No styling. */ + style_file_name = NULL; /* Create a terminal output stream that uses this style file. */ styled_ostream_t stream = diff --git a/libtextstyle/examples/color-hello/hello.c b/libtextstyle/examples/color-hello/hello.c index 82394b24e..fdb800862 100644 --- a/libtextstyle/examples/color-hello/hello.c +++ b/libtextstyle/examples/color-hello/hello.c @@ -139,16 +139,23 @@ main (int argc, char *argv[]) exit (0); } - /* Find the style file. */ - style_file_prepare ("HELLO_STYLE", "HELLO_STYLESDIR", STYLESDIR, - "hello-default.css"); - /* As a fallback, use the default in the current directory. */ - { - struct stat statbuf; + if (color_mode == color_yes + || (color_mode == color_tty && isatty (STDOUT_FILENO))) + { + /* Find the style file. */ + style_file_prepare ("HELLO_STYLE", "HELLO_STYLESDIR", STYLESDIR, + "hello-default.css"); + /* As a fallback, use the default in the current directory. */ + { + struct stat statbuf; - if (style_file_name == NULL || stat (style_file_name, &statbuf) < 0) - style_file_name = "hello-default.css"; - } + if (style_file_name == NULL || stat (style_file_name, &statbuf) < 0) + style_file_name = "hello-default.css"; + } + } + else + /* No styling. */ + style_file_name = NULL; /* Create a terminal output stream that uses this style file. */ styled_ostream_t stream = -- 2.47.2