From 4832a994616bb9e7b8037cc1e58c96fc84da85e5 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Mon, 4 Jan 2016 22:06:29 +0100 Subject: degesch: add basic autocomplete for /topic --- NEWS | 2 ++ degesch.c | 29 ++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index fccdfbc..d9ef75e 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,8 @@ * Use TLS Server Name Indication when connecting to servers + * degesch: added autocomplete for /topic + * degesch: resolve remote addresses asynchronously * degesch: various bugfixes diff --git a/degesch.c b/degesch.c index 7163098..0a8d4b5 100644 --- a/degesch.c +++ b/degesch.c @@ -1,7 +1,7 @@ /* * degesch.c: the experimental IRC client * - * Copyright (c) 2015, Přemysl Janouch + * Copyright (c) 2015 - 2016, Přemysl Janouch * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -10175,6 +10175,29 @@ complete_option (struct app_context *ctx, struct completion *data, str_vector_free (&options); } +static void +complete_topic (struct app_context *ctx, struct completion *data, + const char *word, struct str_vector *output) +{ + (void) data; + + // TODO: make it work in other server-related buffers, too, i.e. when we're + // completing the third word and the second word is a known channel name + struct buffer *buffer = ctx->current_buffer; + if (buffer->type != BUFFER_CHANNEL) + return; + + const char *topic = buffer->channel->topic; + if (topic && !strncasecmp_ascii (word, topic, strlen (word))) + { + // We must prepend the channel name if the topic itself starts + // with something that could be regarded as a channel name + str_vector_add_owned (output, irc_is_channel (buffer->server, topic) + ? xstrdup_printf ("%s %s", buffer->channel->name, topic) + : xstrdup (topic)); + } +} + static void complete_nicknames (struct app_context *ctx, struct completion *data, const char *word, struct str_vector *output) @@ -10208,6 +10231,7 @@ complete_word (struct app_context *ctx, struct completion *data, // First figure out what exactly we need to complete bool try_commands = false; bool try_options = false; + bool try_topic = false; bool try_nicknames = false; if (data->location == 0 && completion_matches (data, 0, "/*")) @@ -10216,6 +10240,8 @@ complete_word (struct app_context *ctx, struct completion *data, try_options = true; else if (data->location == 1 && completion_matches (data, 0, "/help")) try_commands = try_options = true; + else if (data->location == 1 && completion_matches (data, 0, "/topic")) + try_topic = try_nicknames = true; else try_nicknames = true; @@ -10227,6 +10253,7 @@ complete_word (struct app_context *ctx, struct completion *data, if (try_commands) complete_command (ctx, data, word, &words); if (try_options) complete_option (ctx, data, word, &words); + if (try_topic) complete_topic (ctx, data, word, &words); if (try_nicknames) complete_nicknames (ctx, data, word, &words); if (words.len == 1) -- cgit v1.2.3-70-g09d2