degesch: factor out make_prompt()
This commit is contained in:
parent
8cb55e81b3
commit
61ebbe245b
68
degesch.c
68
degesch.c
@ -1314,6 +1314,43 @@ get_unseen_prefix (struct app_context *ctx)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
make_prompt (struct app_context *ctx, struct str *output)
|
||||
{
|
||||
if (!ctx->irc_ready)
|
||||
{
|
||||
// XXX: does this make any sense?
|
||||
str_append (output, "(disconnected)");
|
||||
return;
|
||||
}
|
||||
|
||||
struct buffer *buffer = ctx->current_buffer;
|
||||
if (!soft_assert (buffer))
|
||||
return;
|
||||
|
||||
str_append_c (output, '[');
|
||||
|
||||
char *unseen_prefix = get_unseen_prefix (ctx);
|
||||
if (unseen_prefix)
|
||||
str_append_printf (output, "(%s) ", unseen_prefix);
|
||||
free (unseen_prefix);
|
||||
|
||||
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_c (output, ']');
|
||||
}
|
||||
|
||||
static void
|
||||
refresh_prompt (struct app_context *ctx)
|
||||
{
|
||||
@ -1321,35 +1358,8 @@ refresh_prompt (struct app_context *ctx)
|
||||
|
||||
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, '[');
|
||||
|
||||
char *unseen_prefix = get_unseen_prefix (ctx);
|
||||
if (unseen_prefix)
|
||||
str_append_printf (&prompt, "(%s) ", unseen_prefix);
|
||||
free (unseen_prefix);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
str_append_c (&prompt, ']');
|
||||
}
|
||||
str_append (&prompt, " ");
|
||||
make_prompt (ctx, &prompt);
|
||||
str_append_c (&prompt, ' ');
|
||||
|
||||
// After building the new prompt, replace the old one
|
||||
free (ctx->readline_prompt);
|
||||
|
Loading…
Reference in New Issue
Block a user