summaryrefslogtreecommitdiff
path: root/degesch.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-06-21 19:23:52 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-06-21 19:35:35 +0200
commitb56245cf5b52cecb922761cd1dc46489883b5d82 (patch)
treec2c97507a85736c631d3ba4ac95dd91691c0e56e /degesch.c
parentb3a80630aa87ed6463288a1ae80f3d7b53b97c0a (diff)
downloadxK-b56245cf5b52cecb922761cd1dc46489883b5d82.tar.gz
xK-b56245cf5b52cecb922761cd1dc46489883b5d82.tar.xz
xK-b56245cf5b52cecb922761cd1dc46489883b5d82.zip
degesch: implement /buffer move
Diffstat (limited to 'degesch.c')
-rw-r--r--degesch.c38
1 files changed, 33 insertions, 5 deletions
diff --git a/degesch.c b/degesch.c
index 7e8b8b4..b103d6b 100644
--- a/degesch.c
+++ b/degesch.c
@@ -5937,6 +5937,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)
{
char *action = cut_word (&a->arguments);
@@ -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[] =
"[<message>]",
handle_command_quit, 0 },
{ "buffer", "Manage buffers",
- "list | clear | move | { close [<number> | <name>] } | <number>",
+ "<N> | list | clear | move <N> | close [<N> | <name>]",
handle_command_buffer, 0 },
{ "set", "Manage configuration",
"[<option>]",