diff --git a/cmd-display-message.c b/cmd-display-message.c index 07cd12a8..2e935908 100644 --- a/cmd-display-message.c +++ b/cmd-display-message.c @@ -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/format.c b/format.c index ea1372e7..0d1351ad 100644 --- a/format.c +++ b/format.c @@ -716,7 +716,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); @@ -743,6 +745,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); @@ -771,6 +781,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/tmux.1 b/tmux.1 index aadf113b..de25d227 100644 --- a/tmux.1 +++ b/tmux.1 @@ -4282,7 +4282,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 @@ -4305,9 +4305,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/tmux.h b/tmux.h index db45ac13..16727536 100644 --- a/tmux.h +++ b/tmux.h @@ -706,6 +706,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 *); @@ -1589,6 +1590,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 *, @@ -2158,6 +2161,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/window-buffer.c b/window-buffer.c index 379b90ad..79b02e9b 100644 --- a/window-buffer.c +++ b/window-buffer.c @@ -40,6 +40,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/window-client.c b/window-client.c index db1edbb3..ec98984d 100644 --- a/window-client.c +++ b/window-client.c @@ -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/window-tree.c b/window-tree.c index c0d71a7e..55dda694 100644 --- a/window-tree.c +++ b/window-tree.c @@ -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/window.c b/window.c index 66806001..2f1049b2 100644 --- a/window.c +++ b/window.c @@ -60,6 +60,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,