diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2024-10-25 15:00:19 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2024-10-25 15:00:19 +0000 |
commit | bf92eb7a7424d3103c01f5b5be7d189d6e168b9c (patch) | |
tree | 4b0096ce4fab13502cb5ccad31a6ffd268c9cf53 /usr.bin/tmux/window-copy.c | |
parent | ae9550c1949a1940717431c3ae7e11317814f4e7 (diff) |
Flag tabs if possible in the grid cell so they can be preserved on
copying and capture-pane. From Alexander Arch in GitHub issue 4201.
Diffstat (limited to 'usr.bin/tmux/window-copy.c')
-rw-r--r-- | usr.bin/tmux/window-copy.c | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/usr.bin/tmux/window-copy.c b/usr.bin/tmux/window-copy.c index 3129bf146ee..e9578ea754f 100644 --- a/usr.bin/tmux/window-copy.c +++ b/usr.bin/tmux/window-copy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window-copy.c,v 1.358 2024/10/21 12:39:49 nicm Exp $ */ +/* $OpenBSD: window-copy.c,v 1.359 2024/10/25 15:00:18 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -3301,6 +3301,11 @@ window_copy_cellstring(const struct grid_line *gl, u_int px, size_t *size, *allocated = 0; return (&gce->data.data); } + if (gce->flags & GRID_FLAG_TAB) { + *size = 1; + *allocated = 0; + return ("\t"); + } utf8_to_data(gl->extddata[gce->offset].data, &ud); if (ud.size == 0) { @@ -4083,9 +4088,15 @@ window_copy_match_at_cursor(struct window_copy_mode_data *data) px = at - (py * sx); grid_get_cell(gd, px, gd->hsize + py - data->oy, &gc); - buf = xrealloc(buf, len + gc.data.size + 1); - memcpy(buf + len, gc.data.data, gc.data.size); - len += gc.data.size; + if (gc.flags & GRID_FLAG_TAB) { + buf = xrealloc(buf, len + 2); + buf[len] = '\t'; + len++; + } else { + buf = xrealloc(buf, len + gc.data.size + 1); + memcpy(buf + len, gc.data.data, gc.data.size); + len += gc.data.size; + } } if (len != 0) buf[len] = '\0'; @@ -4812,7 +4823,13 @@ window_copy_copy_line(struct window_mode_entry *wme, char **buf, size_t *off, grid_get_cell(gd, i, sy, &gc); if (gc.flags & GRID_FLAG_PADDING) continue; - utf8_copy(&ud, &gc.data); + if (gc.flags & GRID_FLAG_TAB) { + memset(ud.data, 0, sizeof ud.data); + *ud.data = '\t'; + ud.have = ud.size = 1; + ud.width = gc.data.width; + } else + utf8_copy(&ud, &gc.data); if (ud.size == 1 && (gc.attr & GRID_ATTR_CHARSET)) { s = tty_acs_get(NULL, ud.data[0]); if (s != NULL && strlen(s) <= sizeof ud.data) { |