degesch: refactor handle_command_buffer() a bit
This commit is contained in:
parent
0141bef3cd
commit
a75fc35295
83
degesch.c
83
degesch.c
|
@ -2642,6 +2642,45 @@ server_command_check (struct app_context *ctx, const char *action)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
show_buffers_list (struct app_context *ctx)
|
||||||
|
{
|
||||||
|
buffer_send_status (ctx, ctx->global_buffer, "%s", "");
|
||||||
|
buffer_send_status (ctx, ctx->global_buffer, "Buffers list:");
|
||||||
|
|
||||||
|
int i = 1;
|
||||||
|
LIST_FOR_EACH (struct buffer, iter, ctx->buffers)
|
||||||
|
buffer_send_status (ctx, ctx->global_buffer,
|
||||||
|
" [%d] %s", i++, iter->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
handle_buffer_close (struct app_context *ctx, char *arguments)
|
||||||
|
{
|
||||||
|
struct buffer *buffer = NULL;
|
||||||
|
const char *which = NULL;
|
||||||
|
if (!*arguments)
|
||||||
|
buffer = ctx->current_buffer;
|
||||||
|
else
|
||||||
|
buffer = try_decode_buffer (ctx, (which = cut_word (&arguments)));
|
||||||
|
|
||||||
|
if (!buffer)
|
||||||
|
buffer_send_error (ctx, ctx->global_buffer,
|
||||||
|
"%s: %s", "No such buffer", which);
|
||||||
|
else if (buffer == ctx->global_buffer)
|
||||||
|
buffer_send_error (ctx, ctx->global_buffer,
|
||||||
|
"Can't close the global buffer");
|
||||||
|
else if (buffer == ctx->server_buffer)
|
||||||
|
buffer_send_error (ctx, ctx->global_buffer,
|
||||||
|
"Can't close the server buffer");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (buffer == ctx->current_buffer)
|
||||||
|
buffer_activate (ctx, buffer_next (ctx, 1));
|
||||||
|
buffer_remove (ctx, buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
handle_command_buffer (struct app_context *ctx, char *arguments)
|
handle_command_buffer (struct app_context *ctx, char *arguments)
|
||||||
{
|
{
|
||||||
|
@ -2649,21 +2688,10 @@ handle_command_buffer (struct app_context *ctx, char *arguments)
|
||||||
if (try_handle_buffer_goto (ctx, action))
|
if (try_handle_buffer_goto (ctx, action))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
struct buffer *buffer = NULL;
|
|
||||||
|
|
||||||
// XXX: also build a prefix map?
|
// XXX: also build a prefix map?
|
||||||
// It looks like we'll want to split this into functions anyway.
|
|
||||||
// TODO: some subcommand to print N last lines from the buffer
|
// TODO: some subcommand to print N last lines from the buffer
|
||||||
if (!strcasecmp_ascii (action, "list"))
|
if (!strcasecmp_ascii (action, "list"))
|
||||||
{
|
show_buffers_list (ctx);
|
||||||
buffer_send_status (ctx, ctx->global_buffer, "%s", "");
|
|
||||||
buffer_send_status (ctx, ctx->global_buffer, "Buffers list:");
|
|
||||||
|
|
||||||
int i = 1;
|
|
||||||
LIST_FOR_EACH (struct buffer, iter, ctx->buffers)
|
|
||||||
buffer_send_status (ctx, ctx->global_buffer,
|
|
||||||
" [%d] %s", i++, iter->name);
|
|
||||||
}
|
|
||||||
else if (!strcasecmp_ascii (action, "clear"))
|
else if (!strcasecmp_ascii (action, "clear"))
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
|
@ -2674,36 +2702,7 @@ handle_command_buffer (struct app_context *ctx, char *arguments)
|
||||||
// we will probably need to extend liberty for this
|
// 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, arguments);
|
||||||
const char *which = NULL;
|
|
||||||
if (!*arguments)
|
|
||||||
buffer = ctx->current_buffer;
|
|
||||||
else
|
|
||||||
buffer = try_decode_buffer (ctx, (which = cut_word (&arguments)));
|
|
||||||
|
|
||||||
if (!buffer)
|
|
||||||
{
|
|
||||||
buffer_send_error (ctx, ctx->global_buffer,
|
|
||||||
"%s: %s", "No such buffer", which);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (buffer == ctx->global_buffer)
|
|
||||||
{
|
|
||||||
buffer_send_error (ctx, ctx->global_buffer,
|
|
||||||
"Can't close the global buffer");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (buffer == ctx->server_buffer)
|
|
||||||
{
|
|
||||||
buffer_send_error (ctx, ctx->global_buffer,
|
|
||||||
"Can't close the server buffer");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (buffer == ctx->current_buffer)
|
|
||||||
buffer_activate (ctx, buffer_next (ctx, 1));
|
|
||||||
buffer_remove (ctx, buffer);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue