From 65523b817aee44eef40feaa99b89a726035af31c Mon Sep 17 00:00:00 2001 From: Ezekiel Warren Date: Fri, 13 Oct 2023 20:31:05 -0700 Subject: [PATCH] feat: coloured text output (#51) --- ecsact/cli/detail/text_report.cc | 44 ++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/ecsact/cli/detail/text_report.cc b/ecsact/cli/detail/text_report.cc index d9ade86..aa7cc49 100644 --- a/ecsact/cli/detail/text_report.cc +++ b/ecsact/cli/detail/text_report.cc @@ -16,32 +16,40 @@ using ecsact::cli::subcommand_stdout_message; using ecsact::cli::success_message; using ecsact::cli::warning_message; +#define COLOR_RED "\e[0;31m" +#define COLOR_GRN "\e[0;32m" +#define COLOR_YEL "\e[0;33m" +#define COLOR_BLU "\e[0;34m" +#define COLOR_MAG "\e[0;35m" +#define COLOR_CYN "\e[0;36m" + +#define COLOR_RESET "\e[0m" + namespace { auto print_text_report(const alert_message& msg) -> void { std::cout << std::format( // - "[ALERT] {}\n", + COLOR_RED "ALERT:" COLOR_RESET " {}\n", msg.content ); } auto print_text_report(const info_message& msg) -> void { std::cout << std::format( // - "[INFO] {}\n", + COLOR_GRN "INFO:" COLOR_RESET " {}\n", msg.content ); } auto print_text_report(const error_message& msg) -> void { std::cout << std::format( // - "[ERROR] {}\n", + COLOR_RED "ERROR:" COLOR_RESET " {}\n", msg.content ); } auto print_text_report(const ecsact_error_message& msg) -> void { std::cerr << std::format( // - "[ERROR] {}:{}:{}\n" - " {}\n", + COLOR_RED "ERROR:" COLOR_RESET " {}:{}:{}\n {}\n", msg.ecsact_source_path, msg.line, msg.character, @@ -51,31 +59,33 @@ auto print_text_report(const ecsact_error_message& msg) -> void { auto print_text_report(const warning_message& msg) -> void { std::cout << std::format( // - "[WARNING] {}\n", + COLOR_YEL "WARNING:" COLOR_RESET " {}\n", msg.content ); } auto print_text_report(const success_message& msg) -> void { std::cout << std::format( // - "[SUCCESS] {}\n", + COLOR_GRN "SUCCESS:" COLOR_RESET " {}\n", msg.content ); } auto print_text_report(const module_methods_message& msg) -> void { - std::cout << "[Module Methods for " << msg.module_name << "]\n"; + std::cout << "MODULE METHODS FOR " << msg.module_name << ":\n"; for(auto& method : msg.methods) { std::cout // - << " " << (method.available ? "YES " : " NO ") << method.method_name - << "\n"; + << " " << (method.available ? COLOR_GRN "YES " : COLOR_RED " NO ") + << COLOR_RESET << method.method_name << "\n"; } } auto print_text_report(const subcommand_start_message& msg) -> void { - std::cout // - << "[SUBCOMMAND START id=(" << std::to_string(msg.id) << ")] " - << msg.executable << " "; + std::cout << std::format( // + COLOR_BLU "SUBCOMMAND({}) START >>" COLOR_RESET " {} ", + msg.id, + msg.executable + ); for(auto& arg : msg.arguments) { std::cout << arg << " "; } @@ -84,7 +94,7 @@ auto print_text_report(const subcommand_start_message& msg) -> void { auto print_text_report(const subcommand_stdout_message& msg) -> void { std::cout << std::format( // - "[SUBCOMMAND STDOUT id=({})] {}\n", + COLOR_BLU "SUBCOMMAND({}) STDOUT:" COLOR_RESET " {}\n", msg.id, msg.line ); @@ -92,7 +102,7 @@ auto print_text_report(const subcommand_stdout_message& msg) -> void { auto print_text_report(const subcommand_stderr_message& msg) -> void { std::cout << std::format( // - "[SUBCOMMAND STDERR id=({})] {}\n", + COLOR_RED "SUBCOMMAND({}) STDERR:" COLOR_RESET " {}\n", msg.id, msg.line ); @@ -100,7 +110,7 @@ auto print_text_report(const subcommand_stderr_message& msg) -> void { auto print_text_report(const subcommand_progress_message& msg) -> void { std::cout << std::format( // - "[SUBCOMMAND PROG id=({})] {}\n", + COLOR_BLU "SUBCOMMAND({}) PROG:" COLOR_RESET " {}\n", msg.id, msg.description ); @@ -108,7 +118,7 @@ auto print_text_report(const subcommand_progress_message& msg) -> void { auto print_text_report(const subcommand_end_message& msg) -> void { std::cout << std::format( // - "[SUBCOMMAND END id=({})] exit code {}\n", + COLOR_BLU "SUBCOMMAND({}) END << " COLOR_RESET " exit code {}\n", msg.id, msg.exit_code );