about summary refs log tree commit diff stats
path: root/src/input_win.c
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-10-28 00:12:39 +0100
committerJames Booth <boothj5@gmail.com>2012-10-28 00:12:39 +0100
commit86adbc497361da1bf2a54201e3bdc07f3eca401b (patch)
tree280e12fb6c4228fbf53b20b95e640edfa90690ef /src/input_win.c
parent7e26fcdf84e649ed25a0f8ec98ea44c7bf592113 (diff)
downloadprofani-tty-86adbc497361da1bf2a54201e3bdc07f3eca401b.tar.gz
Added autocomplete for second /notify parameter
Diffstat (limited to 'src/input_win.c')
-rw-r--r--src/input_win.c58
1 files changed, 56 insertions, 2 deletions
diff --git a/src/input_win.c b/src/input_win.c
index b69e3feb..330b6443 100644
--- a/src/input_win.c
+++ b/src/input_win.c
@@ -68,6 +68,7 @@ static int _printable(const int ch);
 static void _replace_input(char *input, const char * const new_input, int *size);
 static void _parameter_autocomplete(char *input, int *size, char *command,
     autocomplete_func func);
+static void _notify_autocomplete(char *input, int *size);
 
 void
 create_input_window(void)
@@ -361,8 +362,6 @@ _handle_edit(const int ch, char *input, int *size)
             cmd_help_complete);
         _parameter_autocomplete(input, size, "/beep",
             prefs_autocomplete_boolean_choice);
-        _parameter_autocomplete(input, size, "/notify",
-            cmd_notify_complete);
         _parameter_autocomplete(input, size, "/flash",
             prefs_autocomplete_boolean_choice);
         _parameter_autocomplete(input, size, "/showsplash",
@@ -374,6 +373,8 @@ _handle_edit(const int ch, char *input, int *size)
         _parameter_autocomplete(input, size, "/vercheck",
             prefs_autocomplete_boolean_choice);
 
+        _notify_autocomplete(input, size);
+
         return 1;
 
     default:
@@ -433,3 +434,56 @@ _parameter_autocomplete(char *input, int *size, char *command,
     }
     free(command_cpy);
 }
+
+static void
+_notify_autocomplete(char *input, int *size)
+{
+    char *found = NULL;
+    char *auto_msg = NULL;
+    char inp_cpy[*size];
+    int i;
+
+    if ((strncmp(input, "/notify message ", 16) == 0) && (*size > 16)) {
+        for(i = 16; i < *size; i++) {
+            inp_cpy[i-16] = input[i];
+        }
+        inp_cpy[(*size) - 16] = '\0';
+        found = prefs_autocomplete_boolean_choice(inp_cpy);
+        if (found != NULL) {
+            auto_msg = (char *) malloc((16 + (strlen(found) + 1)) * sizeof(char));
+            strcpy(auto_msg, "/notify message ");
+            strcat(auto_msg, found);
+            _replace_input(input, auto_msg, size);
+            free(auto_msg);
+            free(found);
+        }
+    } else if ((strncmp(input, "/notify typing ", 15) == 0) && (*size > 15)) {
+        for(i = 15; i < *size; i++) {
+            inp_cpy[i-15] = input[i];
+        }
+        inp_cpy[(*size) - 15] = '\0';
+        found = prefs_autocomplete_boolean_choice(inp_cpy);
+        if (found != NULL) {
+            auto_msg = (char *) malloc((15 + (strlen(found) + 1)) * sizeof(char));
+            strcpy(auto_msg, "/notify typing ");
+            strcat(auto_msg, found);
+            _replace_input(input, auto_msg, size);
+            free(auto_msg);
+            free(found);
+        }
+    } else if ((strncmp(input, "/notify ", 8) == 0) && (*size > 8)) {
+        for(i = 8; i < *size; i++) {
+            inp_cpy[i-8] = input[i];
+        }
+        inp_cpy[(*size) - 8] = '\0';
+        found = cmd_notify_complete(inp_cpy);
+        if (found != NULL) {
+            auto_msg = (char *) malloc((8 + (strlen(found) + 1)) * sizeof(char));
+            strcpy(auto_msg, "/notify ");
+            strcat(auto_msg, found);
+            _replace_input(input, auto_msg, size);
+            free(auto_msg);
+            free(found);
+        }
+    }
+}