]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
libtextstyle: examples: Enable --color=html, for debuggability.
authorBruno Haible <bruno@clisp.org>
Mon, 6 May 2019 23:27:33 +0000 (01:27 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 6 May 2019 23:27:33 +0000 (01:27 +0200)
Reported by Akim Demaille.

* libtextstyle/examples/color-hello/hello.c (main): Handle color_html case.
* libtextstyle/examples/color-filter/filter.c (main): Likewise.

libtextstyle/examples/color-filter/filter.c
libtextstyle/examples/color-hello/hello.c

index c2e88c40d838bcef1ed12b8f11bf7d9edf72d8a9..e97e2f96b719283d001b1cd78cfaab2a3263889d 100644 (file)
@@ -88,7 +88,8 @@ main (int argc, char *argv[])
   }
 
   if (color_mode == color_yes
-      || (color_mode == color_tty && isatty (STDOUT_FILENO)))
+      || (color_mode == color_tty && isatty (STDOUT_FILENO))
+      || color_mode == color_html)
     {
       /* Find the style file.  */
       style_file_prepare ("FILTER_STYLE", "FILTER_STYLESDIR", STYLESDIR,
@@ -107,8 +108,11 @@ main (int argc, char *argv[])
 
   /* Create a terminal output stream that uses this style file.  */
   styled_ostream_t stream =
-    styled_ostream_create (STDOUT_FILENO, "(stdout)", TTYCTL_AUTO,
-                           style_file_name);
+    (color_mode == color_html
+     ? html_styled_ostream_create (file_ostream_create (stdout),
+                                   style_file_name)
+     : styled_ostream_create (STDOUT_FILENO, "(stdout)", TTYCTL_AUTO,
+                              style_file_name));
 
   /* Allocate initial storage for the loop.  */
   size_t buflen = 10;
index fdb800862d575615af8786f057da04afd2a59100..87e091f127d547930bd719c16fa873d39c964a97 100644 (file)
@@ -140,7 +140,8 @@ main (int argc, char *argv[])
     }
 
   if (color_mode == color_yes
-      || (color_mode == color_tty && isatty (STDOUT_FILENO)))
+      || (color_mode == color_tty && isatty (STDOUT_FILENO))
+      || color_mode == color_html)
     {
       /* Find the style file.  */
       style_file_prepare ("HELLO_STYLE", "HELLO_STYLESDIR", STYLESDIR,
@@ -159,8 +160,11 @@ main (int argc, char *argv[])
 
   /* Create a terminal output stream that uses this style file.  */
   styled_ostream_t stream =
-    styled_ostream_create (STDOUT_FILENO, "(stdout)", TTYCTL_AUTO,
-                           style_file_name);
+    (color_mode == color_html
+     ? html_styled_ostream_create (file_ostream_create (stdout),
+                                   style_file_name)
+     : styled_ostream_create (STDOUT_FILENO, "(stdout)", TTYCTL_AUTO,
+                              style_file_name));
 
   /* Determine the full name of the user.  */
   if (fullname == NULL)