mirror of
https://github.com/tmate-io/tmate.git
synced 2024-11-23 16:43:11 +01:00
Sync OpenBSD patchset 268:
Change list-buffers to run the preview of the buffer through vis(1).
This commit is contained in:
parent
bcfb4f2a07
commit
9386f640a5
@ -1,4 +1,4 @@
|
|||||||
/* $Id: cmd-list-buffers.c,v 1.9 2009-07-28 22:12:16 tcunha Exp $ */
|
/* $Id: cmd-list-buffers.c,v 1.10 2009-08-20 11:28:05 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -19,6 +19,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <vis.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
@ -46,44 +47,33 @@ cmd_list_buffers_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
struct session *s;
|
struct session *s;
|
||||||
struct paste_buffer *pb;
|
struct paste_buffer *pb;
|
||||||
u_int idx;
|
u_int idx;
|
||||||
char *tmp;
|
char tmp[51 * 4 + 1];
|
||||||
size_t size, in, out;
|
size_t size, len;
|
||||||
|
|
||||||
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
if (s->sx > 35) { /* leave three for ... */
|
|
||||||
size = s->sx - 32;
|
|
||||||
tmp = xmalloc(size + 1);
|
|
||||||
} else {
|
|
||||||
size = 0;
|
|
||||||
tmp = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
idx = 0;
|
idx = 0;
|
||||||
while ((pb = paste_walk_stack(&s->buffers, &idx)) != NULL) {
|
while ((pb = paste_walk_stack(&s->buffers, &idx)) != NULL) {
|
||||||
if (tmp != NULL) {
|
size = strlen(pb->data);
|
||||||
in = out = 0;
|
|
||||||
while (out < size && pb->data[in] != '\0') {
|
|
||||||
if (pb->data[in] > 31 && pb->data[in] != 127)
|
|
||||||
tmp[out++] = pb->data[in];
|
|
||||||
in++;
|
|
||||||
}
|
|
||||||
tmp[out] = '\0';
|
|
||||||
if (out == size) {
|
|
||||||
tmp[out - 1] = '.';
|
|
||||||
tmp[out - 2] = '.';
|
|
||||||
tmp[out - 3] = '.';
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx->print(ctx, "%d: %zu bytes: \"%s\"",
|
/* Translate the first 50 characters. */
|
||||||
idx - 1, strlen(pb->data), tmp);
|
len = size;
|
||||||
} else
|
if (len > 50)
|
||||||
ctx->print(ctx, "%d: %zu bytes", idx, strlen(pb->data));
|
len = 50;
|
||||||
|
strvisx(tmp, pb->data, len, VIS_OCTAL|VIS_TAB|VIS_NL);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If the first 50 characterswere 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tmp != NULL)
|
|
||||||
xfree(tmp);
|
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user