degesch: add basic autocomplete for /topic

This commit is contained in:
Přemysl Eric Janouch 2016-01-04 22:06:29 +01:00
parent 0092c34568
commit 4832a99461
2 changed files with 30 additions and 1 deletions

2
NEWS
View File

@ -2,6 +2,8 @@
* Use TLS Server Name Indication when connecting to servers * Use TLS Server Name Indication when connecting to servers
* degesch: added autocomplete for /topic
* degesch: resolve remote addresses asynchronously * degesch: resolve remote addresses asynchronously
* degesch: various bugfixes * degesch: various bugfixes

View File

@ -1,7 +1,7 @@
/* /*
* degesch.c: the experimental IRC client * degesch.c: the experimental IRC client
* *
* Copyright (c) 2015, Přemysl Janouch <p.janouch@gmail.com> * Copyright (c) 2015 - 2016, Přemysl Janouch <p.janouch@gmail.com>
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * 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); 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 static void
complete_nicknames (struct app_context *ctx, struct completion *data, complete_nicknames (struct app_context *ctx, struct completion *data,
const char *word, struct str_vector *output) 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 // First figure out what exactly we need to complete
bool try_commands = false; bool try_commands = false;
bool try_options = false; bool try_options = false;
bool try_topic = false;
bool try_nicknames = false; bool try_nicknames = false;
if (data->location == 0 && completion_matches (data, 0, "/*")) if (data->location == 0 && completion_matches (data, 0, "/*"))
@ -10216,6 +10240,8 @@ complete_word (struct app_context *ctx, struct completion *data,
try_options = true; try_options = true;
else if (data->location == 1 && completion_matches (data, 0, "/help")) else if (data->location == 1 && completion_matches (data, 0, "/help"))
try_commands = try_options = true; try_commands = try_options = true;
else if (data->location == 1 && completion_matches (data, 0, "/topic"))
try_topic = try_nicknames = true;
else else
try_nicknames = true; 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_commands) complete_command (ctx, data, word, &words);
if (try_options) complete_option (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 (try_nicknames) complete_nicknames (ctx, data, word, &words);
if (words.len == 1) if (words.len == 1)