diff options
Diffstat (limited to 'degesch.c')
| -rw-r--r-- | degesch.c | 38 | 
1 files changed, 33 insertions, 5 deletions
| @@ -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>]", | 
