From: nicm Date: Wed, 20 Jan 2021 07:16:54 +0000 (+0000) Subject: Change so that window_flags escapes # automatically which means configs X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=b1a381546f9dc2215d80971fa40bd4aad7153408;p=openbsd Change so that window_flags escapes # automatically which means configs will not have to change. A new format window_raw_flags contains the old unescaped version. --- diff --git a/usr.bin/tmux/cmd-list-windows.c b/usr.bin/tmux/cmd-list-windows.c index 0b599c64071..0a6c745cdf8 100644 --- a/usr.bin/tmux/cmd-list-windows.c +++ b/usr.bin/tmux/cmd-list-windows.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-list-windows.c,v 1.46 2020/04/13 10:59:58 nicm Exp $ */ +/* $OpenBSD: cmd-list-windows.c,v 1.47 2021/01/20 07:16:54 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -28,14 +28,14 @@ */ #define LIST_WINDOWS_TEMPLATE \ - "#{window_index}: #{window_name}#{window_flags} " \ + "#{window_index}: #{window_name}#{window_raw_flags} " \ "(#{window_panes} panes) " \ "[#{window_width}x#{window_height}] " \ "[layout #{window_layout}] #{window_id}" \ "#{?window_active, (active),}"; #define LIST_WINDOWS_WITH_SESSION_TEMPLATE \ "#{session_name}:" \ - "#{window_index}: #{window_name}#{window_flags} " \ + "#{window_index}: #{window_name}#{window_raw_flags} " \ "(#{window_panes} panes) " \ "[#{window_width}x#{window_height}] " diff --git a/usr.bin/tmux/control-notify.c b/usr.bin/tmux/control-notify.c index 6ab63d8f61c..5c8a9499b06 100644 --- a/usr.bin/tmux/control-notify.c +++ b/usr.bin/tmux/control-notify.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control-notify.c,v 1.27 2020/05/21 07:24:13 nicm Exp $ */ +/* $OpenBSD: control-notify.c,v 1.28 2021/01/20 07:16:54 nicm Exp $ */ /* * Copyright (c) 2012 Nicholas Marriott @@ -49,7 +49,7 @@ control_notify_window_layout_changed(struct window *w) char *cp; template = "%layout-change #{window_id} #{window_layout} " - "#{window_visible_layout} #{window_flags}"; + "#{window_visible_layout} #{window_raw_flags}"; TAILQ_FOREACH(c, &clients, entry) { if (!CONTROL_SHOULD_NOTIFY_CLIENT(c) || c->session == NULL) diff --git a/usr.bin/tmux/format.c b/usr.bin/tmux/format.c index ca93f639ae7..b08e329ec44 100644 --- a/usr.bin/tmux/format.c +++ b/usr.bin/tmux/format.c @@ -1,4 +1,4 @@ -/* $OpenBSD: format.c,v 1.269 2020/12/30 18:29:40 nicm Exp $ */ +/* $OpenBSD: format.c,v 1.270 2021/01/20 07:16:54 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott @@ -89,7 +89,7 @@ format_job_cmp(struct format_job *fj1, struct format_job *fj2) #define FORMAT_TIMESTRING 0x1 #define FORMAT_BASENAME 0x2 #define FORMAT_DIRNAME 0x4 -#define FORMAT_QUOTE 0x8 +#define FORMAT_QUOTE_SHELL 0x8 #define FORMAT_LITERAL 0x10 #define FORMAT_EXPAND 0x20 #define FORMAT_EXPANDTIME 0x40 @@ -99,7 +99,7 @@ format_job_cmp(struct format_job *fj1, struct format_job *fj2) #define FORMAT_PRETTY 0x400 #define FORMAT_LENGTH 0x800 #define FORMAT_WIDTH 0x1000 -#define FORMAT_ESCAPE 0x2000 +#define FORMAT_QUOTE_STYLE 0x2000 /* Limit on recursion. */ #define FORMAT_LOOP_LIMIT 10 @@ -1378,9 +1378,9 @@ format_add_cb(struct format_tree *ft, const char *key, format_cb cb) fe->value = NULL; } -/* Quote special characters in string. */ +/* Quote shell special characters in string. */ static char * -format_quote(const char *s) +format_quote_shell(const char *s) { const char *cp; char *out, *at; @@ -1395,9 +1395,9 @@ format_quote(const char *s) return (out); } -/* Escape #s in string. */ +/* Quote #s in string. */ static char * -format_escape(const char *s) +format_quote_style(const char *s) { const char *cp; char *out, *at; @@ -1552,14 +1552,14 @@ found: found = xstrdup(dirname(saved)); free(saved); } - if (modifiers & FORMAT_QUOTE) { + if (modifiers & FORMAT_QUOTE_SHELL) { saved = found; - found = xstrdup(format_quote(saved)); + found = xstrdup(format_quote_shell(saved)); free(saved); } - if (modifiers & FORMAT_ESCAPE) { + if (modifiers & FORMAT_QUOTE_STYLE) { saved = found; - found = xstrdup(format_escape(saved)); + found = xstrdup(format_quote_style(saved)); free(saved); } return (found); @@ -2240,9 +2240,10 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen, break; case 'q': if (fm->argc < 1) - modifiers |= FORMAT_QUOTE; - else if (strchr(fm->argv[0], 'e') != NULL) - modifiers |= FORMAT_ESCAPE; + modifiers |= FORMAT_QUOTE_SHELL; + else if (strchr(fm->argv[0], 'e') != NULL || + strchr(fm->argv[0], 'h') != NULL) + modifiers |= FORMAT_QUOTE_STYLE; break; case 'E': modifiers |= FORMAT_EXPAND; @@ -2980,7 +2981,8 @@ format_defaults_winlink(struct format_tree *ft, struct winlink *wl) format_add(ft, "window_index", "%d", wl->idx); format_add_cb(ft, "window_stack_index", format_cb_window_stack_index); - format_add(ft, "window_flags", "%s", window_printable_flags(wl)); + format_add(ft, "window_flags", "%s", window_printable_flags(wl, 1)); + format_add(ft, "window_raw_flags", "%s", window_printable_flags(wl, 0)); format_add(ft, "window_active", "%d", wl == s->curw); format_add_cb(ft, "window_active_sessions", format_cb_window_active_sessions); diff --git a/usr.bin/tmux/options-table.c b/usr.bin/tmux/options-table.c index ed511153523..18ba826c91d 100644 --- a/usr.bin/tmux/options-table.c +++ b/usr.bin/tmux/options-table.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options-table.c,v 1.137 2021/01/04 08:43:16 nicm Exp $ */ +/* $OpenBSD: options-table.c,v 1.138 2021/01/20 07:16:54 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott @@ -1018,7 +1018,7 @@ const struct options_table_entry options_table[] = { { .name = "window-status-current-format", .type = OPTIONS_TABLE_STRING, .scope = OPTIONS_TABLE_WINDOW, - .default_str = "#I:#W#{?window_flags,#{q/e:window_flags}, }", + .default_str = "#I:#W#{?window_flags,#{window_flags}, }", .text = "Format of the current window in the status line." }, @@ -1034,7 +1034,7 @@ const struct options_table_entry options_table[] = { { .name = "window-status-format", .type = OPTIONS_TABLE_STRING, .scope = OPTIONS_TABLE_WINDOW, - .default_str = "#I:#W#{?window_flags,#{q/e:window_flags}, }", + .default_str = "#I:#W#{?window_flags,#{window_flags}, }", .text = "Format of windows in the status line, except the current " "window." }, diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index e4033d66984..9ca90db3451 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.811 2021/01/17 16:17:41 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.812 2021/01/20 07:16:54 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott .\" @@ -14,7 +14,7 @@ .\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING .\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: January 17 2021 $ +.Dd $Mdocdate: January 20 2021 $ .Dt TMUX 1 .Os .Sh NAME @@ -4651,8 +4651,8 @@ of the variable respectively. .Ql q:\& will escape .Xr sh 1 -special characters or with an -.Ql e +special characters or with a +.Ql h suffix, escape hash characters (so .Ql # becomes @@ -4882,7 +4882,8 @@ The following variables are available, where appropriate: .It Li "window_cell_height" Ta "" Ta "Height of each cell in pixels" .It Li "window_cell_width" Ta "" Ta "Width of each cell in pixels" .It Li "window_end_flag" Ta "" Ta "1 if window has the highest index" -.It Li "window_flags" Ta "#F" Ta "Window flags" +.It Li "window_flags" Ta "#F" Ta "Window flags with # escaped as ##" +.It Li "window_raw_flags" Ta "" Ta "Window flags with nothing escaped" .It Li "window_format" Ta "" Ta "1 if format is for a window" .It Li "window_height" Ta "" Ta "Height of window" .It Li "window_id" Ta "" Ta "Unique window ID" diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index e82bd5257ba..7617811f855 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.1085 2021/01/18 10:27:54 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.1086 2021/01/20 07:16:54 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -2761,7 +2761,7 @@ int window_pane_key(struct window_pane *, struct client *, int window_pane_visible(struct window_pane *); u_int window_pane_search(struct window_pane *, const char *, int, int); -const char *window_printable_flags(struct winlink *); +const char *window_printable_flags(struct winlink *, int); struct window_pane *window_pane_find_up(struct window_pane *); struct window_pane *window_pane_find_down(struct window_pane *); struct window_pane *window_pane_find_left(struct window_pane *); diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c index d6ba1b30d89..3082d1b7c1d 100644 --- a/usr.bin/tmux/window.c +++ b/usr.bin/tmux/window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window.c,v 1.267 2020/12/15 08:31:50 nicm Exp $ */ +/* $OpenBSD: window.c,v 1.268 2021/01/20 07:16:54 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -803,15 +803,18 @@ window_destroy_panes(struct window *w) } const char * -window_printable_flags(struct winlink *wl) +window_printable_flags(struct winlink *wl, int escape) { struct session *s = wl->session; static char flags[32]; int pos; pos = 0; - if (wl->flags & WINLINK_ACTIVITY) + if (wl->flags & WINLINK_ACTIVITY) { flags[pos++] = '#'; + if (escape) + flags[pos++] = '#'; + } if (wl->flags & WINLINK_BELL) flags[pos++] = '!'; if (wl->flags & WINLINK_SILENCE)