diff options
author | James Booth <boothj5@gmail.com> | 2012-05-10 23:51:06 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2012-05-10 23:51:06 +0100 |
commit | 46ee72f91664a6cabc5cb90123af08323d36788e (patch) | |
tree | 416280cda3542d6ab897aabf9c56c1b876d1139d | |
parent | d6f7862097fb35835f492fd908999bd525d54460 (diff) | |
download | profani-tty-46ee72f91664a6cabc5cb90123af08323d36788e.tar.gz |
Finished /connect tab completion
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | input_win.c | 18 | ||||
-rw-r--r-- | preferences.c | 17 | ||||
-rw-r--r-- | preferences.h | 3 |
4 files changed, 32 insertions, 8 deletions
diff --git a/Makefile b/Makefile index 7bc0e963..d06bff56 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ log.o: log.h windows.o: windows.h util.h contact_list.h preferences.h title_bar.o: windows.h status_bar.o: windows.h util.h -input_win.o: windows.h +input_win.o: windows.h preferences.h jabber.o: jabber.h log.h windows.h contact_list.h profanity.o: log.h windows.h jabber.h command.h preferences.h util.o: util.h diff --git a/input_win.c b/input_win.c index 5ed17d05..115fc0e8 100644 --- a/input_win.c +++ b/input_win.c @@ -38,9 +38,12 @@ #include <string.h> #include <stdlib.h> + #include <ncurses.h> + #include "windows.h" #include "history.h" +#include "preferences.h" static WINDOW *inp_win; @@ -120,6 +123,7 @@ void inp_get_char(int *ch, char *input, int *size) } reset_search_attempts(); + reset_login_search(); } } @@ -244,6 +248,20 @@ static int _handle_edit(const int ch, char *input, int *size) free(auto_msg); free(found); } + } else if ((strncmp(input, "/connect ", 9) == 0) && (*size > 9)) { + for(i = 9; i < *size; i++) { + inp_cpy[i-9] = input[i]; + } + inp_cpy[(*size) - 9] = '\0'; + found = find_login(inp_cpy); + if (found != NULL) { + auto_msg = (char *) malloc((9 + (strlen(found) + 1)) * sizeof(char)); + strcpy(auto_msg, "/connect "); + strcat(auto_msg, found); + _replace_input(input, auto_msg, size); + free(auto_msg); + free(found); + } } return 1; diff --git a/preferences.c b/preferences.c index 01cbc7ab..412fb526 100644 --- a/preferences.c +++ b/preferences.c @@ -25,6 +25,8 @@ #include <glib.h> +#include "preferences.h" + static GString *prefs_loc; static GKeyFile *prefs; @@ -35,7 +37,6 @@ static gchar *search_str = NULL; static void _save_prefs(void); static gint _compare_jids(gconstpointer a, gconstpointer b); -static void _reset_login_search(void); static gchar * _search_logins_from(GSList *curr); void prefs_load(void) @@ -53,11 +54,11 @@ void prefs_load(void) gsize i; for (i = 0; i < njids; i++) { - logins = g_slist_insert_sorted(logins, jids[0], _compare_jids); + logins = g_slist_insert_sorted(logins, jids[i], _compare_jids); } } -char * find_login(char *search_str) +char * find_login(char *prefix) { gchar *found = NULL; @@ -65,7 +66,7 @@ char * find_login(char *search_str) return NULL; if (last_found == NULL) { - search_str = g_strdup(search_str); + search_str = g_strdup(prefix); found = _search_logins_from(logins); return found; @@ -78,16 +79,18 @@ char * find_login(char *search_str) if (found != NULL) return found; - _reset_login_search(); + reset_login_search(); return NULL; } } -static void _reset_login_search(void) +void reset_login_search(void) { last_found = NULL; - if (search_str != NULL) + if (search_str != NULL) { free(search_str); + search_str = NULL; + } } static gchar * _search_logins_from(GSList *curr) diff --git a/preferences.h b/preferences.h index cb6586d2..8f2cfadc 100644 --- a/preferences.h +++ b/preferences.h @@ -27,6 +27,9 @@ void prefs_load(void); +char * find_login(char *prefix); +void reset_login_search(void); + gboolean prefs_get_beep(void); void prefs_set_beep(gboolean value); gboolean prefs_get_flash(void); |