about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-09-16 20:52:38 +0100
committerJames Booth <boothj5@gmail.com>2014-09-16 20:52:38 +0100
commit0d9a145d453f9d6b4653d75e9ab7c3179f32c695 (patch)
tree147f621d71fa0a9e798c56be16b671ab9bc13f46
parent728f1f014b9e63f8f093ebf411244673d9a9dbae (diff)
downloadprofani-tty-0d9a145d453f9d6b4653d75e9ab7c3179f32c695.tar.gz
Implemented /form help
-rw-r--r--src/command/command.c8
-rw-r--r--src/command/commands.c29
-rw-r--r--src/ui/core.c36
-rw-r--r--src/ui/ui.h3
4 files changed, 63 insertions, 13 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 0f820a33..a60cf9e5 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -317,15 +317,16 @@ static struct cmd_t command_defs[] =
 
     { "/form",
         cmd_form, parse_args, 1, 3, NULL,
-        { "/form show|submit|cancel|set|add|remove [tag value]", "Form manipulation.",
-        { "/form show|submit|cancel|set|add|remove [tag value]",
-          "---------------------------------------------------",
+        { "/form show|submit|cancel|set|add|remove|help [tag] [value]", "Form manipulation.",
+        { "/form show|submit|cancel|set|add|remove|help [tag] [value]",
+          "----------------------------------------------------------",
           "set tag value    - Set tagged form field to value.",
           "add tag value    - Add value to tagged form field.",
           "remove tag value - Remove value from tagged form field.",
           "show             - Show the current form.",
           "submit           - Submit the current form.",
           "cancel           - Cancel changes to the current form.",
+          "help [tag]       - Display help for form, or a specific field.",
           NULL } } },
 
     { "/rooms",
@@ -1233,6 +1234,7 @@ cmd_init(void)
     autocomplete_add(form_ac, "set");
     autocomplete_add(form_ac, "add");
     autocomplete_add(form_ac, "remove");
+    autocomplete_add(form_ac, "help");
 
     cmd_history_init();
 }
diff --git a/src/command/commands.c b/src/command/commands.c
index e96d2f7a..fa439955 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -634,12 +634,9 @@ cmd_help(gchar **args, struct cmd_help_t help)
         }
 
         cons_show("");
-
         if (help_text != NULL) {
-            int i;
-            for (i = 0; help_text[i] != NULL; i++) {
-                cons_show(help_text[i]);
-            }
+            ProfWin *console = wins_get_console();
+            ui_show_lines(console, help_text);
         } else {
             cons_show("No such command.");
         }
@@ -1806,6 +1803,7 @@ cmd_form(gchar **args, struct cmd_help_t help)
     if ((g_strcmp0(args[0], "submit") != 0) &&
             (g_strcmp0(args[0], "cancel") != 0) &&
             (g_strcmp0(args[0], "show") != 0) &&
+            (g_strcmp0(args[0], "help") != 0) &&
             (g_strcmp0(args[0], "set") != 0) &&
             (g_strcmp0(args[0], "add") != 0) &&
             (g_strcmp0(args[0], "remove") != 0)) {
@@ -1824,6 +1822,27 @@ cmd_form(gchar **args, struct cmd_help_t help)
         return TRUE;
     }
 
+    if (g_strcmp0(args[0], "help") == 0) {
+        char *tag = args[1];
+        if (tag != NULL) {
+            ui_show_form_field_help(current, current->form, tag);
+        } else {
+            ui_show_form_help(current, current->form);
+
+            const gchar **help_text = NULL;
+            Command *command = g_hash_table_lookup(commands, "/form");
+
+            if (command != NULL) {
+                help_text = command->help.long_help;
+            }
+
+            ui_show_lines(current, help_text);
+        }
+        ui_current_print_line("");
+        g_strfreev(split_recipient);
+        return TRUE;
+    }
+
     if (g_strcmp0(args[0], "submit") == 0) {
         iq_submit_room_config(room, current->form);
 
diff --git a/src/ui/core.c b/src/ui/core.c
index 5e1a13ce..b3e3f94e 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -2025,11 +2025,7 @@ _ui_show_form(ProfWin *window, const char * const room, DataForm *form)
     }
     win_save_print(window, '-', NULL, 0, 0, "", "");
 
-    if (form->instructions != NULL) {
-        win_save_vprint(window, '-', NULL, 0, 0, "", "Instructions:");
-        win_save_print(window, '-', NULL, 0, 0, "", form->instructions);
-        win_save_print(window, '-', NULL, 0, 0, "", "");
-    }
+    ui_show_form_help(window, form);
 
     GSList *fields = form->fields;
     GSList *curr_field = fields;
@@ -2085,6 +2081,33 @@ _ui_handle_room_config_submit_result(void)
 }
 
 static void
+_ui_show_form_field_help(ProfWin *window, DataForm *form, char *tag)
+{
+    win_save_println(window, "HELP FIELD");
+}
+
+static void
+_ui_show_form_help(ProfWin *window, DataForm *form)
+{
+    if (form->instructions != NULL) {
+        win_save_vprint(window, '-', NULL, 0, 0, "", "Instructions:");
+        win_save_print(window, '-', NULL, 0, 0, "", form->instructions);
+        win_save_print(window, '-', NULL, 0, 0, "", "");
+    }
+}
+
+static void
+_ui_show_lines(ProfWin *window, const gchar** lines)
+{
+    if (lines != NULL) {
+        int i;
+        for (i = 0; lines[i] != NULL; i++) {
+            win_save_print(window, '-', NULL, 0, 0, "", lines[i]);
+        }
+    }
+}
+
+static void
 _win_handle_switch(const wint_t * const ch)
 {
     if (*ch == KEY_F(1)) {
@@ -2326,4 +2349,7 @@ ui_init_module(void)
     ui_win_has_unsaved_form = _ui_win_has_unsaved_form;
     ui_show_form = _ui_show_form;
     ui_show_form_field = _ui_show_form_field;
+    ui_show_form_help = _ui_show_form_help;
+    ui_show_form_field_help = _ui_show_form_field_help;
+    ui_show_lines = _ui_show_lines;
 }
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 4790982f..52a93521 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -164,6 +164,9 @@ void (*ui_handle_room_configuration)(const char * const room, DataForm *form);
 void (*ui_handle_room_config_submit_result)(void);
 void (*ui_show_form)(ProfWin *window, const char * const room, DataForm *form);
 void (*ui_show_form_field)(ProfWin *window, DataForm *form, char *tag);
+void (*ui_show_form_help)(ProfWin *window, DataForm *form);
+void (*ui_show_form_field_help)(ProfWin *window, DataForm *form, char *tag);
+void (*ui_show_lines)(ProfWin *window, const gchar** lines);
 
 // contact status functions
 void (*ui_status_room)(const char * const contact);