]> git.xolatile.top Git - emil-bake.git/commitdiff
\e[91mColor!\e[0m
authorEmil Williams <emilwilliams@tuta.io>
Fri, 19 Jan 2024 20:57:41 +0000 (20:57 +0000)
committerEmil Williams <emilwilliams@tuta.io>
Fri, 19 Jan 2024 20:57:41 +0000 (20:57 +0000)
bake.c

diff --git a/bake.c b/bake.c
index 75de2a7623d7b9a58cf749cbaecf12b87bc34d46..91ae59c520d5323b947cc33a45c31707e3b82953 100644 (file)
--- a/bake.c
+++ b/bake.c
 
 /* Require space after START */
 #define REQUIRE_SPACE
+/* Enable colors */
+#define COLOR
+
+#ifdef COLOR
+#define    RED "\e[91m"
+#define  GREEN "\e[92m"
+#define YELLOW "\e[93m"
+#define    DIM "\e[2m"
+#define   BOLD "\e[1m"
+#define  RESET "\e[0m"
+#else
+#define    RED
+#define  GREEN
+#define YELLOW
+#define    DIM
+#define   BOLD
+#define  RESET
+#endif
 
 #define START "@BAKE"
 #define  STOP "@STOP"
 #define  HELP                                                                          \
-    "target-file [arguments ...]\n"                                                    \
-    "Use the format `@BAKE cmd ...' within the target-file, this will execute the\n"   \
-    "rest of line, or if found within the file, until the @STOP marker.\n"             \
-    /* "Whitespace is required after and before both markers respectively.\n" */
-
-#define DESC                                                \
-  "Options [Must always be first]\n"                        \
-  "\t-h --help, -n --dry-run\n"                             \
-  "Expansions\n"                                            \
-  "\t$@  returns target-file                (abc.x.txt)\n"  \
-  "\t$*  returns target-file without suffix (^-> abc.x)\n"  \
-  "\t$+  returns arguments\n"
+    BOLD "target-file" RESET " [arguments ...]\n"                                      \
+    "Use the format `" BOLD "@BAKE" RESET " cmd ...' within the target-file, this will execute the\n"   \
+    "rest of line, or if found within the file, until the " BOLD "@STOP" RESET " marker.\n"             \
+
+#define DESC                                                 \
+  "Options [Must always be first]\n"                         \
+  "\t" DIM "-h --help" RESET", " BOLD "-n --dry-run\n" RESET \
+  "Expansions\n"                                             \
+  "\t" YELLOW "$@" RESET "  returns target-file                (abc.x.txt)\n"  \
+  "\t" YELLOW "$*" RESET "  returns target-file without suffix (^-> abc.x)\n"  \
+  "\t" YELLOW "$+" RESET "  returns arguments\n"
 
 /*** Utility functions ***/
 
@@ -151,7 +168,7 @@ find_region(map_t m) {
 
 #ifdef REQUIRE_SPACE
     if (!isspace(*start)) {
-      fprintf(stderr, "%s: Found start without suffix spacing.\n", g_filename);
+      fprintf(stderr, RED "%s" RESET ": Found start without suffix spacing.\n", g_filename);
       return buf;
     }
 #endif /* REQUIRE_SPACE */
@@ -273,7 +290,7 @@ strip(char * buf) {
 
 static int
 run(char * buf) {
-  fputs("Output:\n", stderr);
+  fputs(GREEN "output" RESET ":\n", stderr);
   return system(buf);
 }
 
@@ -306,8 +323,8 @@ main(int argc, char ** argv) {
   }
 
   if (!buf) {
-    if (errno) { fprintf(stderr, "%s: %s", g_filename, strerror(errno)); }
-    else { fprintf(stderr, "%s: File unrecognized.\n", g_filename); }
+    if (errno) { fprintf(stderr, BOLD RED "%s" RESET ": %s\n", g_filename, strerror(errno)); }
+    else { fprintf(stderr, BOLD RED "%s" RESET ": File unrecognized.\n", g_filename); }
     return 1;
   }
 
@@ -319,14 +336,14 @@ main(int argc, char ** argv) {
   }
   buf = expand(buf);
 
-  fprintf(stderr, "Bake: %s\n", buf + strip(buf));
+  fprintf(stderr, GREEN "%s" RESET ": %s\n", argv[0], buf + strip(buf));
   ret = ret ? 0 : run(buf);
   if (ret)
-  { fprintf(stderr, "Result: %d\n", ret); }
+  { fprintf(stderr, RED "result" RESET ": " BOLD "%d\n" RESET, ret); }
 
   free(buf);
   return ret;
 help:
-  fprintf(stderr, "%s: %s", argv[0], HELP DESC);
+  fprintf(stderr, YELLOW "%s" RESET ": %s", argv[0], HELP DESC);
   return 1;
 }