Key (v) and flag (-N) to toggle preview in choose modes.

This commit is contained in:
nicm
2017-08-23 09:39:11 +00:00
parent 1d60dd5872
commit 08b125194e
3 changed files with 35 additions and 14 deletions

View File

@ -30,8 +30,8 @@ const struct cmd_entry cmd_choose_tree_entry = {
.name = "choose-tree", .name = "choose-tree",
.alias = NULL, .alias = NULL,
.args = { "F:f:O:st:w", 0, 1 }, .args = { "F:f:NO:st:w", 0, 1 },
.usage = "[-sw] [-F format] [-f filter] [-O sort-order] " .usage = "[-Nsw] [-F format] [-f filter] [-O sort-order] "
CMD_TARGET_PANE_USAGE, CMD_TARGET_PANE_USAGE,
.target = { 't', CMD_FIND_PANE, 0 }, .target = { 't', CMD_FIND_PANE, 0 },
@ -44,8 +44,8 @@ const struct cmd_entry cmd_choose_client_entry = {
.name = "choose-client", .name = "choose-client",
.alias = NULL, .alias = NULL,
.args = { "F:f:O:t:", 0, 1 }, .args = { "F:f:NO:t:", 0, 1 },
.usage = "[-F format] [-f filter] [-O sort-order] " .usage = "[-N] [-F format] [-f filter] [-O sort-order] "
CMD_TARGET_PANE_USAGE, CMD_TARGET_PANE_USAGE,
.target = { 't', CMD_FIND_PANE, 0 }, .target = { 't', CMD_FIND_PANE, 0 },
@ -58,8 +58,8 @@ const struct cmd_entry cmd_choose_buffer_entry = {
.name = "choose-buffer", .name = "choose-buffer",
.alias = NULL, .alias = NULL,
.args = { "F:f:O:t:", 0, 1 }, .args = { "F:f:NO:t:", 0, 1 },
.usage = "[-F format] [-f filter] [-O sort-order] " .usage = "[-N] [-F format] [-f filter] [-O sort-order] "
CMD_TARGET_PANE_USAGE, CMD_TARGET_PANE_USAGE,
.target = { 't', CMD_FIND_PANE, 0 }, .target = { 't', CMD_FIND_PANE, 0 },

View File

@ -60,6 +60,7 @@ struct mode_tree_data {
struct screen screen; struct screen screen;
int preview;
char *search; char *search;
char *filter; char *filter;
}; };
@ -295,6 +296,8 @@ mode_tree_start(struct window_pane *wp, struct args *args,
mtd->sort_size = sort_size; mtd->sort_size = sort_size;
mtd->sort_type = 0; mtd->sort_type = 0;
mtd->preview = !args_has(args, 'N');
sort = args_get(args, 'O'); sort = args_get(args, 'O');
if (sort != NULL) { if (sort != NULL) {
for (i = 0; i < sort_size; i++) { for (i = 0; i < sort_size; i++) {
@ -348,12 +351,15 @@ mode_tree_build(struct mode_tree_data *mtd)
mode_tree_set_current(mtd, tag); mode_tree_set_current(mtd, tag);
mtd->width = screen_size_x(s); mtd->width = screen_size_x(s);
mtd->height = (screen_size_y(s) / 3) * 2; if (mtd->preview) {
if (mtd->height > mtd->line_size) mtd->height = (screen_size_y(s) / 3) * 2;
mtd->height = screen_size_y(s) / 2; if (mtd->height > mtd->line_size)
if (mtd->height < 10) mtd->height = screen_size_y(s) / 2;
mtd->height = screen_size_y(s); if (mtd->height < 10)
if (screen_size_y(s) - mtd->height < 2) mtd->height = screen_size_y(s);
if (screen_size_y(s) - mtd->height < 2)
mtd->height = screen_size_y(s);
} else
mtd->height = screen_size_y(s); mtd->height = screen_size_y(s);
} }
@ -549,7 +555,7 @@ mode_tree_draw(struct mode_tree_data *mtd)
} }
sy = screen_size_y(s); sy = screen_size_y(s);
if (sy <= 4 || h <= 4 || sy - h <= 4 || w <= 4) { if (!mtd->preview || sy <= 4 || h <= 4 || sy - h <= 4 || w <= 4) {
screen_write_stop(&ctx); screen_write_stop(&ctx);
return; return;
} }
@ -861,6 +867,10 @@ mode_tree_key(struct mode_tree_data *mtd, struct client *c, key_code *key,
mode_tree_filter_callback, mode_tree_filter_free, mtd, mode_tree_filter_callback, mode_tree_filter_free, mtd,
PROMPT_NOFORMAT); PROMPT_NOFORMAT);
break; break;
case 'v':
mtd->preview = !mtd->preview;
mode_tree_build(mtd);
break;
} }
return (0); return (0);
} }

