degesch: factor out buffer_get_index()

This commit is contained in:
Přemysl Eric Janouch 2015-04-17 20:45:54 +02:00
parent 2d4adaefbf
commit e5b52fcd76
1 changed files with 15 additions and 6 deletions

View File

@ -952,6 +952,19 @@ buffer_goto (struct app_context *ctx, int n)
return false; return false;
} }
static int
buffer_get_index (struct app_context *ctx, struct buffer *buffer)
{
int index = 1;
LIST_FOR_EACH (struct buffer, iter, ctx->buffers)
{
if (iter == buffer)
return index;
index++;
}
return -1;
}
static void static void
init_buffers (struct app_context *ctx) init_buffers (struct app_context *ctx)
{ {
@ -1291,12 +1304,8 @@ refresh_prompt (struct app_context *ctx)
str_append_printf (&prompt, "(%s) ", unseen_prefix); str_append_printf (&prompt, "(%s) ", unseen_prefix);
free (unseen_prefix); free (unseen_prefix);
int buffer_index = 1; str_append_printf (&prompt, "%d:%s",
for (struct buffer *iter = ctx->buffers; buffer_get_index (ctx, buffer), buffer->name);
iter && iter != buffer; iter = iter->next)
buffer_index++;
str_append_printf (&prompt, "%d:%s", buffer_index, buffer->name);
if (buffer->type == BUFFER_CHANNEL && *buffer->mode) if (buffer->type == BUFFER_CHANNEL && *buffer->mode)
str_append_printf (&prompt, "(%s)", buffer->mode); str_append_printf (&prompt, "(%s)", buffer->mode);