diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2015-04-17 20:45:54 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2015-04-17 21:19:51 +0200 |
commit | e5b52fcd76c94f6349cddb0e1872ff8b2109acea (patch) | |
tree | a52ecff2362f13f8f7b503c248ff5a6066aab5cd | |
parent | 2d4adaefbf8682d0aac7d0328d7342d8f6ea2fdc (diff) | |
download | xK-e5b52fcd76c94f6349cddb0e1872ff8b2109acea.tar.gz xK-e5b52fcd76c94f6349cddb0e1872ff8b2109acea.tar.xz xK-e5b52fcd76c94f6349cddb0e1872ff8b2109acea.zip |
degesch: factor out buffer_get_index()
-rw-r--r-- | degesch.c | 21 |
1 files changed, 15 insertions, 6 deletions
@@ -952,6 +952,19 @@ buffer_goto (struct app_context *ctx, int n) 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 init_buffers (struct app_context *ctx) { @@ -1291,12 +1304,8 @@ refresh_prompt (struct app_context *ctx) str_append_printf (&prompt, "(%s) ", unseen_prefix); free (unseen_prefix); - int buffer_index = 1; - for (struct buffer *iter = ctx->buffers; - iter && iter != buffer; iter = iter->next) - buffer_index++; - - str_append_printf (&prompt, "%d:%s", buffer_index, buffer->name); + 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); |