13
tmux.1
View File

@ -1354,6 +1354,7 @@ the end of the visible pane.
The default is to capture only the visible contents of the pane. The default is to capture only the visible contents of the pane.
.It Xo .It Xo
.Ic choose-client .Ic choose-client
.Op Fl N
.Op Fl F Ar format .Op Fl F Ar format
.Op Fl f Ar filter .Op Fl f Ar filter
.Op Fl O Ar sort-order .Op Fl O Ar sort-order
@ -1381,6 +1382,7 @@ The following keys may be used in client mode:
.It Li "Z" Ta "Suspend tagged clients" .It Li "Z" Ta "Suspend tagged clients"
.It Li "f" Ta "Enter a format to filter items" .It Li "f" Ta "Enter a format to filter items"
.It Li "O" Ta "Change sort order" .It Li "O" Ta "Change sort order"
.It Li "v" Ta "Toggle preview"
.It Li "q" Ta "Exit mode" .It Li "q" Ta "Exit mode"
.El .El
.Pp .Pp
@ -1404,10 +1406,12 @@ or
specifies an initial filter. specifies an initial filter.
.Fl F .Fl F
specifies the format for each item in the list. specifies the format for each item in the list.
.Fl N
starts without the preview.
This command works only if at least one client is attached. This command works only if at least one client is attached.
.It Xo .It Xo
.Ic choose-tree .Ic choose-tree
.Op Fl sw .Op Fl Nsw
.Op Fl F Ar format .Op Fl F Ar format
.Op Fl f Ar filter .Op Fl f Ar filter
.Op Fl O Ar sort-order .Op Fl O Ar sort-order
@ -1436,6 +1440,7 @@ The following keys may be used in tree mode:
.It Li "\&:" Ta "Run a command for each tagged item" .It Li "\&:" Ta "Run a command for each tagged item"
.It Li "f" Ta "Enter a format to filter items" .It Li "f" Ta "Enter a format to filter items"
.It Li "O" Ta "Change sort order" .It Li "O" Ta "Change sort order"
.It Li "v" Ta "Toggle preview"
.It Li "q" Ta "Exit mode" .It Li "q" Ta "Exit mode"
.El .El
.Pp .Pp
@ -1458,6 +1463,8 @@ or
specifies an initial filter. specifies an initial filter.
.Fl F .Fl F
specifies the format for each item in the tree. specifies the format for each item in the tree.
.Fl N
starts without the preview.
This command works only if at least one client is attached. This command works only if at least one client is attached.
.It Xo .It Xo
.Ic display-panes .Ic display-panes
@ -4054,6 +4061,7 @@ The buffer commands are as follows:
.Bl -tag -width Ds .Bl -tag -width Ds
.It Xo .It Xo
.Ic choose-buffer .Ic choose-buffer
.Op Fl N
.Op Fl F Ar format .Op Fl F Ar format
.Op Fl f Ar filter .Op Fl f Ar filter
.Op Fl O Ar sort-order .Op Fl O Ar sort-order
@ -4077,6 +4085,7 @@ The following keys may be used in buffer mode:
.It Li "D" Ta "Delete tagged buffers" .It Li "D" Ta "Delete tagged buffers"
.It Li "f" Ta "Enter a format to filter items" .It Li "f" Ta "Enter a format to filter items"
.It Li "O" Ta "Change sort order" .It Li "O" Ta "Change sort order"
.It Li "v" Ta "Toggle preview"
.It Li "q" Ta "Exit mode" .It Li "q" Ta "Exit mode"
.El .El
.Pp .Pp
@ -4099,6 +4108,8 @@ or
specifies an initial filter. specifies an initial filter.
.Fl F .Fl F
specifies the format for each item in the list. specifies the format for each item in the list.
.Fl N
starts without the preview.
This command works only if at least one client is attached. This command works only if at least one client is attached.
.It Ic clear-history Op Fl t Ar target-pane .It Ic clear-history Op Fl t Ar target-pane
.D1 (alias: Ic clearhist ) .D1 (alias: Ic clearhist )