summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2024-10-01 10:10:30 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2024-10-01 10:10:30 +0000
commit1bdf50d53c09823aa5584905a5f30f96f799d0b0 (patch)
treedecb64b9c1ca4be20b2c0e8b7e163632e2b18255
parentd9206fe62689f3ba29a1868df3193345bc077023 (diff)
Add a way to make the preview larger in tree mode, GitHub issue 4124.
-rw-r--r--usr.bin/tmux/mode-tree.c57
-rw-r--r--usr.bin/tmux/tmux.18
2 files changed, 49 insertions, 16 deletions
diff --git a/usr.bin/tmux/mode-tree.c b/usr.bin/tmux/mode-tree.c
index 41c220100ca..0bd42b324f9 100644
--- a/usr.bin/tmux/mode-tree.c
+++ b/usr.bin/tmux/mode-tree.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mode-tree.c,v 1.69 2024/08/21 04:17:09 nicm Exp $ */
+/* $OpenBSD: mode-tree.c,v 1.70 2024/10/01 10:10:29 nicm Exp $ */
/*
* Copyright (c) 2017 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -30,6 +30,12 @@ enum mode_tree_search_dir {
MODE_TREE_SEARCH_BACKWARD
};
+enum mode_tree_preview {
+ MODE_TREE_PREVIEW_OFF,
+ MODE_TREE_PREVIEW_NORMAL,
+ MODE_TREE_PREVIEW_BIG
+};
+
struct mode_tree_item;
TAILQ_HEAD(mode_tree_list, mode_tree_item);
@@ -414,7 +420,12 @@ mode_tree_start(struct window_pane *wp, struct args *args,
mtd->sort_list = sort_list;
mtd->sort_size = sort_size;
- mtd->preview = !args_has(args, 'N');
+ if (args_has(args, 'N') > 1)
+ mtd->preview = MODE_TREE_PREVIEW_BIG;
+ else if (args_has(args, 'N'))
+ mtd->preview = MODE_TREE_PREVIEW_OFF;
+ else
+ mtd->preview = MODE_TREE_PREVIEW_NORMAL;
sort = args_get(args, 'O');
if (sort != NULL) {
@@ -470,12 +481,21 @@ mode_tree_set_height(struct mode_tree_data *mtd)
if (height < screen_size_y(s))
mtd->height = screen_size_y(s) - height;
} else {
- mtd->height = (screen_size_y(s) / 3) * 2;
- if (mtd->height > mtd->line_size)
- mtd->height = screen_size_y(s) / 2;
+ if (mtd->preview == MODE_TREE_PREVIEW_NORMAL) {
+ mtd->height = (screen_size_y(s) / 3) * 2;
+ if (mtd->height > mtd->line_size)
+ mtd->height = screen_size_y(s) / 2;
+ if (mtd->height < 10)
+ mtd->height = screen_size_y(s);
+ } else if (mtd->preview == MODE_TREE_PREVIEW_BIG) {
+ mtd->height = screen_size_y(s) / 4;
+ if (mtd->height > mtd->line_size)
+ mtd->height = mtd->line_size;
+ if (mtd->height < 2)
+ mtd->height = 2;
+ } else
+ mtd->height = screen_size_y(s);
}
- if (mtd->height < 10)
- mtd->height = screen_size_y(s);
if (screen_size_y(s) - mtd->height < 2)
mtd->height = screen_size_y(s);
}
@@ -510,7 +530,7 @@ mode_tree_build(struct mode_tree_data *mtd)
mode_tree_set_current(mtd, tag);
mtd->width = screen_size_x(s);
- if (mtd->preview)
+ if (mtd->preview != MODE_TREE_PREVIEW_OFF)
mode_tree_set_height(mtd);
else
mtd->height = screen_size_y(s);
@@ -742,8 +762,11 @@ mode_tree_draw(struct mode_tree_data *mtd)
}
}
+ if (mtd->preview == MODE_TREE_PREVIEW_OFF)
+ goto done;
+
sy = screen_size_y(s);
- if (!mtd->preview || sy <= 4 || h <= 4 || sy - h <= 4 || w <= 4)
+ if (sy <= 4 || h < 2 || sy - h <= 4 || w <= 4)
goto done;
line = &mtd->line_list[mtd->current];
@@ -1041,7 +1064,7 @@ mode_tree_key(struct mode_tree_data *mtd, struct client *c, key_code *key,
if (x > mtd->width || y > mtd->height) {
if (*key == KEYC_MOUSEDOWN3_PANE)
mode_tree_display_menu(mtd, c, x, y, 1);
- if (!mtd->preview)
+ if (mtd->preview == MODE_TREE_PREVIEW_OFF)
*key = KEYC_NONE;
return (0);
}
@@ -1232,9 +1255,19 @@ mode_tree_key(struct mode_tree_data *mtd, struct client *c, key_code *key,
PROMPT_NOFORMAT, PROMPT_TYPE_SEARCH);
break;
case 'v':
- mtd->preview = !mtd->preview;
+ switch (mtd->preview) {
+ case MODE_TREE_PREVIEW_OFF:
+ mtd->preview = MODE_TREE_PREVIEW_BIG;
+ break;
+ case MODE_TREE_PREVIEW_NORMAL:
+ mtd->preview = MODE_TREE_PREVIEW_OFF;
+ break;
+ case MODE_TREE_PREVIEW_BIG:
+ mtd->preview = MODE_TREE_PREVIEW_NORMAL;
+ break;
+ }
mode_tree_build(mtd);
- if (mtd->preview)
+ if (mtd->preview != MODE_TREE_PREVIEW_OFF)
mode_tree_check_selected(mtd);
break;
}
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index 246df394e24..418621a9f76 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.957 2024/09/16 20:46:58 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.958 2024/10/01 10:10:29 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.\"
@@ -14,7 +14,7 @@
.\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
.\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: September 16 2024 $
+.Dd $Mdocdate: October 1 2024 $
.Dt TMUX 1
.Os
.Sh NAME
@@ -2627,7 +2627,7 @@ specifies the format for each item in the list and
.Fl K
a format for each shortcut key; both are evaluated once for each line.
.Fl N
-starts without the preview.
+starts without the preview or if given twice with the larger preview.
This command works only if at least one client is attached.
.It Xo
.Ic choose-tree
@@ -2711,7 +2711,7 @@ specifies the format for each item in the tree and
.Fl K
a format for each shortcut key; both are evaluated once for each line.
.Fl N
-starts without the preview.
+starts without the preview or if given twice with the larger preview.
.Fl G
includes all sessions in any session groups in the tree rather than only the
first.