From b56245cf5b52cecb922761cd1dc46489883b5d82 Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Sun, 21 Jun 2015 19:23:52 +0200
Subject: degesch: implement /buffer move
---
degesch.c | 38 +++++++++++++++++++++++++++++++++-----
1 file changed, 33 insertions(+), 5 deletions(-)
(limited to 'degesch.c')
diff --git a/degesch.c b/degesch.c
index 7e8b8b4..b103d6b 100644
--- a/degesch.c
+++ b/degesch.c
@@ -5936,6 +5936,37 @@ handle_buffer_close (struct app_context *ctx, struct handler_args *a)
}
}
+static bool
+handle_buffer_move (struct app_context *ctx, struct handler_args *a)
+{
+ unsigned long request;
+ if (!xstrtoul (&request, a->arguments, 10))
+ return false;
+
+ unsigned long total = 0;
+ LIST_FOR_EACH (struct buffer, iter, ctx->buffers)
+ total++;
+
+ if (request == 0 || request > total)
+ {
+ buffer_send_error (ctx, NULL, "%s: %s",
+ "Can't move buffer", "requested position is out of range");
+ return true;
+ }
+
+ struct buffer *buffer = a->buffer;
+ LIST_UNLINK_WITH_TAIL (ctx->buffers, ctx->buffers_tail, buffer);
+
+ struct buffer *following = ctx->buffers;
+ while (--request && following)
+ following = following->next;
+
+ LIST_INSERT_WITH_TAIL (ctx->buffers, ctx->buffers_tail, buffer, following);
+
+ refresh_prompt (ctx);
+ return true;
+}
+
static bool
handle_command_buffer (struct app_context *ctx, struct handler_args *a)
{
@@ -5954,10 +5985,7 @@ handle_command_buffer (struct app_context *ctx, struct handler_args *a)
buffer_print_backlog (ctx, a->buffer);
}
else if (!strcasecmp_ascii (action, "move"))
- {
- // TODO: unlink the buffer and link it back at index;
- // we will probably need to extend liberty for this
- }
+ handle_buffer_move (ctx, a);
else if (!strcasecmp_ascii (action, "close"))
handle_buffer_close (ctx, a);
else
@@ -6724,7 +6752,7 @@ g_command_handlers[] =
"[]",
handle_command_quit, 0 },
{ "buffer", "Manage buffers",
- "list | clear | move | { close [ | ] } | ",
+ " | list | clear | move | close [ | ]",
handle_command_buffer, 0 },
{ "set", "Manage configuration",
"[