about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-03-10 22:32:07 +0000
committerJames Booth <boothj5@gmail.com>2012-03-10 22:32:07 +0000
commitf928fb36250bab2ad5829a07a04b7ecde47f728c (patch)
treeb2d49e4becb52430f01e012db721df085e18fe56
parentf23f768d5451f540b05321af575e8fcf094738a0 (diff)
downloadprofani-tty-f928fb36250bab2ad5829a07a04b7ecde47f728c.tar.gz
Started autocomplete contact
Currently autocompletes first match
-rw-r--r--input_win.c24
-rw-r--r--test_contact_list.c7
2 files changed, 30 insertions, 1 deletions
diff --git a/input_win.c b/input_win.c
index 06540bf1..1714dc82 100644
--- a/input_win.c
+++ b/input_win.c
@@ -37,6 +37,7 @@
  */
 
 #include <string.h>
+#include <stdlib.h>
 #include <ncurses.h>
 #include "windows.h"
 #include "history.h"
@@ -138,8 +139,11 @@ static int _handle_edit(const int ch, char *input, int *size)
     int i;
     char *prev = NULL;
     char *next = NULL;
+    char *found = NULL;
+    char *auto_msg = NULL;
     int inp_y = 0;
     int inp_x = 0;
+    char inp_cpy[*size];
     
     getyx(inp_win, inp_y, inp_x);
 
@@ -191,6 +195,23 @@ static int _handle_edit(const int ch, char *input, int *size)
             _replace_input(input, next, size);
         return 1;
 
+    case 9: // tab
+        if ((strncmp(input, "/msg ", 5) == 0) && (*size > 5)) {
+            for(i = 5; i < *size; i++) {
+                inp_cpy[i-5] = input[i];
+            }
+            inp_cpy[(*size) - 5] = '\0';
+            found = find_contact(inp_cpy);
+            if (found != NULL) {
+                auto_msg = (char *) malloc((5 + (strlen(found) + 1)) * sizeof(char));
+                strcpy(auto_msg, "/msg ");
+                strcat(auto_msg, found);
+                _replace_input(input, auto_msg, size);
+                free(auto_msg);
+            }
+        }
+        return 1;
+
     default:
         return 0;
     }
@@ -198,7 +219,8 @@ static int _handle_edit(const int ch, char *input, int *size)
 
 static int _printable(const int ch)
 {
-   return (ch != ERR && ch != '\n' && ch != KEY_PPAGE && ch != KEY_NPAGE &&
+   return (ch != ERR && ch != '\n' && 
+            ch != KEY_PPAGE && ch != KEY_NPAGE &&
             ch != KEY_F(1) && ch != KEY_F(2) && ch != KEY_F(3) && 
             ch != KEY_F(4) && ch != KEY_F(5) && ch != KEY_F(6) &&
             ch != KEY_F(7) && ch != KEY_F(8) && ch != KEY_F(9) &&
diff --git a/test_contact_list.c b/test_contact_list.c
index 8c205faf..92972651 100644
--- a/test_contact_list.c
+++ b/test_contact_list.c
@@ -353,6 +353,12 @@ static void find_returns_null(void)
     assert_is_null(result);
 }
 
+static void find_on_empty_returns_null(void)
+{
+    char *result = find_contact("James");
+    assert_is_null(result);
+}
+
 void register_contact_list_tests(void)
 {
     TEST_MODULE("contact_list tests");
@@ -387,4 +393,5 @@ void register_contact_list_tests(void)
     TEST(find_second_exists);
     TEST(find_third_exists);
     TEST(find_returns_null);
+    TEST(find_on_empty_returns_null);
 }