degesch: implement /buffer move

This commit is contained in:
Přemysl Eric Janouch 2015-06-21 19:23:52 +02:00
parent b3a80630aa
commit b56245cf5b
2 changed files with 42 additions and 5 deletions

View File

@ -49,6 +49,15 @@
// --- To be moved to liberty -------------------------------------------------- // --- To be moved to liberty --------------------------------------------------
#define LIST_INSERT_WITH_TAIL(head, tail, link, following) \
BLOCK_START \
if (following) \
LIST_APPEND_WITH_TAIL ((head), (following)->prev, (link)); \
else \
LIST_APPEND_WITH_TAIL ((head), (tail), (link)); \
(link)->next = (following); \
BLOCK_END
static void static void
split_str (const char *s, char delimiter, struct str_vector *out) split_str (const char *s, char delimiter, struct str_vector *out)
{ {

View File

@ -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 static bool
handle_command_buffer (struct app_context *ctx, struct handler_args *a) 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); buffer_print_backlog (ctx, a->buffer);
} }
else if (!strcasecmp_ascii (action, "move")) else if (!strcasecmp_ascii (action, "move"))
{ handle_buffer_move (ctx, a);
// TODO: unlink the buffer and link it back at index;
// we will probably need to extend liberty for this
}
else if (!strcasecmp_ascii (action, "close")) else if (!strcasecmp_ascii (action, "close"))
handle_buffer_close (ctx, a); handle_buffer_close (ctx, a);
else else
@ -6724,7 +6752,7 @@ g_command_handlers[] =
"[<message>]", "[<message>]",
handle_command_quit, 0 }, handle_command_quit, 0 },
{ "buffer", "Manage buffers", { "buffer", "Manage buffers",
"list | clear | move | { close [<number> | <name>] } | <number>", "<N> | list | clear | move <N> | close [<N> | <name>]",
handle_command_buffer, 0 }, handle_command_buffer, 0 },
{ "set", "Manage configuration", { "set", "Manage configuration",
"[<option>]", "[<option>]",