diff options
author | 2019-03-18 14:10:25 +0000 | |
---|---|---|
committer | 2019-03-18 14:10:25 +0000 | |
commit | 71431f24a7c77d16abf872da635f23c689a953c1 (patch) | |
tree | e731dde25753c248d347a88b21d992a690f5250e | |
parent | Insert a missing input line break after a .Vt macro; (diff) | |
download | wireguard-openbsd-71431f24a7c77d16abf872da635f23c689a953c1.tar.xz wireguard-openbsd-71431f24a7c77d16abf872da635f23c689a953c1.zip |
Add format variables for the default formats for the various modes
(tree_mode_format and so on) and add a -a flag to display-message to
list variables with values.
-rw-r--r-- | usr.bin/tmux/cmd-display-message.c | 20 | ||||
-rw-r--r-- | usr.bin/tmux/format.c | 38 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.1 | 13 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 6 | ||||
-rw-r--r-- | usr.bin/tmux/window-buffer.c | 3 | ||||
-rw-r--r-- | usr.bin/tmux/window-client.c | 3 | ||||
-rw-r--r-- | usr.bin/tmux/window-tree.c | 3 | ||||
-rw-r--r-- | usr.bin/tmux/window.c | 13 |
8 files changed, 83 insertions, 16 deletions
diff --git a/usr.bin/tmux/cmd-display-message.c b/usr.bin/tmux/cmd-display-message.c index 8c2a8819094..b5a741143b0 100644 --- a/usr.bin/tmux/cmd-display-message.c +++ b/usr.bin/tmux/cmd-display-message.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-display-message.c,v 1.47 2019/03/15 10:04:13 nicm Exp $ */ +/* $OpenBSD: cmd-display-message.c,v 1.48 2019/03/18 14:10:25 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org> @@ -39,8 +39,8 @@ const struct cmd_entry cmd_display_message_entry = { .name = "display-message", .alias = "display", - .args = { "c:pt:F:v", 0, 1 }, - .usage = "[-pv] [-c target-client] [-F format] " + .args = { "ac:pt:F:v", 0, 1 }, + .usage = "[-apv] [-c target-client] [-F format] " CMD_TARGET_PANE_USAGE " [message]", .target = { 't', CMD_FIND_PANE, 0 }, @@ -49,6 +49,14 @@ const struct cmd_entry cmd_display_message_entry = { .exec = cmd_display_message_exec }; +static void +cmd_display_message_each(const char *key, const char *value, void *arg) +{ + struct cmdq_item *item = arg; + + cmdq_print(item, "%s=%s", key, value); +} + static enum cmd_retval cmd_display_message_exec(struct cmd *self, struct cmdq_item *item) { @@ -91,6 +99,12 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item) ft = format_create(item->client, item, FORMAT_NONE, flags); format_defaults(ft, target_c, s, wl, wp); + if (args_has(args, 'a')) { + if (item != NULL) + format_each(ft, cmd_display_message_each, item); + return (CMD_RETURN_NORMAL); + } + msg = format_expand_time(ft, template); if (args_has(self->args, 'p')) cmdq_print(item, "%s", msg); diff --git a/usr.bin/tmux/format.c b/usr.bin/tmux/format.c index 58a19e69d64..a88effc34a4 100644 --- a/usr.bin/tmux/format.c +++ b/usr.bin/tmux/format.c @@ -1,4 +1,4 @@ -/* $OpenBSD: format.c,v 1.183 2019/03/18 09:46:42 nicm Exp $ */ +/* $OpenBSD: format.c,v 1.184 2019/03/18 14:10:25 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -701,7 +701,9 @@ format_merge(struct format_tree *ft, struct format_tree *from) struct format_tree * format_create(struct client *c, struct cmdq_item *item, int tag, int flags) { - struct format_tree *ft; + struct format_tree *ft; + const struct window_mode **wm; + char tmp[64]; if (!event_initialized(&format_job_event)) { evtimer_set(&format_job_event, format_job_timer, NULL); @@ -727,6 +729,14 @@ format_create(struct client *c, struct cmdq_item *item, int tag, int flags) format_add(ft, "socket_path", "%s", socket_path); format_add_tv(ft, "start_time", &start_time); + for (wm = all_window_modes; *wm != NULL; wm++) { + if ((*wm)->default_format != NULL) { + xsnprintf(tmp, sizeof tmp, "%s_format", (*wm)->name); + tmp[strcspn(tmp, "-")] = '_'; + format_add(ft, tmp, "%s", (*wm)->default_format); + } + } + if (item != NULL) { if (item->cmd != NULL) format_add(ft, "command", "%s", item->cmd->entry->name); @@ -755,6 +765,30 @@ format_free(struct format_tree *ft) free(ft); } +/* Walk each format. */ +void +format_each(struct format_tree *ft, void (*cb)(const char *, const char *, + void *), void *arg) +{ + struct format_entry *fe; + static char s[64]; + + RB_FOREACH(fe, format_entry_tree, &ft->tree) { + if (fe->t != 0) { + xsnprintf(s, sizeof s, "%lld", (long long)fe->t); + cb(fe->key, fe->value, s); + } else { + if (fe->value == NULL && fe->cb != NULL) { + fe->cb(ft, fe); + if (fe->value == NULL) + fe->value = xstrdup(""); + } + cb(fe->key, fe->value, arg); + } + } +} + + /* Add a key-value pair. */ void format_add(struct format_tree *ft, const char *key, const char *fmt, ...) diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 0ad26ea58c7..0194b59b16f 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.623 2019/03/17 19:33:12 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.624 2019/03/18 14:10:25 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> .\" @@ -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: March 17 2019 $ +.Dd $Mdocdate: March 18 2019 $ .Dt TMUX 1 .Os .Sh NAME @@ -4177,7 +4177,7 @@ option. This command works only from inside .Nm . .It Xo Ic display-message -.Op Fl pv +.Op Fl apv .Op Fl c Ar target-client .Op Fl t Ar target-pane .Op Ar message @@ -4200,9 +4200,10 @@ if is given, otherwise the active pane for the session attached to .Ar target-client . .Pp -With -.Fl v , -verbose logging is printed as the format is parsed. +.Fl v +prints verbose logging as the format is parsed and +.Fl a +lists the format variables and their values. .El .Sh BUFFERS .Nm diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 75fa606fcb0..4826aed41e1 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.872 2019/03/18 11:58:40 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.873 2019/03/18 14:10:25 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -704,6 +704,7 @@ struct screen_write_ctx { struct window_mode_entry; struct window_mode { const char *name; + const char *default_format; struct screen *(*init)(struct window_mode_entry *, struct cmd_find_state *, struct args *); @@ -1587,6 +1588,8 @@ struct format_tree *format_create(struct client *, struct cmdq_item *, int, void format_free(struct format_tree *); void printflike(3, 4) format_add(struct format_tree *, const char *, const char *, ...); +void format_each(struct format_tree *, void (*)(const char *, + const char *, void *), void *); char *format_expand_time(struct format_tree *, const char *); char *format_expand(struct format_tree *, const char *); char *format_single(struct cmdq_item *, const char *, @@ -2156,6 +2159,7 @@ void screen_select_cell(struct screen *, struct grid_cell *, /* window.c */ extern struct windows windows; extern struct window_pane_tree all_window_panes; +extern const struct window_mode *all_window_modes[]; int window_cmp(struct window *, struct window *); RB_PROTOTYPE(windows, window, entry, window_cmp); int winlink_cmp(struct winlink *, struct winlink *); diff --git a/usr.bin/tmux/window-buffer.c b/usr.bin/tmux/window-buffer.c index f4a90e16b78..de81cdda141 100644 --- a/usr.bin/tmux/window-buffer.c +++ b/usr.bin/tmux/window-buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window-buffer.c,v 1.16 2019/03/12 20:02:47 nicm Exp $ */ +/* $OpenBSD: window-buffer.c,v 1.17 2019/03/18 14:10:25 nicm Exp $ */ /* * Copyright (c) 2017 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -41,6 +41,7 @@ static void window_buffer_key(struct window_mode_entry *, const struct window_mode window_buffer_mode = { .name = "buffer-mode", + .default_format = WINDOW_BUFFER_DEFAULT_FORMAT, .init = window_buffer_init, .free = window_buffer_free, diff --git a/usr.bin/tmux/window-client.c b/usr.bin/tmux/window-client.c index 588933205ac..e15eec83148 100644 --- a/usr.bin/tmux/window-client.c +++ b/usr.bin/tmux/window-client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window-client.c,v 1.19 2019/03/16 19:12:13 nicm Exp $ */ +/* $OpenBSD: window-client.c,v 1.20 2019/03/18 14:10:25 nicm Exp $ */ /* * Copyright (c) 2017 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -42,6 +42,7 @@ static void window_client_key(struct window_mode_entry *, const struct window_mode window_client_mode = { .name = "client-mode", + .default_format = WINDOW_CLIENT_DEFAULT_FORMAT, .init = window_client_init, .free = window_client_free, diff --git a/usr.bin/tmux/window-tree.c b/usr.bin/tmux/window-tree.c index dcc25def295..5784a6ac2d1 100644 --- a/usr.bin/tmux/window-tree.c +++ b/usr.bin/tmux/window-tree.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window-tree.c,v 1.34 2019/03/12 20:02:47 nicm Exp $ */ +/* $OpenBSD: window-tree.c,v 1.35 2019/03/18 14:10:25 nicm Exp $ */ /* * Copyright (c) 2017 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -55,6 +55,7 @@ static void window_tree_key(struct window_mode_entry *, const struct window_mode window_tree_mode = { .name = "tree-mode", + .default_format = WINDOW_TREE_DEFAULT_FORMAT, .init = window_tree_init, .free = window_tree_free, diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c index ccc9c5a6d2c..6f4adbc51f3 100644 --- a/usr.bin/tmux/window.c +++ b/usr.bin/tmux/window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window.c,v 1.221 2019/03/14 09:53:52 nicm Exp $ */ +/* $OpenBSD: window.c,v 1.222 2019/03/18 14:10:25 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -62,6 +62,17 @@ static u_int next_window_pane_id; static u_int next_window_id; static u_int next_active_point; +/* List of window modes. */ +const struct window_mode *all_window_modes[] = { + &window_buffer_mode, + &window_client_mode, + &window_clock_mode, + &window_copy_mode, + &window_tree_mode, + &window_view_mode, + NULL +}; + static void window_destroy(struct window *); static struct window_pane *window_pane_create(struct window *, u_int, u_int, |