Use a separate define for each default format template and strip clutter

from the choose-tree defaults.
This commit is contained in:
Nicholas Marriott 2012-08-14 08:51:53 +00:00
parent 6804d5841e
commit 73c6785538
13 changed files with 66 additions and 30 deletions

View File

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

View File

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

View File

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

View File

@ -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;
}
/*

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

60
tmux.h
View File

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