Skip to content

Commit

Permalink
Merge branch 'master' into sixel
Browse files Browse the repository at this point in the history
  • Loading branch information
topcat001 committed Oct 27, 2022
2 parents a82f14c + d001a94 commit 2a1e16a
Show file tree
Hide file tree
Showing 20 changed files with 216 additions and 82 deletions.
6 changes: 6 additions & 0 deletions client.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,12 @@ client_main(struct event_base *base, int argc, char **argv, uint64_t flags,
log_debug("flags are %#llx", (unsigned long long)client_flags);

/* Initialize the client socket and start the server. */
#ifdef HAVE_SYSTEMD
if (systemd_activated()) {
/* socket-based activation, do not even try to be a client. */
fd = server_start(client_proc, flags, base, 0, NULL);
} else
#endif
fd = client_connect(base, socket_path, client_flags);
if (fd == -1) {
if (errno == ECONNREFUSED) {
Expand Down
18 changes: 11 additions & 7 deletions cmd-capture-pane.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const struct cmd_entry cmd_capture_pane_entry = {
.alias = "capturep",

.args = { "ab:CeE:JNpPqS:t:", 0, 0, NULL },
.usage = "[-aCeJNpPq] " CMD_BUFFER_USAGE " [-E end-line] "
.usage = "[-aCeJNpPqT] " CMD_BUFFER_USAGE " [-E end-line] "
"[-S start-line] " CMD_TARGET_PANE_USAGE,

.target = { 't', CMD_FIND_PANE, 0 },
Expand Down Expand Up @@ -110,7 +110,7 @@ cmd_capture_pane_history(struct args *args, struct cmdq_item *item,
struct grid *gd;
const struct grid_line *gl;
struct grid_cell *gc = NULL;
int n, with_codes, escape_c0, join_lines, no_trim;
int n, join_lines, flags = 0;
u_int i, sx, top, bottom, tmp;
char *cause, *buf, *line;
const char *Sflag, *Eflag;
Expand Down Expand Up @@ -169,15 +169,19 @@ cmd_capture_pane_history(struct args *args, struct cmdq_item *item,
top = tmp;
}

with_codes = args_has(args, 'e');
escape_c0 = args_has(args, 'C');
join_lines = args_has(args, 'J');
no_trim = args_has(args, 'N');
if (args_has(args, 'e'))
flags |= GRID_STRING_WITH_SEQUENCES;
if (args_has(args, 'C'))
flags |= GRID_STRING_ESCAPE_SEQUENCES;
if (!join_lines && !args_has(args, 'T'))
flags |= GRID_STRING_EMPTY_CELLS;
if (!join_lines && !args_has(args, 'N'))
flags |= GRID_STRING_TRIM_SPACES;

buf = NULL;
for (i = top; i <= bottom; i++) {
line = grid_string_cells(gd, 0, i, sx, &gc, with_codes,
escape_c0, !join_lines && !no_trim, wp->screen);
line = grid_string_cells(gd, 0, i, sx, &gc, flags, wp->screen);
linelen = strlen(line);

buf = cmd_capture_pane_append(buf, len, line, linelen);
Expand Down
3 changes: 2 additions & 1 deletion cmd-parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,8 @@ cmd_parse_from_arguments(struct args_value *values, u_int count,
arg->type = CMD_PARSE_STRING;
arg->string = copy;
TAILQ_INSERT_TAIL(&cmd->arguments, arg, entry);
}
} else
free(copy);
} else if (values[i].type == ARGS_COMMANDS) {
arg = xcalloc(1, sizeof *arg);
arg->type = CMD_PARSE_PARSED_COMMANDS;
Expand Down
1 change: 1 addition & 0 deletions compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ void *recallocarray(void *, size_t, size_t, size_t);

#ifdef HAVE_SYSTEMD
/* systemd.c */
int systemd_activated(void);
int systemd_create_socket(int, char **);
#endif

Expand Down
10 changes: 9 additions & 1 deletion compat/systemd.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,23 @@

#include <systemd/sd-daemon.h>

#include <string.h>

#include "tmux.h"

int
systemd_activated(void)
{
return (sd_listen_fds(0) >= 1);
}

int
systemd_create_socket(int flags, char **cause)
{
int fds;
int fd;
struct sockaddr_un sa;
int addrlen = sizeof sa;
socklen_t addrlen = sizeof sa;

fds = sd_listen_fds(0);
if (fds > 1) { /* too many file descriptors */
Expand Down
2 changes: 1 addition & 1 deletion grid-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,5 +231,5 @@ grid_view_string_cells(struct grid *gd, u_int px, u_int py, u_int nx)
px = grid_view_x(gd, px);
py = grid_view_y(gd, py);

return (grid_string_cells(gd, px, py, nx, NULL, 0, 0, 0, NULL));
return (grid_string_cells(gd, px, py, nx, NULL, 0, NULL));
}
88 changes: 49 additions & 39 deletions grid.c
Original file line number Diff line number Diff line change
Expand Up @@ -861,40 +861,45 @@ grid_string_cells_us(const struct grid_cell *gc, int *values)
/* Add on SGR code. */
static void
grid_string_cells_add_code(char *buf, size_t len, u_int n, int *s, int *newc,
int *oldc, size_t nnewc, size_t noldc, int escape_c0)
int *oldc, size_t nnewc, size_t noldc, int flags)
{
u_int i;
char tmp[64];

if (nnewc != 0 &&
(nnewc != noldc ||
memcmp(newc, oldc, nnewc * sizeof newc[0]) != 0 ||
(n != 0 && s[0] == 0))) {
if (escape_c0)
strlcat(buf, "\\033[", len);
int reset = (n != 0 && s[0] == 0);

if (nnewc == 0)
return; /* no code to add */
if (!reset &&
nnewc == noldc &&
memcmp(newc, oldc, nnewc * sizeof newc[0]) == 0)
return; /* no reset and colour unchanged */
if (reset && (newc[0] == 49 || newc[0] == 39))
return; /* reset and colour default */

if (flags & GRID_STRING_ESCAPE_SEQUENCES)
strlcat(buf, "\\033[", len);
else
strlcat(buf, "\033[", len);
for (i = 0; i < nnewc; i++) {
if (i + 1 < nnewc)
xsnprintf(tmp, sizeof tmp, "%d;", newc[i]);
else
strlcat(buf, "\033[", len);
for (i = 0; i < nnewc; i++) {
if (i + 1 < nnewc)
xsnprintf(tmp, sizeof tmp, "%d;", newc[i]);
else
xsnprintf(tmp, sizeof tmp, "%d", newc[i]);
strlcat(buf, tmp, len);
}
strlcat(buf, "m", len);
xsnprintf(tmp, sizeof tmp, "%d", newc[i]);
strlcat(buf, tmp, len);
}
strlcat(buf, "m", len);
}

static int
grid_string_cells_add_hyperlink(char *buf, size_t len, const char *id,
const char *uri, int escape_c0)
const char *uri, int flags)
{
char *tmp;

if (strlen(uri) + strlen(id) + 17 >= len)
return (0);

if (escape_c0)
if (flags & GRID_STRING_ESCAPE_SEQUENCES)
strlcat(buf, "\\033]8;", len);
else
strlcat(buf, "\033]8;", len);
Expand All @@ -905,7 +910,7 @@ grid_string_cells_add_hyperlink(char *buf, size_t len, const char *id,
} else
strlcat(buf, ";", len);
strlcat(buf, uri, len);
if (escape_c0)
if (flags & GRID_STRING_ESCAPE_SEQUENCES)
strlcat(buf, "\\033\\\\", len);
else
strlcat(buf, "\033\\", len);
Expand All @@ -918,7 +923,7 @@ grid_string_cells_add_hyperlink(char *buf, size_t len, const char *id,
*/
static void
grid_string_cells_code(const struct grid_cell *lastgc,
const struct grid_cell *gc, char *buf, size_t len, int escape_c0,
const struct grid_cell *gc, char *buf, size_t len, int flags,
struct screen *sc, int *has_link)
{
int oldc[64], newc[64], s[128];
Expand All @@ -927,7 +932,7 @@ grid_string_cells_code(const struct grid_cell *lastgc,
char tmp[64];
const char *uri, *id;

struct {
static const struct {
u_int mask;
u_int code;
} attrs[] = {
Expand Down Expand Up @@ -966,7 +971,7 @@ grid_string_cells_code(const struct grid_cell *lastgc,
/* Write the attributes. */
*buf = '\0';
if (n > 0) {
if (escape_c0)
if (flags & GRID_STRING_ESCAPE_SEQUENCES)
strlcat(buf, "\\033[", len);
else
strlcat(buf, "\033[", len);
Expand All @@ -988,29 +993,29 @@ grid_string_cells_code(const struct grid_cell *lastgc,
nnewc = grid_string_cells_fg(gc, newc);
noldc = grid_string_cells_fg(lastgc, oldc);
grid_string_cells_add_code(buf, len, n, s, newc, oldc, nnewc, noldc,
escape_c0);
flags);

/* If the background colour changed, append its parameters. */
nnewc = grid_string_cells_bg(gc, newc);
noldc = grid_string_cells_bg(lastgc, oldc);
grid_string_cells_add_code(buf, len, n, s, newc, oldc, nnewc, noldc,
escape_c0);
flags);

/* If the underscore colour changed, append its parameters. */
nnewc = grid_string_cells_us(gc, newc);
noldc = grid_string_cells_us(lastgc, oldc);
grid_string_cells_add_code(buf, len, n, s, newc, oldc, nnewc, noldc,
escape_c0);
flags);

/* Append shift in/shift out if needed. */
if ((attr & GRID_ATTR_CHARSET) && !(lastattr & GRID_ATTR_CHARSET)) {
if (escape_c0)
if (flags & GRID_STRING_ESCAPE_SEQUENCES)
strlcat(buf, "\\016", len); /* SO */
else
strlcat(buf, "\016", len); /* SO */
}
if (!(attr & GRID_ATTR_CHARSET) && (lastattr & GRID_ATTR_CHARSET)) {
if (escape_c0)
if (flags & GRID_STRING_ESCAPE_SEQUENCES)
strlcat(buf, "\\017", len); /* SI */
else
strlcat(buf, "\017", len); /* SI */
Expand All @@ -1020,10 +1025,10 @@ grid_string_cells_code(const struct grid_cell *lastgc,
if (sc != NULL && sc->hyperlinks != NULL && lastgc->link != gc->link) {
if (hyperlinks_get(sc->hyperlinks, gc->link, &uri, &id, NULL)) {
*has_link = grid_string_cells_add_hyperlink(buf, len,
id, uri, escape_c0);
id, uri, flags);
} else if (*has_link) {
grid_string_cells_add_hyperlink(buf, len, "", "",
escape_c0);
flags);
*has_link = 0;
}
}
Expand All @@ -1032,15 +1037,14 @@ grid_string_cells_code(const struct grid_cell *lastgc,
/* Convert cells into a string. */
char *
grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx,
struct grid_cell **lastgc, int with_codes, int escape_c0, int trim,
struct screen *s)
struct grid_cell **lastgc, int flags, struct screen *s)
{
struct grid_cell gc;
static struct grid_cell lastgc1;
const char *data;
char *buf, code[8192];
size_t len, off, size, codelen;
u_int xx, has_link = 0;
u_int xx, has_link = 0, end;
const struct grid_line *gl;

if (lastgc != NULL && *lastgc == NULL) {
Expand All @@ -1053,24 +1057,30 @@ grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx,
off = 0;

gl = grid_peek_line(gd, py);
if (flags & GRID_STRING_EMPTY_CELLS)
end = gl->cellsize;
else
end = gl->cellused;
for (xx = px; xx < px + nx; xx++) {
if (gl == NULL || xx >= gl->cellused)
if (gl == NULL || xx >= end)
break;
grid_get_cell(gd, xx, py, &gc);
if (gc.flags & GRID_FLAG_PADDING)
continue;

if (with_codes) {
if (flags & GRID_STRING_WITH_SEQUENCES) {
grid_string_cells_code(*lastgc, &gc, code, sizeof code,
escape_c0, s, &has_link);
flags, s, &has_link);
codelen = strlen(code);
memcpy(*lastgc, &gc, sizeof **lastgc);
} else
codelen = 0;

data = gc.data.data;
size = gc.data.size;
if (escape_c0 && size == 1 && *data == '\\') {
if ((flags & GRID_STRING_ESCAPE_SEQUENCES) &&
size == 1 &&
*data == '\\') {
data = "\\\\";
size = 2;
}
Expand All @@ -1090,7 +1100,7 @@ grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx,

if (has_link) {
grid_string_cells_add_hyperlink(code, sizeof code, "", "",
escape_c0);
flags);
codelen = strlen(code);
while (len < off + size + codelen + 1) {
buf = xreallocarray(buf, 2, len);
Expand All @@ -1100,7 +1110,7 @@ grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx,
off += codelen;
}

if (trim) {
if (flags & GRID_STRING_TRIM_SPACES) {
while (off > 0 && buf[off - 1] == ' ')
off--;
}
Expand Down
6 changes: 3 additions & 3 deletions input.c
Original file line number Diff line number Diff line change
Expand Up @@ -1899,7 +1899,7 @@ input_csi_dispatch_winops(struct input_ctx *ictx)
}
break;
case 18:
input_reply(ictx, "\033[8;%u;%ut", x, y);
input_reply(ictx, "\033[8;%u;%ut", y, x);
break;
default:
log_debug("%s: unknown '%c'", __func__, ictx->ch);
Expand Down Expand Up @@ -2242,7 +2242,6 @@ static int
input_dcs_dispatch(struct input_ctx *ictx)
{
struct window_pane *wp = ictx->wp;
struct options *oo = wp->options;
struct screen_write_ctx *sctx = &ictx->ctx;
struct window *w = wp->window;
u_char *buf = ictx->input_buf;
Expand All @@ -2256,7 +2255,8 @@ input_dcs_dispatch(struct input_ctx *ictx)
return (0);
if (ictx->flags & INPUT_DISCARD)
return (0);
allow_passthrough = options_get_number(oo, "allow-passthrough");
allow_passthrough = options_get_number(wp->options,
"allow-passthrough");
if (!allow_passthrough)
return (0);
log_debug("%s: \"%s\"", __func__, buf);
Expand Down
13 changes: 12 additions & 1 deletion options-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ static const char *options_table_clock_mode_style_list[] = {
static const char *options_table_status_list[] = {
"off", "on", "2", "3", "4", "5", NULL
};
static const char *options_table_message_line_list[] = {
"0", "1", "2", "3", "4", NULL
};
static const char *options_table_status_keys_list[] = {
"emacs", "vi", NULL
};
Expand Down Expand Up @@ -541,13 +544,21 @@ const struct options_table_entry options_table[] = {
"'mode-keys' is set to 'vi'."
},

{ .name = "message-line",
.type = OPTIONS_TABLE_CHOICE,
.scope = OPTIONS_TABLE_SESSION,
.choices = options_table_message_line_list,
.default_num = 0,
.text = "Position (line) of messages and the command prompt."
},

{ .name = "message-style",
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_SESSION,
.default_str = "bg=yellow,fg=black",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ",",
.text = "Style of the command prompt."
.text = "Style of messages and the command prompt."
},

{ .name = "mouse",
Expand Down
2 changes: 1 addition & 1 deletion regress/conf/2eae5d47049c1f6d0bef3db4e171aed7.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ set-window-option -g pane-base-index 1
unbind ^B
bind ^B select-pane -t :.+

# Reload config wtih a key
# Reload config with a key
bind-key r source-file ~/.tmux.conf \; display "Config reloaded!"

# Mouse works as expected
Expand Down
Loading

0 comments on commit 2a1e16a

Please sign in to comment.