mirror of
https://github.com/tmate-io/tmate.git
synced 2024-11-23 16:43:11 +01:00
Sync OpenBSD patchset 269:
Pass show-buffer output through vis(3) as well, and wrap it to the edge of the terminal when used from the command line.
This commit is contained in:
parent
9386f640a5
commit
3756fce553
@ -1,4 +1,4 @@
|
|||||||
/* $Id: cmd-show-buffer.c,v 1.6 2009-07-28 22:12:16 tcunha Exp $ */
|
/* $Id: cmd-show-buffer.c,v 1.7 2009-08-20 11:30:24 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -18,7 +18,8 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <string.h>
|
||||||
|
#include <vis.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
@ -45,9 +46,9 @@ cmd_show_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
struct cmd_buffer_data *data = self->data;
|
struct cmd_buffer_data *data = self->data;
|
||||||
struct session *s;
|
struct session *s;
|
||||||
struct paste_buffer *pb;
|
struct paste_buffer *pb;
|
||||||
u_int size;
|
char *in, *buf, *ptr;
|
||||||
char *buf, *ptr;
|
size_t size, len;
|
||||||
size_t len;
|
u_int width;
|
||||||
|
|
||||||
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
if ((s = cmd_find_session(ctx, data->target)) == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
@ -61,27 +62,43 @@ cmd_show_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
ctx->error(ctx, "no buffer %d", data->buffer);
|
ctx->error(ctx, "no buffer %d", data->buffer);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
if (pb == NULL)
|
||||||
|
return (0);
|
||||||
|
|
||||||
if (pb != NULL) {
|
size = strlen(pb->data);
|
||||||
size = s->sx;
|
if (size > SIZE_MAX / 4 - 1)
|
||||||
|
size = SIZE_MAX / 4 - 1;
|
||||||
|
in = xmalloc(size * 4 + 1);
|
||||||
|
strvisx(in, pb->data, size, VIS_OCTAL|VIS_TAB);
|
||||||
|
|
||||||
buf = xmalloc(size + 1);
|
width = s->sx;
|
||||||
|
if (ctx->cmdclient != NULL)
|
||||||
|
width = ctx->cmdclient->tty.sx;
|
||||||
|
|
||||||
|
buf = xmalloc(width + 1);
|
||||||
len = 0;
|
len = 0;
|
||||||
|
|
||||||
ptr = pb->data;
|
ptr = in;
|
||||||
do {
|
do {
|
||||||
buf[len++] = *ptr++;
|
buf[len++] = *ptr++;
|
||||||
|
|
||||||
if (len == size) {
|
if (len == width || buf[len - 1] == '\n') {
|
||||||
|
if (buf[len - 1] == '\n')
|
||||||
|
len--;
|
||||||
buf[len] = '\0';
|
buf[len] = '\0';
|
||||||
ctx->print(ctx, buf);
|
|
||||||
|
|
||||||
|
ctx->print(ctx, "%s", buf);
|
||||||
len = 0;
|
len = 0;
|
||||||
}
|
}
|
||||||
} while (*ptr != '\0');
|
} while (*ptr != '\0');
|
||||||
|
|
||||||
|
if (len != 0) {
|
||||||
buf[len] = '\0';
|
buf[len] = '\0';
|
||||||
ctx->print(ctx, buf);
|
ctx->print(ctx, buf);
|
||||||
}
|
}
|
||||||
|
xfree(buf);
|
||||||
|
|
||||||
|
xfree(in);
|
||||||
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user