diff --git a/cmd/arg.c b/cmd/arg.c index 579b0da..f7e4963 100644 --- a/cmd/arg.c +++ b/cmd/arg.c @@ -160,7 +160,7 @@ void z__b_get_arg_description(struct b_command_arg *arg, b_string *out) b_string_append_cstr(out, " "); } - b_string_append_cstr(out, "[values:"); + b_string_append_cstr(out, "[[values:"); for (size_t i = 0; arg->arg_allowed_values[i]; i++) { if (i > 0) { diff --git a/cmd/command.c b/cmd/command.c index 926c5a8..6ed5ec1 100644 --- a/cmd/command.c +++ b/cmd/command.c @@ -10,7 +10,7 @@ #define OUTPUT_STREAM stderr -static struct b_btree command_list = {}; +static struct b_btree command_list = {0}; B_BTREE_DEFINE_SIMPLE_GET(struct b_command, unsigned int, b_node, b_id, get_command) B_BTREE_DEFINE_SIMPLE_INSERT(struct b_command, b_node, b_id, put_command) @@ -545,8 +545,9 @@ static void print_options_list(struct b_command *cmd) z__b_get_option_description(opt, desc_str); size_t opt_len - = b_string_get_size(opt_str, B_STRLEN_IGNORE_ESC) + 4; - size_t desc_len = b_string_get_size(desc_str, B_STRLEN_IGNORE_ESC); + = b_string_get_size(opt_str, B_STRLEN_IGNORE_ESC | B_STRLEN_IGNORE_MOD) + 4; + size_t desc_len = b_string_get_size( + desc_str, B_STRLEN_IGNORE_ESC | B_STRLEN_IGNORE_MOD); if (description_on_separate_line(opt_len, desc_len)) { continue; @@ -557,7 +558,7 @@ static void print_options_list(struct b_command *cmd) } } - b_paragraph_format format = {}; + b_paragraph_format format = {0}; format.p_flags = B_PARAGRAPH_DONT_INDENT_FIRST_LINE; format.p_left_margin = desb_margin + 4; format.p_right_margin = 4; @@ -575,9 +576,12 @@ static void print_options_list(struct b_command *cmd) z__b_get_option_usage_string(opt, CMD_STR_COLOUR, opt_str); z__b_get_option_description(opt, desc_str); - size_t opt_len - = b_string_get_size(opt_str, B_STRLEN_IGNORE_ESC) + 4; - size_t desc_len = b_string_get_size(desc_str, B_STRLEN_IGNORE_ESC); + size_t opt_len = b_string_get_size( + opt_str, B_STRLEN_IGNORE_ESC + | B_STRLEN_IGNORE_MOD) + + 4; + size_t desc_len = b_string_get_size( + desc_str, B_STRLEN_IGNORE_ESC | B_STRLEN_IGNORE_MOD); bool new_paragraph = description_on_separate_line(opt_len, desc_len); @@ -631,14 +635,16 @@ static void print_args_list(struct b_command *cmd) b_string_clear(str); z__b_get_arg_usage_string(arg, true, str); - size_t len = b_string_get_size(str, B_STRLEN_IGNORE_ESC) + 4; + size_t len = b_string_get_size( + str, B_STRLEN_IGNORE_ESC | B_STRLEN_IGNORE_MOD) + + 4; if (len > desb_margin) { desb_margin = len; } } - b_paragraph_format format = {}; + b_paragraph_format format = {0}; format.p_flags = B_PARAGRAPH_DONT_INDENT_FIRST_LINE; format.p_left_margin = desb_margin + 4; format.p_right_margin = 4; @@ -653,7 +659,10 @@ static void print_args_list(struct b_command *cmd) fputs(" ", OUTPUT_STREAM); b_fputs(b_string_ptr(str), OUTPUT_STREAM); - unsigned int len = b_string_get_size(str, B_STRLEN_IGNORE_ESC) + 4; + unsigned int len + = b_string_get_size( + str, B_STRLEN_IGNORE_ESC | B_STRLEN_IGNORE_MOD) + + 4; while (len < format.p_left_margin) { fputc(' ', OUTPUT_STREAM); len++; @@ -682,14 +691,16 @@ static void print_commands_list(struct b_command *cmd) b_string_clear(str); get_command_string(sub, str); - size_t len = b_string_get_size(str, B_STRLEN_IGNORE_ESC) + 4; + size_t len = b_string_get_size( + str, B_STRLEN_IGNORE_ESC | B_STRLEN_IGNORE_MOD) + + 4; if (len > desb_margin) { desb_margin = len; } } - b_paragraph_format format = {}; + b_paragraph_format format = {0}; format.p_flags = B_PARAGRAPH_DONT_INDENT_FIRST_LINE; format.p_left_margin = desb_margin + 4; format.p_right_margin = 4; @@ -704,7 +715,10 @@ static void print_commands_list(struct b_command *cmd) fputs(" ", OUTPUT_STREAM); b_fputs(b_string_ptr(str), OUTPUT_STREAM); - unsigned int len = b_string_get_size(str, B_STRLEN_IGNORE_ESC) + 4; + unsigned int len + = b_string_get_size( + str, B_STRLEN_IGNORE_ESC | B_STRLEN_IGNORE_MOD) + + 4; while (len < format.p_left_margin) { fputc(' ', OUTPUT_STREAM); len++; @@ -816,7 +830,7 @@ struct b_command_option *b_command_get_option_with_short_name( static void print_usage(struct b_command *cmd) { - b_paragraph_format format = {}; + b_paragraph_format format = {0}; format.p_left_margin = format.p_right_margin = 4; b_fprintf(OUTPUT_STREAM, F_YELLOW "USAGE:" F_RESET "\n"); @@ -847,7 +861,7 @@ static void print_usage(struct b_command *cmd) static void print_help(struct b_command *cmd) { - b_paragraph_format format = {}; + b_paragraph_format format = {0}; if (!cmd->b_parent) { b_fprintf(OUTPUT_STREAM, F_GREEN "%s" F_RESET "\n", cmd->b_name); diff --git a/cmd/command.h b/cmd/command.h index 3e1d34d..971d074 100644 --- a/cmd/command.h +++ b/cmd/command.h @@ -5,14 +5,14 @@ #include #include -#define F_RED "\033[91m" -#define F_GREEN "\033[92m" -#define F_YELLOW "\033[93m" +#define F_RED "[bright,red]" +#define F_GREEN "[bright,green]" +#define F_YELLOW "[bright,yellow]" -#define F_RED_BOLD "\033[1;91m" -#define F_GREEN_BOLD "\033[1;92m" -#define F_YELLOW_BOLD "\033[1;93m" -#define F_RESET "\033[0m" +#define F_RED_BOLD "[bright,bold,red]" +#define F_GREEN_BOLD "[bright,bold,green]" +#define F_YELLOW_BOLD "[bright,bold,yellow]" +#define F_RESET "[reset]" enum cmd_string_flags { CMD_STR_COLOUR = 0x01u, diff --git a/cmd/option.c b/cmd/option.c index cbc476b..50901a8 100644 --- a/cmd/option.c +++ b/cmd/option.c @@ -118,7 +118,7 @@ void z__b_get_option_description(struct b_command_option *opt, b_string *out) if (it.i > 0) { b_string_append_cstr(out, "; "); } else { - b_string_append_cstr(out, " ["); + b_string_append_cstr(out, " [["); close_bracket = true; }