about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-07-26 01:27:42 +0100
committerJames Booth <boothj5@gmail.com>2015-07-26 01:27:42 +0100
commit36ebf0fc17f271e79445bfc320bef137bf3582bf (patch)
tree42684c14611e0e991e50920813684f8d2411f4c3
parentcb7504e67f6d7e7a48dac96d7d2c6ef1a373873f (diff)
downloadprofani-tty-36ebf0fc17f271e79445bfc320bef137bf3582bf.tar.gz
Updated help category output
-rw-r--r--src/command/command.c111
-rw-r--r--src/command/commands.c81
-rw-r--r--src/ui/console.c4
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, "<a href=\"#%s\">%s</a>,\n", &pcmd->cmd[1], pcmd->cmd);
+        fprintf(main_fragment, "<a name=\"%s\"></a>\n", &pcmd->cmd[1]);
+        fprintf(main_fragment, "<h4>%s</h4>\n", pcmd->cmd);
 
-        // old style
-        if (pcmd->help.usage) {
-//            fprintf(toc_fragment, "<a href=\"#%s\">%s</a>,\n", &pcmd->cmd[1], pcmd->cmd);
-//            fprintf(main_fragment, "<a name=\"%s\"></a>\n", &pcmd->cmd[1]);
-//            fprintf(main_fragment, "<h4>%s</h4>\n", pcmd->cmd);
-//            fputs("<p>Usage:</p>\n", main_fragment);
-//            fprintf(main_fragment, "<p><pre><code>%s</code></pre></p>\n", pcmd->help.usage);
-//
-//            fputs("<p>Details:</p>\n", main_fragment);
-//            fputs("<p><pre><code>", main_fragment);
-//            int i = 2;
-//            while (pcmd->help.long_help[i]) {
-//                fprintf(main_fragment, "%s\n", pcmd->help.long_help[i++]);
-//            }
-//            fputs("</code></pre></p>\n<a href=\"#top\"><h5>back to top</h5></a><br><hr>\n", main_fragment);
-//            fputs("\n", main_fragment);
-
-        // new style
-        } else {
-            fprintf(toc_fragment, "<a href=\"#%s\">%s</a>,\n", &pcmd->cmd[1], pcmd->cmd);
-            fprintf(main_fragment, "<a name=\"%s\"></a>\n", &pcmd->cmd[1]);
-            fprintf(main_fragment, "<h4>%s</h4>\n", pcmd->cmd);
+        fputs("<p><b>Synopsis</b></p>\n", main_fragment);
+        fputs("<p><pre><code>", main_fragment);
+        int i = 0;
+        while (pcmd->help.synopsis[i]) {
+            char *str1 = str_replace(pcmd->help.synopsis[i], "<", "&lt;");
+            char *str2 = str_replace(str1, ">", "&gt;");
+            fprintf(main_fragment, "%s\n", str2);
+            i++;
+        }
+        fputs("</code></pre></p>\n", main_fragment);
+
+        fputs("<p><b>Description</b></p>\n", main_fragment);
+        fputs("<p>", main_fragment);
+        fprintf(main_fragment, "%s\n", pcmd->help.desc);
+        fputs("</p>\n", main_fragment);
+
+        if (pcmd->help.args[0][0] != NULL) {
+            fputs("<p><b>Arguments</b></p>\n", main_fragment);
+            fputs("<table>", main_fragment);
+            for (i = 0; pcmd->help.args[i][0] != NULL; i++) {
+                fputs("<tr>", main_fragment);
+                fputs("<td>", main_fragment);
+                fputs("<code>", main_fragment);
+                char *str1 = str_replace(pcmd->help.args[i][0], "<", "&lt;");
+                char *str2 = str_replace(str1, ">", "&gt;");
+                fprintf(main_fragment, "%s", str2);
+                fputs("</code>", main_fragment);
+                fputs("</td>", main_fragment);
+                fputs("<td>", main_fragment);
+                fprintf(main_fragment, "%s", pcmd->help.args[i][1]);
+                fputs("</td>", main_fragment);
+                fputs("</tr>", main_fragment);
+            }
+            fputs("</table>\n", main_fragment);
+        }
 
-            fputs("<p><b>Synopsis</b></p>\n", main_fragment);
+        if (pcmd->help.examples[0] != NULL) {
+            fputs("<p><b>Examples</b></p>\n", main_fragment);
             fputs("<p><pre><code>", main_fragment);
             int i = 0;
-            while (pcmd->help.synopsis[i]) {
-                char *str1 = str_replace(pcmd->help.synopsis[i], "<", "&lt;");
-                char *str2 = str_replace(str1, ">", "&gt;");
-                fprintf(main_fragment, "%s\n", str2);
+            while (pcmd->help.examples[i]) {
+                fprintf(main_fragment, "%s\n", pcmd->help.examples[i]);
                 i++;
             }
             fputs("</code></pre></p>\n", main_fragment);
+        }
 
-            fputs("<p><b>Description</b></p>\n", main_fragment);
-            fputs("<p>", main_fragment);
-            fprintf(main_fragment, "%s\n", pcmd->help.desc);
-            fputs("</p>\n", main_fragment);
-
-            if (pcmd->help.args[0][0] != NULL) {
-                fputs("<p><b>Arguments</b></p>\n", main_fragment);
-                fputs("<table>", main_fragment);
-                for (i = 0; pcmd->help.args[i][0] != NULL; i++) {
-                    fputs("<tr>", main_fragment);
-                    fputs("<td>", main_fragment);
-                    fputs("<code>", main_fragment);
-                    char *str1 = str_replace(pcmd->help.args[i][0], "<", "&lt;");
-                    char *str2 = str_replace(str1, ">", "&gt;");
-                    fprintf(main_fragment, "%s", str2);
-                    fputs("</code>", main_fragment);
-                    fputs("</td>", main_fragment);
-                    fputs("<td>", main_fragment);
-                    fprintf(main_fragment, "%s", pcmd->help.args[i][1]);
-                    fputs("</td>", main_fragment);
-                    fputs("</tr>", main_fragment);
-                }
-                fputs("</table>\n", main_fragment);
-            }
+        fputs("<a href=\"#top\"><h5>back to top</h5></a><br><hr>\n", main_fragment);
+        fputs("\n", main_fragment);
 
-            if (pcmd->help.examples[0] != NULL) {
-                fputs("<p><b>Examples</b></p>\n", main_fragment);
-                fputs("<p><pre><code>", main_fragment);
-                int i = 0;
-                while (pcmd->help.examples[i]) {
-                    fprintf(main_fragment, "%s\n", pcmd->help.examples[i]);
-                    i++;
-                }
-                fputs("</code></pre></p>\n", main_fragment);
-            }
-
-            fputs("<a href=\"#top\"><h5>back to top</h5></a><br><hr>\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.");