Per NicM's suggestions this patch: * Reimplements -F for choose-{window,session}, and makes the old syntax the default, which means configs won't have to change.
* -s and -w to choose-tree are now the session/window flags. -SW are for formatting. * Moved #define's from tty.c to tmux.h to allow for tty_use_acs() to be used so as to work out if the terminal supports ACS line characters or not when rendering the tree. Will fallback to ASCII rendering if not. --- trunk/cmd-choose-tree.c | 101 ++++++++++++++++++++++++++++++++--------------- trunk/tmux.1 | 16 ++++---- trunk/tmux.h | 8 ++++ trunk/tty.c | 9 ----- 4 files changed, 85 insertions(+), 49 deletions(-) diff --git a/trunk/cmd-choose-tree.c b/trunk/cmd-choose-tree.c index 5de71d5..1bdf3ce 100644 --- a/trunk/cmd-choose-tree.c +++ b/trunk/cmd-choose-tree.c @@ -24,6 +24,10 @@ #include "tmux.h" +#define DEFAULT_WIN_ACTION "select-window -t '%%'" +#define DEFAULT_SES_ACTION "switch-client -t '%%'" +#define DEFAULT_WIN_TEMPLATE DEFAULT_WINDOW_TEMPLATE " \"#{pane_title}\"" + /* * Enter choice mode to choose a session and/or window. */ @@ -35,7 +39,7 @@ void cmd_choose_tree_free(struct window_choose_data *); const struct cmd_entry cmd_choose_tree_entry = { "choose-tree", NULL, - "SWs:w:b:c:t:", 0, 1, + "S:W:swb:c:t:", 0, 1, "[-S] [-W] [-s format] [-w format ] [-b session template] " \ "[-c window template] " CMD_TARGET_WINDOW_USAGE, 0, @@ -46,8 +50,8 @@ const struct cmd_entry cmd_choose_tree_entry = { const struct cmd_entry cmd_choose_session_entry = { "choose-session", NULL, - "Ss:b:t:", 0, 1, - CMD_TARGET_WINDOW_USAGE " [-s format] [-b session template]", + "F:t:", 0, 1, + CMD_TARGET_WINDOW_USAGE " [-F format] [template]", 0, NULL, NULL, @@ -56,8 +60,8 @@ const struct cmd_entry cmd_choose_session_entry = { const struct cmd_entry cmd_choose_window_entry = { "choose-window", NULL, - "Ww:c:t:", 0, 1, - CMD_TARGET_WINDOW_USAGE "[-W] [-w format] [-c window template]", + "F:t:", 0, 1, + CMD_TARGET_WINDOW_USAGE "[-F format] [template]", 0, NULL, NULL, @@ -83,9 +87,6 @@ cmd_choose_tree_exec(struct cmd *self, struct cmd_ctx *ctx) return (-1); } - sflag = self->entry == &cmd_choose_session_entry; - wflag = self->entry == &cmd_choose_window_entry; - s = ctx->curclient->session; tty = &ctx->curclient->tty; @@ -95,45 +96,81 @@ cmd_choose_tree_exec(struct cmd *self, struct cmd_ctx *ctx) if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0) return (0); - if ((ses_action = args_get(args, 'b')) == NULL) - ses_action = "switch-client -t '%%'"; + if (self->entry == &cmd_choose_session_entry) + { + wflag = 0; + sflag = 1; + + if ((ses_template = args_get(args, 'F')) == NULL) + ses_template = DEFAULT_SESSION_TEMPLATE; - if ((win_action = args_get(args, 'c')) == NULL) - win_action = "select-window -t '%%'"; + if (args->argc != 0) + ses_action = args->argv[0]; + else + ses_action = DEFAULT_SES_ACTION; + } - if ((ses_template = args_get(args, 's')) == NULL) - ses_template = DEFAULT_SESSION_TEMPLATE; + if (self->entry == &cmd_choose_window_entry) + { + sflag = 0; + wflag = 1; - if ((win_template = args_get(args, 'w')) == NULL) - win_template = DEFAULT_WINDOW_TEMPLATE " \"#{pane_title}\""; + if ((win_template = args_get(args, 'F')) == NULL) + win_template = DEFAULT_WIN_TEMPLATE; - if (self->entry == &cmd_choose_tree_entry) { - wflag = args_has(args, 'W'); - sflag = args_has(args, 'S'); + if (args->argc != 0) + win_action = args->argv[0]; + else + win_action = DEFAULT_WIN_ACTION; } - if (!wflag && !sflag) { - ctx->error(ctx, "Nothing to display, no flags given."); - window_pane_reset_mode(wl->window->active); - return (-1); + if (self->entry == &cmd_choose_tree_entry) + { + wflag = args_has(args, 'w'); + sflag = args_has(args, 's'); + + if ((ses_action = args_get(args, 'b')) == NULL) + ses_action = DEFAULT_SES_ACTION; + + if ((win_action = args_get(args, 'c')) == NULL) + win_action = DEFAULT_WIN_ACTION; + + if ((ses_template = args_get(args, 'S')) == NULL) + ses_template = DEFAULT_SESSION_TEMPLATE; + + if ((win_template = args_get(args, 'W')) == NULL) + win_template = DEFAULT_WIN_TEMPLATE; } - /* If we're drawing in tree mode, including sessions, then pad the - * window template with ACS drawing characters, otherwise just render - * the windows as a flat list, without any padding. + /* + * If not asking for windows and sessions, assume no "-ws" given and + * hence display the entire tree outright. + */ + if (!wflag && !sflag) + wflag = sflag = 1; + + /* + * If we're drawing in tree mode, including sessions, then pad the + * window template with ACS drawing characters if supported, otherwise + * just render the windows as a flat list, without any padding. */ - if (wflag && sflag) - xasprintf(&final_win_template, " %s%s> %s", - tty_acs_get(tty, 't'), tty_acs_get(tty, 'q'), - win_template); - else + if (wflag && sflag) { + if (tty_use_acs(tty)) { + xasprintf(&final_win_template, " %s%s> %s", + tty_acs_get(tty, 't'), tty_acs_get(tty, 'q'), + win_template); + } else + xasprintf(&final_win_template, " ---> %s", + win_template); + } else final_win_template = xstrdup(win_template); idx_ses = cur_win = -1; RB_FOREACH(s2, sessions, &sessions) { idx_ses++; - /* If we're just choosing windows, jump straight there. Note + /* + * If we're just choosing windows, jump straight there. Note * that this implies the current session, so only choose * windows when the session matches this one. */ diff --git a/trunk/tmux.1 b/trunk/tmux.1 index 4cf41b4..8de6e6a 100644 --- a/trunk/tmux.1 +++ b/trunk/tmux.1 @@ -1095,12 +1095,12 @@ This command works only from inside .Nm . .It Xo .Ic choose-tree -.Op Fl S -.Op Fl W +.Op Fl s +.Op Fl w .Op Fl b Ar session-template .Op Fl c Ar window-template -.Op Fl s Ar format -.Op Fl w Ar format +.Op Fl S Ar format +.Op Fl W Ar format .Op Fl t Ar target-window .Xc Put a window into tree choice mode, where either sessions or windows may be @@ -1117,10 +1117,10 @@ commands are wrappers around . .Pp If -.Fl S +.Fl s is given, will show sessions. If -.Fl W +.Fl w is given, will show windows. If .Fl b @@ -1139,11 +1139,11 @@ This command will run .Ar session-template before it. If -.Fl s +.Fl S is given will display the specified format instead of the default session format. If -.Fl w +.Fl W is given will display the specified format instead of the default window format. For the meaning of the diff --git a/trunk/tmux.h b/trunk/tmux.h index 9cf4a7b..820fc70 100644 --- a/trunk/tmux.h +++ b/trunk/tmux.h @@ -136,6 +136,14 @@ extern char **environ; #define KEYC_MASK_MOD (KEYC_ESCAPE|KEYC_CTRL|KEYC_SHIFT|KEYC_PREFIX) #define KEYC_MASK_KEY (~KEYC_MASK_MOD) +/* TTY capability check. */ +#define tty_use_acs(tty) \ + (tty_term_has((tty)->term, TTYC_ACSC) && !((tty)->flags & TTY_UTF8)) +#define tty_use_rect(tty) \ + ((tty)->xterm_version > 270) +#define tty_pane_full_width(tty, ctx) \ + ((ctx)->xoff == 0 && screen_size_x((ctx)->wp->screen) >= (tty)->sx) + /* Other key codes. */ enum key_code { /* Mouse key. */ diff --git a/trunk/tty.c b/trunk/tty.c index 1c0c7a6..8568ab4 100644 --- a/trunk/tty.c +++ b/trunk/tty.c @@ -54,15 +54,6 @@ void tty_emulate_repeat( void tty_repeat_space(struct tty *, u_int); void tty_cell(struct tty *, const struct grid_cell *, const struct grid_utf8 *); - -#define tty_use_acs(tty) \ - (tty_term_has((tty)->term, TTYC_ACSC) && !((tty)->flags & TTY_UTF8)) -#define tty_use_rect(tty) \ - ((tty)->xterm_version > 270) - -#define tty_pane_full_width(tty, ctx) \ - ((ctx)->xoff == 0 && screen_size_x((ctx)->wp->screen) >= (tty)->sx) - void tty_init(struct tty *tty, struct client *c, int fd, char *term) { -- 1.7.10 ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users