From 51ca5c79e4174a67aa1e50402c28ecf0a06798e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Janouch?= Date: Wed, 15 Apr 2015 16:18:43 +0200 Subject: [PATCH] degesch: show active buffers in prompt --- degesch.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/degesch.c b/degesch.c index 358e592..1786770 100644 --- a/degesch.c +++ b/degesch.c @@ -1216,6 +1216,31 @@ irc_establish_connection (struct app_context *ctx, // --- More readline funky stuff ----------------------------------------------- +static char * +get_unseen_prefix (struct app_context *ctx) +{ + struct str active_buffers; + str_init (&active_buffers); + + size_t i = 0; + LIST_FOR_EACH (struct buffer, iter, ctx->buffers) + { + i++; + if (!iter->unseen_messages_count) + continue; + + if (active_buffers.len) + str_append_c (&active_buffers, ','); + str_append_printf (&active_buffers, "%zu", i); + } + + if (active_buffers.len) + return str_steal (&active_buffers); + + str_free (&active_buffers); + return NULL; +} + static void refresh_prompt (struct app_context *ctx) { @@ -1229,8 +1254,11 @@ refresh_prompt (struct app_context *ctx) else { str_append_c (&prompt, '['); - // TODO: go through all buffers and prepend the active ones, - // such as "(1,4) " + + char *unseen_prefix = get_unseen_prefix (ctx); + if (unseen_prefix) + str_append_printf (&prompt, "(%s) ", unseen_prefix); + free (unseen_prefix); // TODO: name of the current buffer // TODO: the channel user mode