From 73c678553809956f428fec9db3210a5576d5883f Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Tue, 14 Aug 2012 08:51:53 +0000 Subject: [PATCH] Use a separate define for each default format template and strip clutter from the choose-tree defaults. --- cmd-break-pane.c | 2 +- cmd-choose-buffer.c | 2 +- cmd-choose-client.c | 2 +- cmd-choose-tree.c | 10 +++----- cmd-display-message.c | 2 +- cmd-find-window.c | 2 +- cmd-list-buffers.c | 2 +- cmd-list-clients.c | 2 +- cmd-list-sessions.c | 2 +- cmd-list-windows.c | 6 ++--- cmd-new-window.c | 2 +- cmd-split-window.c | 2 +- tmux.h | 60 +++++++++++++++++++++++++++++++++++-------- 13 files changed, 66 insertions(+), 30 deletions(-) diff --git a/cmd-break-pane.c b/cmd-break-pane.c index 5ddb8362..038ec85c 100644 --- a/cmd-break-pane.c +++ b/cmd-break-pane.c @@ -95,7 +95,7 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx) if (args_has(args, 'P')) { if ((template = args_get(args, 'F')) == NULL) - template = DEFAULT_PANE_INFO_TEMPLATE; + template = BREAK_PANE_TEMPLATE; ft = format_create(); if ((c = cmd_find_client(ctx, NULL)) != NULL) diff --git a/cmd-choose-buffer.c b/cmd-choose-buffer.c index 3deedfa9..b811a042 100644 --- a/cmd-choose-buffer.c +++ b/cmd-choose-buffer.c @@ -59,7 +59,7 @@ cmd_choose_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) } if ((template = args_get(args, 'F')) == NULL) - template = DEFAULT_BUFFER_LIST_TEMPLATE; + template = CHOOSE_BUFFER_TEMPLATE; if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL) return (CMD_RETURN_ERROR); diff --git a/cmd-choose-client.c b/cmd-choose-client.c index 4059cbba..299fa3af 100644 --- a/cmd-choose-client.c +++ b/cmd-choose-client.c @@ -70,7 +70,7 @@ cmd_choose_client_exec(struct cmd *self, struct cmd_ctx *ctx) return (CMD_RETURN_NORMAL); if ((template = args_get(args, 'F')) == NULL) - template = DEFAULT_CLIENT_TEMPLATE; + template = CHOOSE_CLIENT_TEMPLATE; if (args->argc != 0) action = xstrdup(args->argv[0]); diff --git a/cmd-choose-tree.c b/cmd-choose-tree.c index 102fdc3c..e4fd267e 100644 --- a/cmd-choose-tree.c +++ b/cmd-choose-tree.c @@ -27,8 +27,6 @@ #define CMD_CHOOSE_TREE_WINDOW_ACTION "select-window -t '%%'" #define CMD_CHOOSE_TREE_SESSION_ACTION "switch-client -t '%%'" -#define CMD_CHOOSE_TREE_WINDOW_TEMPLATE \ - DEFAULT_WINDOW_TEMPLATE " \"#{pane_title}\"" /* * Enter choice mode to choose a session and/or window. @@ -104,7 +102,7 @@ cmd_choose_tree_exec(struct cmd *self, struct cmd_ctx *ctx) if (self->entry == &cmd_choose_session_entry) { sflag = 1; if ((ses_template = args_get(args, 'F')) == NULL) - ses_template = DEFAULT_SESSION_TEMPLATE; + ses_template = CHOOSE_TREE_SESSION_TEMPLATE; if (args->argc != 0) ses_action = args->argv[0]; @@ -113,7 +111,7 @@ cmd_choose_tree_exec(struct cmd *self, struct cmd_ctx *ctx) } else if (self->entry == &cmd_choose_window_entry) { wflag = 1; if ((win_template = args_get(args, 'F')) == NULL) - win_template = CMD_CHOOSE_TREE_WINDOW_TEMPLATE; + win_template = CHOOSE_TREE_WINDOW_TEMPLATE; if (args->argc != 0) win_action = args->argv[0]; @@ -130,10 +128,10 @@ cmd_choose_tree_exec(struct cmd *self, struct cmd_ctx *ctx) win_action = CMD_CHOOSE_TREE_WINDOW_ACTION; if ((ses_template = args_get(args, 'S')) == NULL) - ses_template = DEFAULT_SESSION_TEMPLATE; + ses_template = CHOOSE_TREE_SESSION_TEMPLATE; if ((win_template = args_get(args, 'W')) == NULL) - win_template = CMD_CHOOSE_TREE_WINDOW_TEMPLATE; + win_template = CHOOSE_TREE_WINDOW_TEMPLATE; } /* diff --git a/cmd-display-message.c b/cmd-display-message.c index 1aed4f1d..a520e3db 100644 --- a/cmd-display-message.c +++ b/cmd-display-message.c @@ -76,7 +76,7 @@ cmd_display_message_exec(struct cmd *self, struct cmd_ctx *ctx) if (args->argc != 0) template = args->argv[0]; if (template == NULL) - template = DEFAULT_DISPLAY_MESSAGE_TEMPLATE; + template = DISPLAY_MESSAGE_TEMPLATE; ft = format_create(); format_client(ft, c); diff --git a/cmd-find-window.c b/cmd-find-window.c index e73effbf..44bf1770 100644 --- a/cmd-find-window.c +++ b/cmd-find-window.c @@ -98,7 +98,7 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx) return (CMD_RETURN_ERROR); if ((template = args_get(args, 'F')) == NULL) - template = DEFAULT_FIND_WINDOW_TEMPLATE; + template = FIND_WINDOW_TEMPLATE; match_flags = cmd_find_window_match_flags(args); str = args->argv[0]; diff --git a/cmd-list-buffers.c b/cmd-list-buffers.c index f22a35bc..e7f4b735 100644 --- a/cmd-list-buffers.c +++ b/cmd-list-buffers.c @@ -51,7 +51,7 @@ cmd_list_buffers_exec(unused struct cmd *self, struct cmd_ctx *ctx) const char *template; if ((template = args_get(args, 'F')) == NULL) - template = DEFAULT_BUFFER_LIST_TEMPLATE; + template = LIST_BUFFERS_TEMPLATE; idx = 0; while ((pb = paste_walk_stack(&global_buffers, &idx)) != NULL) { diff --git a/cmd-list-clients.c b/cmd-list-clients.c index af6ebde2..ba479689 100644 --- a/cmd-list-clients.c +++ b/cmd-list-clients.c @@ -60,7 +60,7 @@ cmd_list_clients_exec(struct cmd *self, struct cmd_ctx *ctx) s = NULL; if ((template = args_get(args, 'F')) == NULL) - template = DEFAULT_CLIENT_TEMPLATE; + template = LIST_CLIENTS_TEMPLATE; for (i = 0; i < ARRAY_LENGTH(&clients); i++) { c = ARRAY_ITEM(&clients, i); diff --git a/cmd-list-sessions.c b/cmd-list-sessions.c index 6db1e11c..81cc51cc 100644 --- a/cmd-list-sessions.c +++ b/cmd-list-sessions.c @@ -51,7 +51,7 @@ cmd_list_sessions_exec(struct cmd *self, struct cmd_ctx *ctx) char *line; if ((template = args_get(args, 'F')) == NULL) - template = DEFAULT_SESSION_TEMPLATE; + template = LIST_SESSIONS_TEMPLATE; n = 0; RB_FOREACH(s, sessions, &sessions) { diff --git a/cmd-list-windows.c b/cmd-list-windows.c index 62ae6b11..146d29aa 100644 --- a/cmd-list-windows.c +++ b/cmd-list-windows.c @@ -85,12 +85,10 @@ cmd_list_windows_session( if (template == NULL) { switch (type) { case 0: - template = DEFAULT_WINDOW_TEMPLATE \ - " [layout #{window_layout}] #{window_id}" \ - "#{?window_active, (active),}"; + template = LIST_WINDOWS_TEMPLATE; break; case 1: - template = "#{session_name}:" DEFAULT_WINDOW_TEMPLATE; + template = LIST_WINDOWS_WITH_SESSION_TEMPLATE; break; } } diff --git a/cmd-new-window.c b/cmd-new-window.c index 28dd2358..1d9a1e66 100644 --- a/cmd-new-window.c +++ b/cmd-new-window.c @@ -123,7 +123,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx) if (args_has(args, 'P')) { if ((template = args_get(args, 'F')) == NULL) - template = DEFAULT_PANE_INFO_TEMPLATE; + template = NEW_WINDOW_TEMPLATE; ft = format_create(); if ((c = cmd_find_client(ctx, NULL)) != NULL) diff --git a/cmd-split-window.c b/cmd-split-window.c index 88d451c8..2d51d357 100644 --- a/cmd-split-window.c +++ b/cmd-split-window.c @@ -140,7 +140,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx) if (args_has(args, 'P')) { if ((template = args_get(args, 'F')) == NULL) - template = DEFAULT_PANE_INFO_TEMPLATE; + template = SPLIT_WINDOW_TEMPLATE; ft = format_create(); if ((c = cmd_find_client(ctx, NULL)) != NULL) diff --git a/tmux.h b/tmux.h index 0b20eb56..10d4f03d 100644 --- a/tmux.h +++ b/tmux.h @@ -92,34 +92,74 @@ extern char **environ; #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) #endif -/* Default format templates. */ -#define DEFAULT_BUFFER_LIST_TEMPLATE \ +/* Default template for choose-buffer. */ +#define CHOOSE_BUFFER_TEMPLATE \ "#{line}: #{buffer_size} bytes: \"#{buffer_sample}\"" -#define DEFAULT_CLIENT_TEMPLATE \ + +/* Default template for choose-client. */ +#define CHOOSE_CLIENT_TEMPLATE \ "#{client_tty}: #{session_name} " \ "[#{client_width}x#{client_height} #{client_termname}]" \ "#{?client_utf8, (utf8),} #{?client_readonly, (ro),}" -#define DEFAULT_DISPLAY_MESSAGE_TEMPLATE \ + +/* Default templates for choose-tree. */ +#define CHOOSE_TREE_SESSION_TEMPLATE \ + "#{session_name}: #{session_windows} windows " \ + "#{?session_grouped, (group ,}" \ + "#{session_group}#{?session_grouped,),}" \ + "#{?session_attached, (attached),}" +#define CHOOSE_TREE_WINDOW_TEMPLATE \ + "#{window_index}: #{window_name}#{window_flags} " \ + "\"#{pane_title}\"" + +/* Default template for display-message. */ +#define DISPLAY_MESSAGE_TEMPLATE \ "[#{session_name}] #{window_index}:" \ "#{window_name}, current pane #{pane_index} " \ "- (%H:%M %d-%b-%y)" -#define DEFAULT_FIND_WINDOW_TEMPLATE \ + +/* Default template for find-window. */ +#define FIND_WINDOW_TEMPLATE \ "#{window_index}: #{window_name} " \ "[#{window_width}x#{window_height}] " \ "(#{window_panes} panes) #{window_find_matches}" -#define DEFAULT_SESSION_TEMPLATE \ + +/* Default template for list-buffers. */ +#define LIST_BUFFERS_TEMPLATE \ + "#{line}: #{buffer_size} bytes: \"#{buffer_sample}\"" + +/* Default template for list-clients. */ +#define LIST_CLIENTS_TEMPLATE \ + "#{client_tty}: #{session_name} " \ + "[#{client_width}x#{client_height} #{client_termname}]" \ + "#{?client_utf8, (utf8),} #{?client_readonly, (ro),}" + +/* Default template for list-sessions. */ +#define LIST_SESSIONS_TEMPLATE \ "#{session_name}: #{session_windows} windows " \ "(created #{session_created_string}) " \ "[#{session_width}x#{session_height}]" \ "#{?session_grouped, (group ,}" \ "#{session_group}#{?session_grouped,),}" \ "#{?session_attached, (attached),}" -#define DEFAULT_WINDOW_TEMPLATE \ + +/* Default templates for list-windows. */ +#define LIST_WINDOWS_TEMPLATE \ "#{window_index}: #{window_name}#{window_flags} " \ "(#{window_panes} panes) " \ - "[#{window_width}x#{window_height}]" -#define DEFAULT_PANE_INFO_TEMPLATE \ - "#{session_name}:#{window_index}.#{pane_index}" + "[#{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_panes} panes) " \ + "[#{window_width}x#{window_height}] " + +/* Default templates for break-pane, new-window and split-window. */ +#define BREAK_PANE_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}" +#define NEW_WINDOW_TEMPLATE BREAK_PANE_TEMPLATE +#define SPLIT_WINDOW_TEMPLATE BREAK_PANE_TEMPLATE /* Bell option values. */ #define BELL_NONE 0