Skip to content

Commit

Permalink
feat: coloured text output
Browse files Browse the repository at this point in the history
  • Loading branch information
zaucy committed Oct 14, 2023
1 parent ef84dac commit 6146a4d
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions ecsact/cli/detail/text_report.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 << " ";
}
Expand All @@ -84,31 +94,31 @@ 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
);
}

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
);
}

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
);
}

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
);
Expand Down

0 comments on commit 6146a4d

Please # to comment.