]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
libtextstyle: In the examples, actually respect the --color option.
authorBruno Haible <bruno@clisp.org>
Thu, 14 Feb 2019 21:53:27 +0000 (22:53 +0100)
committerBruno Haible <bruno@clisp.org>
Thu, 14 Feb 2019 21:55:50 +0000 (22:55 +0100)
Reported by Akim Demaille <akim.demaille@gmail.com>.

* 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
libtextstyle/examples/color-hello/hello.c

index 1a539383d5a1d99438f4d2a3988cee191c09a2b0..c2e88c40d838bcef1ed12b8f11bf7d9edf72d8a9 100644 (file)
@@ -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 =
index 82394b24ef3fb7c57875db2a0c66c491585c2f6b..fdb800862d575615af8786f057da04afd2a59100 100644 (file)
@@ -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 =