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.
pull/2546/head
nicm 2021-01-20 07:16:54 +00:00
parent 0730dce5ab
commit fb774b77d0
7 changed files with 31 additions and 25 deletions

View File

@ -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}] "

View File

@ -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)

View File

@ -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);

View File

@ -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."
},

7
tmux.1
View File

@ -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"

2
tmux.h
View File

@ -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 *);

View File

@ -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)