[ostree] main: Print error: in red bold just for fun



commit 4c1a69f74e85c9e377e943f3b8dcdae4cd992b54
Author: Colin Walters <walters verbum org>
Date:   Wed Sep 18 16:34:14 2013 -0400

    main: Print error: in red bold just for fun
    
    It's easier to see.  Also drop old dead ot_main() function.

 src/ostree/main.c    |   11 ++++++++++-
 src/ostree/ot-main.c |   22 ----------------------
 src/ostree/ot-main.h |    2 --
 3 files changed, 10 insertions(+), 25 deletions(-)
---
diff --git a/src/ostree/main.c b/src/ostree/main.c
index f23e826..3e164f9 100644
--- a/src/ostree/main.c
+++ b/src/ostree/main.c
@@ -26,6 +26,7 @@
 
 #include <errno.h>
 #include <string.h>
+#include <unistd.h>
 #include <locale.h>
 
 #include "ot-main.h"
@@ -75,7 +76,15 @@ main (int    argc,
 
   if (error != NULL)
     {
-      g_message ("%s", error->message);
+      int is_tty = isatty (1);
+      const char *prefix = "";
+      const char *suffix = "";
+      if (is_tty)
+        {
+          prefix = "\x1b[31m\x1b[1m"; /* red, bold */
+          suffix = "\x1b[22m\x1b[0m"; /* bold off, color reset */
+        }
+      g_printerr ("%serror: %s%s\n", prefix, suffix, error->message);
       g_error_free (error);
     }
 
diff --git a/src/ostree/ot-main.c b/src/ostree/ot-main.c
index 1138f86..3530206 100644
--- a/src/ostree/ot-main.c
+++ b/src/ostree/ot-main.c
@@ -262,25 +262,3 @@ ostree_run (int    argc,
     }
   return 0;
 }
-
-int
-ostree_main (int    argc,
-             char **argv,
-             OstreeCommand *commands)
-{
-  GError *error = NULL;
-  int ret;
-
-  ret = ostree_run (argc, argv, commands, &error);
-
-  if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
-    ostree_usage (argv, commands, TRUE);
-
-  if (error)
-    {
-      g_message ("%s", error->message);
-      g_error_free (error);
-    }
-
-  return ret;
-}
diff --git a/src/ostree/ot-main.h b/src/ostree/ot-main.h
index f137186..49e310e 100644
--- a/src/ostree/ot-main.h
+++ b/src/ostree/ot-main.h
@@ -36,8 +36,6 @@ typedef struct {
   int flags; /* OstreeBuiltinFlags */
 } OstreeCommand;
 
-int ostree_main (int    argc, char **argv, OstreeCommand  *commands);
-
 int ostree_run (int argc, char **argv, OstreeCommand *commands, GError **error);
 
 int ostree_usage (char **argv, OstreeCommand *commands, gboolean is_error);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]