1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Finished /connect tab completion

This commit is contained in:
James Booth 2012-05-10 23:51:06 +01:00
parent d6f7862097
commit 46ee72f916
4 changed files with 32 additions and 8 deletions

View File

@ -18,7 +18,7 @@ log.o: log.h
windows.o: windows.h util.h contact_list.h preferences.h windows.o: windows.h util.h contact_list.h preferences.h
title_bar.o: windows.h title_bar.o: windows.h
status_bar.o: windows.h util.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 jabber.o: jabber.h log.h windows.h contact_list.h
profanity.o: log.h windows.h jabber.h command.h preferences.h profanity.o: log.h windows.h jabber.h command.h preferences.h
util.o: util.h util.o: util.h

View File

@ -38,9 +38,12 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <ncurses.h> #include <ncurses.h>
#include "windows.h" #include "windows.h"
#include "history.h" #include "history.h"
#include "preferences.h"
static WINDOW *inp_win; static WINDOW *inp_win;
@ -120,6 +123,7 @@ void inp_get_char(int *ch, char *input, int *size)
} }
reset_search_attempts(); 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(auto_msg);
free(found); 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; return 1;

View File

@ -25,6 +25,8 @@
#include <glib.h> #include <glib.h>
#include "preferences.h"
static GString *prefs_loc; static GString *prefs_loc;
static GKeyFile *prefs; static GKeyFile *prefs;
@ -35,7 +37,6 @@ static gchar *search_str = NULL;
static void _save_prefs(void); static void _save_prefs(void);
static gint _compare_jids(gconstpointer a, gconstpointer b); static gint _compare_jids(gconstpointer a, gconstpointer b);
static void _reset_login_search(void);
static gchar * _search_logins_from(GSList *curr); static gchar * _search_logins_from(GSList *curr);
void prefs_load(void) void prefs_load(void)
@ -53,11 +54,11 @@ void prefs_load(void)
gsize i; gsize i;
for (i = 0; i < njids; 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; gchar *found = NULL;
@ -65,7 +66,7 @@ char * find_login(char *search_str)
return NULL; return NULL;
if (last_found == NULL) { if (last_found == NULL) {
search_str = g_strdup(search_str); search_str = g_strdup(prefix);
found = _search_logins_from(logins); found = _search_logins_from(logins);
return found; return found;
@ -78,16 +79,18 @@ char * find_login(char *search_str)
if (found != NULL) if (found != NULL)
return found; return found;
_reset_login_search(); reset_login_search();
return NULL; return NULL;
} }
} }
static void _reset_login_search(void) void reset_login_search(void)
{ {
last_found = NULL; last_found = NULL;
if (search_str != NULL) if (search_str != NULL) {
free(search_str); free(search_str);
search_str = NULL;
}
} }
static gchar * _search_logins_from(GSList *curr) static gchar * _search_logins_from(GSList *curr)

View File

@ -27,6 +27,9 @@
void prefs_load(void); void prefs_load(void);
char * find_login(char *prefix);
void reset_login_search(void);
gboolean prefs_get_beep(void); gboolean prefs_get_beep(void);
void prefs_set_beep(gboolean value); void prefs_set_beep(gboolean value);
gboolean prefs_get_flash(void); gboolean prefs_get_flash(void);