From 08c00273973b57e346f65b301f905bd290a00327 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Wed, 15 Apr 2015 16:54:05 +0200 Subject: degesch: more buffer-related stuff --- degesch.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 8 deletions(-) diff --git a/degesch.c b/degesch.c index 1786770..af2ffac 100644 --- a/degesch.c +++ b/degesch.c @@ -200,6 +200,7 @@ struct buffer // Channel information: + char *mode; ///< Channel mode char *topic; ///< Channel topic struct str_map nicks; ///< Maps nicks to "nick_info" }; @@ -220,6 +221,7 @@ buffer_destroy (struct buffer *self) free (self->name); // Can't really free "history" here free (self->saved_line); + free (self->mode); free (self->topic); str_map_free (&self->nicks); free (self); @@ -253,6 +255,13 @@ struct app_context SSL_CTX *ssl_ctx; ///< SSL context SSL *ssl; ///< SSL connection + // TODO: initialize and update these two values + // TODO: probably issue a USERHOST message for ourselves after connecting + // to enable proper word-wrapping; then store it here also, separately, + // without the nickname at the beginning; also could just use WHOIS + char *irc_nickname; ///< Current nickname + char *irc_user_mode; ///< Current user mode + // Events: struct poller_fd tty_event; ///< Terminal input event @@ -353,6 +362,9 @@ app_context_free (struct app_context *self) if (self->ssl_ctx) SSL_CTX_free (self->ssl_ctx); + free (self->irc_nickname); + free (self->irc_user_mode); + LIST_FOR_EACH (struct buffer, iter, self->buffers) buffer_destroy (iter); str_map_free (&self->buffers_by_name); @@ -1251,8 +1263,9 @@ refresh_prompt (struct app_context *ctx) if (!ctx->irc_ready) str_append (&prompt, "(disconnected)"); - else + else if (soft_assert (ctx->current_buffer)) { + struct buffer *buffer = ctx->current_buffer; str_append_c (&prompt, '['); char *unseen_prefix = get_unseen_prefix (ctx); @@ -1260,10 +1273,14 @@ refresh_prompt (struct app_context *ctx) str_append_printf (&prompt, "(%s) ", unseen_prefix); free (unseen_prefix); - // TODO: name of the current buffer - // TODO: the channel user mode - str_append (&prompt, str_map_find (&ctx->config, "nickname")); - // TODO: user mode in parenthesis + str_append (&prompt, buffer->name); + if (buffer->type == BUFFER_CHANNEL) + str_append_printf (&prompt, "(%s)", buffer->mode); + str_append_c (&prompt, ' '); + + str_append (&prompt, ctx->irc_nickname); + str_append_printf (&prompt, "(%s)", ctx->irc_user_mode); + str_append_c (&prompt, ']'); } str_append (&prompt, " "); @@ -1303,7 +1320,19 @@ on_readline_goto_buffer (int count, int key) if (n < 0 || n > 9) return 0; - // TODO: switch to the n-th buffer + // There's no zero-th buffer + if (n == 0) + n = 10; + + // Activate the n-th buffer + int i = 0; + struct app_context *ctx = g_ctx; + LIST_FOR_EACH (struct buffer, iter, ctx->buffers) + if (++i == n) + { + buffer_activate (ctx, iter); + break; + } return 0; } @@ -1312,7 +1341,15 @@ on_readline_previous_buffer (int count, int key) { (void) key; - // TODO: switch "count" times to the previous buffer + struct app_context *ctx = g_ctx; + if (!ctx->current_buffer) + return 0; + + struct buffer *new_buffer = ctx->current_buffer; + while (count-- > 0) + if (!(new_buffer = new_buffer->prev)) + new_buffer = ctx->buffers_tail; + buffer_activate (ctx, new_buffer); return 0; } @@ -1321,7 +1358,15 @@ on_readline_next_buffer (int count, int key) { (void) key; - // TODO: switch "count" times to the next buffer + struct app_context *ctx = g_ctx; + if (!ctx->current_buffer) + return 0; + + struct buffer *new_buffer = ctx->current_buffer; + while (count-- > 0) + if (!(new_buffer = new_buffer->next)) + new_buffer = ctx->buffers; + buffer_activate (ctx, new_buffer); return 0; } -- cgit v1.2.3-70-g09d2