mirror of
https://github.com/tmate-io/tmate.git
synced 2025-08-16 16:41:35 +02:00
Add a choose-buffer command for easier use of the paste buffer stack.
This commit is contained in:
@ -19,7 +19,6 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <vis.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
@ -47,32 +46,17 @@ cmd_list_buffers_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
struct session *s;
|
||||
struct paste_buffer *pb;
|
||||
u_int idx;
|
||||
char tmp[51 * 4 + 1];
|
||||
size_t size, len;
|
||||
char *tmp;
|
||||
|
||||
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||
return (-1);
|
||||
|
||||
idx = 0;
|
||||
while ((pb = paste_walk_stack(&s->buffers, &idx)) != NULL) {
|
||||
size = pb->size;
|
||||
|
||||
/* Translate the first 50 characters. */
|
||||
len = size;
|
||||
if (len > 50)
|
||||
len = 50;
|
||||
strvisx(tmp, pb->data, len, VIS_OCTAL|VIS_TAB|VIS_NL);
|
||||
|
||||
/*
|
||||
* If the first 50 characters were encoded as a longer string,
|
||||
* or there is definitely more data, add "...".
|
||||
*/
|
||||
if (size > 50 || strlen(tmp) > 50) {
|
||||
tmp[50 - 3] = '\0';
|
||||
strlcat(tmp, "...", sizeof tmp);
|
||||
}
|
||||
|
||||
ctx->print(ctx, "%u: %zu bytes: \"%s\"", idx - 1, size, tmp);
|
||||
tmp = paste_print(pb, 50);
|
||||
ctx->print(ctx,
|
||||
"%u: %zu bytes: \"%s\"", idx - 1, pb->size, tmp);
|
||||
xfree(tmp);
|
||||
}
|
||||
|
||||
return (0);
|
||||
|
Reference in New Issue
Block a user