mirror of
https://github.com/tmux/tmux.git
synced 2024-10-31 14:48:56 +00:00
Merge branch 'obsd-master'
This commit is contained in:
commit
6249a4b866
86
cmd-queue.c
86
cmd-queue.c
@ -24,6 +24,7 @@
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <vis.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
@ -823,43 +824,88 @@ cmdq_guard(struct cmdq_item *item, const char *guard, int flags)
|
||||
|
||||
/* Show message from command. */
|
||||
void
|
||||
cmdq_print(struct cmdq_item *item, const char *fmt, ...)
|
||||
cmdq_print_data(struct cmdq_item *item, int parse, struct evbuffer *evb)
|
||||
{
|
||||
struct client *c = item->client;
|
||||
void *data = EVBUFFER_DATA(evb);
|
||||
size_t size = EVBUFFER_LENGTH(evb);
|
||||
struct window_pane *wp;
|
||||
struct window_mode_entry *wme;
|
||||
va_list ap;
|
||||
char *tmp, *msg;
|
||||
|
||||
va_start(ap, fmt);
|
||||
xvasprintf(&msg, fmt, ap);
|
||||
va_end(ap);
|
||||
char *sanitized, *msg, *line;
|
||||
|
||||
if (!parse) {
|
||||
utf8_stravisx(&msg, data, size, VIS_OCTAL|VIS_CSTYLE|VIS_TAB);
|
||||
log_debug("%s: %s", __func__, msg);
|
||||
} else {
|
||||
msg = EVBUFFER_DATA(evb);
|
||||
if (msg[size - 1] != '\0')
|
||||
evbuffer_add(evb, "", 1);
|
||||
}
|
||||
|
||||
if (c == NULL)
|
||||
/* nothing */;
|
||||
else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
|
||||
goto out;
|
||||
|
||||
if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
|
||||
if (~c->flags & CLIENT_UTF8) {
|
||||
tmp = msg;
|
||||
msg = utf8_sanitize(tmp);
|
||||
free(tmp);
|
||||
}
|
||||
sanitized = utf8_sanitize(msg);
|
||||
if (c->flags & CLIENT_CONTROL)
|
||||
control_write(c, "%s", sanitized);
|
||||
else
|
||||
file_print(c, "%s\n", sanitized);
|
||||
free(sanitized);
|
||||
} else {
|
||||
if (c->flags & CLIENT_CONTROL)
|
||||
control_write(c, "%s", msg);
|
||||
else
|
||||
file_print(c, "%s\n", msg);
|
||||
} else {
|
||||
wp = server_client_get_pane(c);
|
||||
wme = TAILQ_FIRST(&wp->modes);
|
||||
if (wme == NULL || wme->mode != &window_view_mode) {
|
||||
window_pane_set_mode(wp, NULL, &window_view_mode, NULL,
|
||||
NULL);
|
||||
}
|
||||
window_copy_add(wp, 0, "%s", msg);
|
||||
goto out;
|
||||
}
|
||||
|
||||
wp = server_client_get_pane(c);
|
||||
wme = TAILQ_FIRST(&wp->modes);
|
||||
if (wme == NULL || wme->mode != &window_view_mode)
|
||||
window_pane_set_mode(wp, NULL, &window_view_mode, NULL, NULL);
|
||||
if (parse) {
|
||||
do {
|
||||
line = evbuffer_readln(evb, NULL, EVBUFFER_EOL_LF);
|
||||
if (line != NULL) {
|
||||
window_copy_add(wp, 1, "%s", line);
|
||||
free(line);
|
||||
}
|
||||
} while (line != NULL);
|
||||
|
||||
size = EVBUFFER_LENGTH(evb);
|
||||
if (size != 0) {
|
||||
line = EVBUFFER_DATA(evb);
|
||||
window_copy_add(wp, 1, "%.*s", (int)size, line);
|
||||
}
|
||||
} else
|
||||
window_copy_add(wp, 0, "%s", msg);
|
||||
|
||||
out:
|
||||
if (!parse)
|
||||
free(msg);
|
||||
|
||||
}
|
||||
|
||||
/* Show message from command. */
|
||||
void
|
||||
cmdq_print(struct cmdq_item *item, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
struct evbuffer *evb;
|
||||
|
||||
evb = evbuffer_new();
|
||||
if (evb == NULL)
|
||||
fatalx("out of memory");
|
||||
|
||||
va_start(ap, fmt);
|
||||
evbuffer_add_vprintf(evb, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
cmdq_print_data(item, 0, evb);
|
||||
evbuffer_free(evb);
|
||||
}
|
||||
|
||||
/* Show error from command. */
|
||||
|
@ -78,7 +78,8 @@ cmd_save_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
int flags;
|
||||
const char *bufname = args_get(args, 'b'), *bufdata;
|
||||
size_t bufsize;
|
||||
char *path, *tmp;
|
||||
char *path;
|
||||
struct evbuffer *evb;
|
||||
|
||||
if (bufname == NULL) {
|
||||
if ((pb = paste_get_top(NULL)) == NULL) {
|
||||
@ -96,10 +97,12 @@ cmd_save_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
if (cmd_get_entry(self) == &cmd_show_buffer_entry) {
|
||||
if (c->session != NULL || (c->flags & CLIENT_CONTROL)) {
|
||||
utf8_stravisx(&tmp, bufdata, bufsize,
|
||||
VIS_OCTAL|VIS_CSTYLE|VIS_TAB);
|
||||
cmdq_print(item, "%s", tmp);
|
||||
free(tmp);
|
||||
evb = evbuffer_new();
|
||||
if (evb == NULL)
|
||||
fatalx("out of memory");
|
||||
evbuffer_add(evb, bufdata, bufsize);
|
||||
cmdq_print_data(item, 1, evb);
|
||||
evbuffer_free(evb);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
path = xstrdup("-");
|
||||
|
1
tmux.h
1
tmux.h
@ -2551,6 +2551,7 @@ u_int cmdq_next(struct client *);
|
||||
struct cmdq_item *cmdq_running(struct client *);
|
||||
void cmdq_guard(struct cmdq_item *, const char *, int);
|
||||
void printflike(2, 3) cmdq_print(struct cmdq_item *, const char *, ...);
|
||||
void cmdq_print_data(struct cmdq_item *, int, struct evbuffer *);
|
||||
void printflike(2, 3) cmdq_error(struct cmdq_item *, const char *, ...);
|
||||
|
||||
/* cmd-wait-for.c */
|
||||
|
Loading…
Reference in New Issue
Block a user