diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2015-04-17 21:40:08 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2015-04-17 21:40:08 +0200 |
commit | 61ebbe245b29fc20b163d80072c1b6f0b5be0d84 (patch) | |
tree | c7fb3c46c2d184eab263e0300c0c57806dd6d72f | |
parent | 8cb55e81b3e281cdf55f16da4209ec357c774bda (diff) | |
download | xK-61ebbe245b29fc20b163d80072c1b6f0b5be0d84.tar.gz xK-61ebbe245b29fc20b163d80072c1b6f0b5be0d84.tar.xz xK-61ebbe245b29fc20b163d80072c1b6f0b5be0d84.zip |
degesch: factor out make_prompt()
-rw-r--r-- | degesch.c | 64 |
1 files changed, 37 insertions, 27 deletions
@@ -1315,41 +1315,51 @@ get_unseen_prefix (struct app_context *ctx) } static void -refresh_prompt (struct app_context *ctx) +make_prompt (struct app_context *ctx, struct str *output) { - bool have_attributes = !!get_attribute_printer (stdout); - - struct str prompt; - str_init (&prompt); - if (!ctx->irc_ready) - str_append (&prompt, "(disconnected)"); - else if (soft_assert (ctx->current_buffer)) { - struct buffer *buffer = ctx->current_buffer; - str_append_c (&prompt, '['); + // XXX: does this make any sense? + str_append (output, "(disconnected)"); + return; + } - char *unseen_prefix = get_unseen_prefix (ctx); - if (unseen_prefix) - str_append_printf (&prompt, "(%s) ", unseen_prefix); - free (unseen_prefix); + struct buffer *buffer = ctx->current_buffer; + if (!soft_assert (buffer)) + return; - str_append_printf (&prompt, "%d:%s", - buffer_get_index (ctx, buffer), buffer->name); - if (buffer->type == BUFFER_CHANNEL && *buffer->mode) - str_append_printf (&prompt, "(%s)", buffer->mode); + str_append_c (output, '['); - if (buffer != ctx->global_buffer) - { - str_append_c (&prompt, ' '); - str_append (&prompt, ctx->irc_nickname); - if (*ctx->irc_user_mode) - str_append_printf (&prompt, "(%s)", ctx->irc_user_mode); - } + char *unseen_prefix = get_unseen_prefix (ctx); + if (unseen_prefix) + str_append_printf (output, "(%s) ", unseen_prefix); + free (unseen_prefix); - str_append_c (&prompt, ']'); + str_append_printf (output, "%d:%s", + buffer_get_index (ctx, buffer), buffer->name); + if (buffer->type == BUFFER_CHANNEL && *buffer->mode) + str_append_printf (output, "(%s)", buffer->mode); + + if (buffer != ctx->global_buffer) + { + str_append_c (output, ' '); + str_append (output, ctx->irc_nickname); + if (*ctx->irc_user_mode) + str_append_printf (output, "(%s)", ctx->irc_user_mode); } - str_append (&prompt, " "); + + str_append_c (output, ']'); +} + +static void +refresh_prompt (struct app_context *ctx) +{ + bool have_attributes = !!get_attribute_printer (stdout); + + struct str prompt; + str_init (&prompt); + make_prompt (ctx, &prompt); + str_append_c (&prompt, ' '); // After building the new prompt, replace the old one free (ctx->readline_prompt); |