From 36ebf0fc17f271e79445bfc320bef137bf3582bf Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 26 Jul 2015 01:27:42 +0100 Subject: Updated help category output --- src/command/command.c | 111 ++++++++++++++++++++----------------------------- src/command/commands.c | 81 +++++++++++++++++++++++------------- src/ui/console.c | 4 +- 3 files changed, 100 insertions(+), 96 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index fe332f4b..72b4a07a 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -3702,80 +3702,60 @@ command_docgen(void) while (curr) { Command *pcmd = curr->data; + fprintf(toc_fragment, "%s,\n", &pcmd->cmd[1], pcmd->cmd); + fprintf(main_fragment, "\n", &pcmd->cmd[1]); + fprintf(main_fragment, "

%s

\n", pcmd->cmd); - // old style - if (pcmd->help.usage) { -// fprintf(toc_fragment, "%s,\n", &pcmd->cmd[1], pcmd->cmd); -// fprintf(main_fragment, "\n", &pcmd->cmd[1]); -// fprintf(main_fragment, "

%s

\n", pcmd->cmd); -// fputs("

Usage:

\n", main_fragment); -// fprintf(main_fragment, "

%s

\n", pcmd->help.usage); -// -// fputs("

Details:

\n", main_fragment); -// fputs("

", main_fragment);
-//            int i = 2;
-//            while (pcmd->help.long_help[i]) {
-//                fprintf(main_fragment, "%s\n", pcmd->help.long_help[i++]);
-//            }
-//            fputs("

\n
back to top


\n", main_fragment); -// fputs("\n", main_fragment); - - // new style - } else { - fprintf(toc_fragment, "%s,\n", &pcmd->cmd[1], pcmd->cmd); - fprintf(main_fragment, "\n", &pcmd->cmd[1]); - fprintf(main_fragment, "

%s

\n", pcmd->cmd); + fputs("

Synopsis

\n", main_fragment); + fputs("

", main_fragment);
+        int i = 0;
+        while (pcmd->help.synopsis[i]) {
+            char *str1 = str_replace(pcmd->help.synopsis[i], "<", "<");
+            char *str2 = str_replace(str1, ">", ">");
+            fprintf(main_fragment, "%s\n", str2);
+            i++;
+        }
+        fputs("

\n", main_fragment); + + fputs("

Description

\n", main_fragment); + fputs("

", main_fragment); + fprintf(main_fragment, "%s\n", pcmd->help.desc); + fputs("

\n", main_fragment); + + if (pcmd->help.args[0][0] != NULL) { + fputs("

Arguments

\n", main_fragment); + fputs("", main_fragment); + for (i = 0; pcmd->help.args[i][0] != NULL; i++) { + fputs("", main_fragment); + fputs("", main_fragment); + fputs("", main_fragment); + fputs("", main_fragment); + } + fputs("
", main_fragment); + fputs("", main_fragment); + char *str1 = str_replace(pcmd->help.args[i][0], "<", "<"); + char *str2 = str_replace(str1, ">", ">"); + fprintf(main_fragment, "%s", str2); + fputs("", main_fragment); + fputs("", main_fragment); + fprintf(main_fragment, "%s", pcmd->help.args[i][1]); + fputs("
\n", main_fragment); + } - fputs("

Synopsis

\n", main_fragment); + if (pcmd->help.examples[0] != NULL) { + fputs("

Examples

\n", main_fragment); fputs("

", main_fragment);
             int i = 0;
-            while (pcmd->help.synopsis[i]) {
-                char *str1 = str_replace(pcmd->help.synopsis[i], "<", "<");
-                char *str2 = str_replace(str1, ">", ">");
-                fprintf(main_fragment, "%s\n", str2);
+            while (pcmd->help.examples[i]) {
+                fprintf(main_fragment, "%s\n", pcmd->help.examples[i]);
                 i++;
             }
             fputs("

\n", main_fragment); + } - fputs("

Description

\n", main_fragment); - fputs("

", main_fragment); - fprintf(main_fragment, "%s\n", pcmd->help.desc); - fputs("

\n", main_fragment); - - if (pcmd->help.args[0][0] != NULL) { - fputs("

Arguments

\n", main_fragment); - fputs("", main_fragment); - for (i = 0; pcmd->help.args[i][0] != NULL; i++) { - fputs("", main_fragment); - fputs("", main_fragment); - fputs("", main_fragment); - fputs("", main_fragment); - } - fputs("
", main_fragment); - fputs("", main_fragment); - char *str1 = str_replace(pcmd->help.args[i][0], "<", "<"); - char *str2 = str_replace(str1, ">", ">"); - fprintf(main_fragment, "%s", str2); - fputs("", main_fragment); - fputs("", main_fragment); - fprintf(main_fragment, "%s", pcmd->help.args[i][1]); - fputs("
\n", main_fragment); - } + fputs("
back to top


\n", main_fragment); + fputs("\n", main_fragment); - if (pcmd->help.examples[0] != NULL) { - fputs("

Examples

\n", main_fragment); - fputs("

", main_fragment);
-                int i = 0;
-                while (pcmd->help.examples[i]) {
-                    fprintf(main_fragment, "%s\n", pcmd->help.examples[i]);
-                    i++;
-                }
-                fputs("

\n", main_fragment); - } - - fputs("
back to top


\n", main_fragment); - fputs("\n", main_fragment); - } curr = g_list_next(curr); } @@ -3783,5 +3763,6 @@ command_docgen(void) fclose(toc_fragment); fclose(main_fragment); + printf("\nProcessed %d commands.\n\n", g_list_length(cmds)); g_list_free(cmds); } diff --git a/src/command/commands.c b/src/command/commands.c index b5babf3c..f8979aec 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -76,7 +76,6 @@ static void _update_presence(const resource_presence_t presence, static gboolean _cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help, const char * const display, preference_t pref); static void _cmd_show_filtered_help(char *heading, gchar *cmd_filter[], int filter_size); -static gint _compare_commands(Command *a, Command *b); static void _who_room(ProfWin *window, gchar **args, struct cmd_help_t help); static void _who_roster(ProfWin *window, gchar **args, struct cmd_help_t help); @@ -779,8 +778,8 @@ cmd_help(ProfWin *window, gchar **args, struct cmd_help_t help) cons_help(); } else if (strcmp(args[0], "commands") == 0) { cons_show(""); - cons_show("All commands"); - cons_show(""); + ProfWin *console = wins_get_console(); + win_print(console, '-', NULL, 0, THEME_WHITE_BOLD, "", "All commands"); GList *ordered_commands = NULL; GHashTableIter iter; @@ -789,15 +788,36 @@ cmd_help(ProfWin *window, gchar **args, struct cmd_help_t help) g_hash_table_iter_init(&iter, commands); while (g_hash_table_iter_next(&iter, &key, &value)) { - ordered_commands = g_list_insert_sorted(ordered_commands, value, (GCompareFunc)_compare_commands); + Command *pcmd = (Command *)value; + ordered_commands = g_list_insert_sorted(ordered_commands, pcmd->cmd, (GCompareFunc)g_strcmp0); } + int maxlen = 0; GList *curr = ordered_commands; while (curr) { - Command *cmd = curr->data; - cons_show("%-13s: %s", cmd->cmd, cmd->help.short_help); + gchar *cmd = curr->data; + int len = strlen(cmd); + if (len > maxlen) maxlen = len; + curr = g_list_next(curr); + } + + GString *cmds = g_string_new(""); + curr = ordered_commands; + int count = 0; + while (curr) { + gchar *cmd = curr->data; + if (count == 5) { + cons_show(cmds->str); + g_string_free(cmds, TRUE); + cmds = g_string_new(""); + count = 0; + } + g_string_append_printf(cmds, "%-*s", maxlen + 1, cmd); curr = g_list_next(curr); + count++; } + cons_show(cmds->str); + g_string_free(cmds, TRUE); g_list_free(ordered_commands); g_list_free(curr); @@ -4748,23 +4768,43 @@ _cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help, static void _cmd_show_filtered_help(char *heading, gchar *cmd_filter[], int filter_size) { + ProfWin *console = wins_get_console(); cons_show(""); - cons_show("%s", heading); - cons_show(""); + win_print(console, '-', NULL, 0, THEME_WHITE_BOLD, "", heading); GList *ordered_commands = NULL; int i; for (i = 0; i < filter_size; i++) { - Command *cmd = g_hash_table_lookup(commands, cmd_filter[i]); - ordered_commands = g_list_insert_sorted(ordered_commands, cmd, (GCompareFunc)_compare_commands); + Command *pcmd = g_hash_table_lookup(commands, cmd_filter[i]); + ordered_commands = g_list_insert_sorted(ordered_commands, pcmd->cmd, (GCompareFunc)g_strcmp0); } + int maxlen = 0; GList *curr = ordered_commands; while (curr) { - Command *cmd = curr->data; - cons_show("%-12s: %s", cmd->cmd, cmd->help.short_help); + gchar *cmd = curr->data; + int len = strlen(cmd); + if (len > maxlen) maxlen = len; + curr = g_list_next(curr); + } + + GString *cmds = g_string_new(""); + curr = ordered_commands; + int count = 0; + while (curr) { + gchar *cmd = curr->data; + if (count == 5) { + cons_show(cmds->str); + g_string_free(cmds, TRUE); + cmds = g_string_new(""); + count = 0; + } + g_string_append_printf(cmds, "%-*s", maxlen + 1, cmd); curr = g_list_next(curr); + count++; } + cons_show(cmds->str); + g_string_free(cmds, TRUE); g_list_free(ordered_commands); g_list_free(curr); @@ -4772,20 +4812,3 @@ _cmd_show_filtered_help(char *heading, gchar *cmd_filter[], int filter_size) cons_show("Use /help [command] without the leading slash, for help on a specific command"); cons_show(""); } - -static -gint _compare_commands(Command *a, Command *b) -{ - const char * utf8_str_a = a->cmd; - const char * utf8_str_b = b->cmd; - - gchar *key_a = g_utf8_collate_key(utf8_str_a, -1); - gchar *key_b = g_utf8_collate_key(utf8_str_b, -1); - - gint result = g_strcmp0(key_a, key_b); - - g_free(key_a); - g_free(key_b); - - return result; -} diff --git a/src/ui/console.c b/src/ui/console.c index 20f6803e..67c1da58 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1533,9 +1533,9 @@ cons_help(void) void cons_navigation_help(void) { + ProfWin *console = wins_get_console(); cons_show(""); - cons_show("Navigation:"); - cons_show(""); + win_print(console, '-', NULL, 0, THEME_WHITE_BOLD, "", "Navigation"); cons_show("Alt-1..Alt-0, F1..F10 : Choose window."); cons_show("Alt-LEFT, Alt-RIGHT : Previous/next chat window"); cons_show("PAGEUP, PAGEDOWN : Page the main window."); -- cgit 1.4.1-2-gfad0