Skip to content

Commit 6146a4d

Browse files
committed
feat: coloured text output
1 parent ef84dac commit 6146a4d

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

ecsact/cli/detail/text_report.cc

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,40 @@ using ecsact::cli::subcommand_stdout_message;
1616
using ecsact::cli::success_message;
1717
using ecsact::cli::warning_message;
1818

19+
#define COLOR_RED "\e[0;31m"
20+
#define COLOR_GRN "\e[0;32m"
21+
#define COLOR_YEL "\e[0;33m"
22+
#define COLOR_BLU "\e[0;34m"
23+
#define COLOR_MAG "\e[0;35m"
24+
#define COLOR_CYN "\e[0;36m"
25+
26+
#define COLOR_RESET "\e[0m"
27+
1928
namespace {
2029
auto print_text_report(const alert_message& msg) -> void {
2130
std::cout << std::format( //
22-
"[ALERT] {}\n",
31+
COLOR_RED "ALERT:" COLOR_RESET " {}\n",
2332
msg.content
2433
);
2534
}
2635

2736
auto print_text_report(const info_message& msg) -> void {
2837
std::cout << std::format( //
29-
"[INFO] {}\n",
38+
COLOR_GRN "INFO:" COLOR_RESET " {}\n",
3039
msg.content
3140
);
3241
}
3342

3443
auto print_text_report(const error_message& msg) -> void {
3544
std::cout << std::format( //
36-
"[ERROR] {}\n",
45+
COLOR_RED "ERROR:" COLOR_RESET " {}\n",
3746
msg.content
3847
);
3948
}
4049

4150
auto print_text_report(const ecsact_error_message& msg) -> void {
4251
std::cerr << std::format( //
43-
"[ERROR] {}:{}:{}\n"
44-
" {}\n",
52+
COLOR_RED "ERROR:" COLOR_RESET " {}:{}:{}\n {}\n",
4553
msg.ecsact_source_path,
4654
msg.line,
4755
msg.character,
@@ -51,31 +59,33 @@ auto print_text_report(const ecsact_error_message& msg) -> void {
5159

5260
auto print_text_report(const warning_message& msg) -> void {
5361
std::cout << std::format( //
54-
"[WARNING] {}\n",
62+
COLOR_YEL "WARNING:" COLOR_RESET " {}\n",
5563
msg.content
5664
);
5765
}
5866

5967
auto print_text_report(const success_message& msg) -> void {
6068
std::cout << std::format( //
61-
"[SUCCESS] {}\n",
69+
COLOR_GRN "SUCCESS:" COLOR_RESET " {}\n",
6270
msg.content
6371
);
6472
}
6573

6674
auto print_text_report(const module_methods_message& msg) -> void {
67-
std::cout << "[Module Methods for " << msg.module_name << "]\n";
75+
std::cout << "MODULE METHODS FOR " << msg.module_name << ":\n";
6876
for(auto& method : msg.methods) {
6977
std::cout //
70-
<< " " << (method.available ? "YES " : " NO ") << method.method_name
71-
<< "\n";
78+
<< " " << (method.available ? COLOR_GRN "YES " : COLOR_RED " NO ")
79+
<< COLOR_RESET << method.method_name << "\n";
7280
}
7381
}
7482

7583
auto print_text_report(const subcommand_start_message& msg) -> void {
76-
std::cout //
77-
<< "[SUBCOMMAND START id=(" << std::to_string(msg.id) << ")] "
78-
<< msg.executable << " ";
84+
std::cout << std::format( //
85+
COLOR_BLU "SUBCOMMAND({}) START >>" COLOR_RESET " {} ",
86+
msg.id,
87+
msg.executable
88+
);
7989
for(auto& arg : msg.arguments) {
8090
std::cout << arg << " ";
8191
}
@@ -84,31 +94,31 @@ auto print_text_report(const subcommand_start_message& msg) -> void {
8494

8595
auto print_text_report(const subcommand_stdout_message& msg) -> void {
8696
std::cout << std::format( //
87-
"[SUBCOMMAND STDOUT id=({})] {}\n",
97+
COLOR_BLU "SUBCOMMAND({}) STDOUT:" COLOR_RESET " {}\n",
8898
msg.id,
8999
msg.line
90100
);
91101
}
92102

93103
auto print_text_report(const subcommand_stderr_message& msg) -> void {
94104
std::cout << std::format( //
95-
"[SUBCOMMAND STDERR id=({})] {}\n",
105+
COLOR_RED "SUBCOMMAND({}) STDERR:" COLOR_RESET " {}\n",
96106
msg.id,
97107
msg.line
98108
);
99109
}
100110

101111
auto print_text_report(const subcommand_progress_message& msg) -> void {
102112
std::cout << std::format( //
103-
"[SUBCOMMAND PROG id=({})] {}\n",
113+
COLOR_BLU "SUBCOMMAND({}) PROG:" COLOR_RESET " {}\n",
104114
msg.id,
105115
msg.description
106116
);
107117
}
108118

109119
auto print_text_report(const subcommand_end_message& msg) -> void {
110120
std::cout << std::format( //
111-
"[SUBCOMMAND END id=({})] exit code {}\n",
121+
COLOR_BLU "SUBCOMMAND({}) END << " COLOR_RESET " exit code {}\n",
112122
msg.id,
113123
msg.exit_code
114124
);

0 commit comments

Comments
 (0)