Commits

Anonymous committed 5a149f2

added completion for fast replies

Comments (0)

Files changed (1)

 static char *password = NULL;
 static char *autojoin = NULL;
 
+static char last_nickname[256] = "";
+
 static void irc_display(const char *fmt, ...);
 
 #include "config.h"
 	if (strcmp("PONG", cmd) == 0) return;
 	if (strcmp("PRIVMSG", cmd) == 0) {
 		user_message(arg, usr, msg);
+		strncpy(last_nickname, usr, sizeof(last_nickname) - 1);
 	} else if (strcmp("PING", cmd) == 0) {
 		irc_send("PONG %s", msg);
 	} else {
 	return 0;
 }
 
+static char **reply_complete(const char *text, int start, int end) {
+	char **matches;
+
+	if (strlen(text) == 0 && start == 0 && strlen(last_nickname) > 0) {
+		matches = malloc(2 * sizeof(char *));
+		matches[0] = malloc(strlen(last_nickname) + 4);
+		strcpy(matches[0], ":m ");
+		strcat(matches[0], last_nickname);
+		matches[1] = NULL;
+		return matches;
+	} else {
+		return NULL;
+	}
+}
+
 static void usage() {
 	printf("Usage:\n"
 			"  six [-p port] [-n nick] [-j channel] [-N] [ -s script ] [-k password] host\n\n");
 
 	/* prepare readline: set handler for CRLF, enable async mode */
 	rl_callback_handler_install(prompt(), rl_handler);
+	rl_attempted_completion_function = reply_complete;
 	rl_bind_key((int) '\n', rl_newline_handler);
 	rl_bind_key((int) '\r', rl_newline_handler);
+	rl_bind_key((int) '\t', rl_complete);
 	rl_erase_empty_line = 1;
 
 	if (nick == NULL) {