about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMel <mel@rnrd.eu>2025-06-12 18:20:21 +0200
committerMel <mel@rnrd.eu>2025-06-12 18:20:21 +0200
commit3e7acb02962b05db8cf83e5b6b082ac368c8c88e (patch)
tree3d3356fe631f69429f14b5278c3a823c7ca2245e
parent9676d1ca61b025af9e52506f8aec1f9c0792f51c (diff)
downloadcatskill-3e7acb02962b05db8cf83e5b6b082ac368c8c88e.tar.zst
catskill-3e7acb02962b05db8cf83e5b6b082ac368c8c88e.zip
Fix `failure()` colors + stream flush, define ANSI escape codes
Signed-off-by: Mel <mel@rnrd.eu>
-rw-r--r--boot/common.c37
1 files changed, 33 insertions, 4 deletions
diff --git a/boot/common.c b/boot/common.c
index 6851312..b9da4cf 100644
--- a/boot/common.c
+++ b/boot/common.c
@@ -39,17 +39,46 @@
 #define nil NULL
 #define unknown void
 
+// ansi escape codes for terminal color and style
+#define ANSI(code) "\33[" code "m"
+
+#define ANSI_RESET ANSI("0")
+#define ANSI_DEFAULT ANSI("39")
+
+#define ANSI_RED ANSI("31")
+#define ANSI_RED_BG ANSI("41")
+#define ANSI_GREEN ANSI("32")
+#define ANSI_GREEN_BG ANSI("42")
+#define ANSI_YELLOW ANSI("33")
+#define ANSI_YELLOW_BG ANSI("43")
+#define ANSI_BLUE ANSI("34")
+#define ANSI_BLUE_BG ANSI("44")
+#define ANSI_MAGENTA ANSI("35")
+#define ANSI_MAGENTA_BG ANSI("45")
+#define ANSI_CYAN ANSI("36")
+#define ANSI_CYAN_BG ANSI("46")
+#define ANSI_WHITE ANSI("37")
+#define ANSI_WHITE_BG ANSI("47")
+#define ANSI_BLACK ANSI("30")
+#define ANSI_BLACK_BG ANSI("40")
+
+#define ANSI_BOLD ANSI("1")
+#define ANSI_NO_BOLD ANSI("22")
+#define ANSI_UNDERLINE ANSI("4")
+#define ANSI_NO_UNDERLINE ANSI("24")
+
 // call on irrecoverable failure.
 // prints a very sad, apologetic message for
 // the user and aborts program with failure status.
 void
 failure(const ascii* message)
 {
+    fflush(stdout); // flush stdout to ensure any message is printed before the error.
+
     const ascii* format =
-        "\\e[0;31m"
-        ";( sorry, a failure has occurred...\n"
-        "-> %s!\n"
-        "\\e[0m";
+        ANSI_RED ANSI_BOLD ";( sorry, a failure has occurred..." ANSI_NO_BOLD "\n"
+        "-> %s!" "\n"
+        ANSI_RESET;
     fprintf(stderr, format, message);
 
     exit(EXIT_FAILURE);