summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/screen-redraw.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2022-02-01 14:46:43 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2022-02-01 14:46:43 +0000
commit60447b85c73e8d054080543e1112c48e37851b45 (patch)
tree97b1f363cb179c823cbcc86deb993d6690e06c2c /usr.bin/tmux/screen-redraw.c
parent254e7454bc1beb57731d9ceb6c12a646af43a5da (diff)
Add option to show arrows for active pane indicator, GitHub issue 3022
from Marcel Partap.
Diffstat (limited to 'usr.bin/tmux/screen-redraw.c')
-rw-r--r--usr.bin/tmux/screen-redraw.c84
1 files changed, 63 insertions, 21 deletions
diff --git a/usr.bin/tmux/screen-redraw.c b/usr.bin/tmux/screen-redraw.c
index 0fcec8fb02f..77041cce920 100644
--- a/usr.bin/tmux/screen-redraw.c
+++ b/usr.bin/tmux/screen-redraw.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: screen-redraw.c,v 1.92 2021/12/13 09:42:20 nicm Exp $ */
+/* $OpenBSD: screen-redraw.c,v 1.93 2022/02/01 14:46:41 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -34,11 +34,16 @@ static void screen_redraw_set_context(struct client *,
#define START_ISOLATE "\342\201\246"
#define END_ISOLATE "\342\201\251"
+/* Border in relation to a pane. */
enum screen_redraw_border_type {
SCREEN_REDRAW_OUTSIDE,
SCREEN_REDRAW_INSIDE,
- SCREEN_REDRAW_BORDER
+ SCREEN_REDRAW_BORDER_LEFT,
+ SCREEN_REDRAW_BORDER_RIGHT,
+ SCREEN_REDRAW_BORDER_TOP,
+ SCREEN_REDRAW_BORDER_BOTTOM
};
+#define BORDER_MARKERS " +,.-"
/* Get cell border character. */
static void
@@ -102,64 +107,74 @@ static enum screen_redraw_border_type
screen_redraw_pane_border(struct window_pane *wp, u_int px, u_int py,
int pane_status)
{
- u_int ex = wp->xoff + wp->sx, ey = wp->yoff + wp->sy;
+ struct options *oo = wp->window->options;
+ int split = 0;
+ u_int ex = wp->xoff + wp->sx, ey = wp->yoff + wp->sy;
/* Inside pane. */
if (px >= wp->xoff && px < ex && py >= wp->yoff && py < ey)
return (SCREEN_REDRAW_INSIDE);
+ /* Get pane indicator. */
+ switch (options_get_number(oo, "pane-border-indicators")) {
+ case PANE_BORDER_COLOUR:
+ case PANE_BORDER_BOTH:
+ split = 1;
+ break;
+ }
+
/* Left/right borders. */
if (pane_status == PANE_STATUS_OFF) {
- if (screen_redraw_two_panes(wp->window, 0)) {
+ if (screen_redraw_two_panes(wp->window, 0) && split) {
if (wp->xoff == 0 && px == wp->sx && py <= wp->sy / 2)
- return (SCREEN_REDRAW_BORDER);
+ return (SCREEN_REDRAW_BORDER_RIGHT);
if (wp->xoff != 0 &&
px == wp->xoff - 1 &&
py > wp->sy / 2)
- return (SCREEN_REDRAW_BORDER);
+ return (SCREEN_REDRAW_BORDER_LEFT);
} else {
if ((wp->yoff == 0 || py >= wp->yoff - 1) && py <= ey) {
if (wp->xoff != 0 && px == wp->xoff - 1)
- return (SCREEN_REDRAW_BORDER);
+ return (SCREEN_REDRAW_BORDER_LEFT);
if (px == ex)
- return (SCREEN_REDRAW_BORDER);
+ return (SCREEN_REDRAW_BORDER_RIGHT);
}
}
} else {
if ((wp->yoff == 0 || py >= wp->yoff - 1) && py <= ey) {
if (wp->xoff != 0 && px == wp->xoff - 1)
- return (SCREEN_REDRAW_BORDER);
+ return (SCREEN_REDRAW_BORDER_LEFT);
if (px == ex)
- return (SCREEN_REDRAW_BORDER);
+ return (SCREEN_REDRAW_BORDER_RIGHT);
}
}
/* Top/bottom borders. */
if (pane_status == PANE_STATUS_OFF) {
- if (screen_redraw_two_panes(wp->window, 1)) {
+ if (screen_redraw_two_panes(wp->window, 1) && split) {
if (wp->yoff == 0 && py == wp->sy && px <= wp->sx / 2)
- return (SCREEN_REDRAW_BORDER);
+ return (SCREEN_REDRAW_BORDER_BOTTOM);
if (wp->yoff != 0 &&
py == wp->yoff - 1 &&
px > wp->sx / 2)
- return (SCREEN_REDRAW_BORDER);
+ return (SCREEN_REDRAW_BORDER_TOP);
} else {
if ((wp->xoff == 0 || px >= wp->xoff - 1) && px <= ex) {
if (wp->yoff != 0 && py == wp->yoff - 1)
- return (SCREEN_REDRAW_BORDER);
+ return (SCREEN_REDRAW_BORDER_TOP);
if (py == ey)
- return (SCREEN_REDRAW_BORDER);
+ return (SCREEN_REDRAW_BORDER_BOTTOM);
}
}
} else if (pane_status == PANE_STATUS_TOP) {
if ((wp->xoff == 0 || px >= wp->xoff - 1) && px <= ex) {
if (wp->yoff != 0 && py == wp->yoff - 1)
- return (SCREEN_REDRAW_BORDER);
+ return (SCREEN_REDRAW_BORDER_TOP);
}
} else {
if ((wp->xoff == 0 || px >= wp->xoff - 1) && px <= ex) {
if (py == ey)
- return (SCREEN_REDRAW_BORDER);
+ return (SCREEN_REDRAW_BORDER_BOTTOM);
}
}
@@ -189,10 +204,10 @@ screen_redraw_cell_border(struct client *c, u_int px, u_int py, int pane_status)
switch (screen_redraw_pane_border(wp, px, py, pane_status)) {
case SCREEN_REDRAW_INSIDE:
return (0);
- case SCREEN_REDRAW_BORDER:
- return (1);
case SCREEN_REDRAW_OUTSIDE:
break;
+ default:
+ return (1);
}
}
@@ -346,7 +361,7 @@ screen_redraw_check_is(u_int px, u_int py, int pane_status,
enum screen_redraw_border_type border;
border = screen_redraw_pane_border(wp, px, py, pane_status);
- if (border == SCREEN_REDRAW_BORDER)
+ if (border != SCREEN_REDRAW_INSIDE && border != SCREEN_REDRAW_OUTSIDE)
return (1);
return (0);
}
@@ -637,11 +652,12 @@ screen_redraw_draw_borders_cell(struct screen_redraw_ctx *ctx, u_int i, u_int j)
struct options *oo = w->options;
struct tty *tty = &c->tty;
struct format_tree *ft;
- struct window_pane *wp;
+ struct window_pane *wp, *active = server_client_get_pane(c);
struct grid_cell gc;
const struct grid_cell *tmp;
struct overlay_ranges r;
u_int cell_type, x = ctx->ox + i, y = ctx->oy + j;
+ int arrows = 0, border;
int pane_status = ctx->pane_status, isolates;
if (c->overlay_check != NULL) {
@@ -689,6 +705,32 @@ screen_redraw_draw_borders_cell(struct screen_redraw_ctx *ctx, u_int i, u_int j)
tty_cursor(tty, i, j);
if (isolates)
tty_puts(tty, END_ISOLATE);
+
+ switch (options_get_number(oo, "pane-border-indicators")) {
+ case PANE_BORDER_ARROWS:
+ case PANE_BORDER_BOTH:
+ arrows = 1;
+ break;
+ }
+
+ if (wp != NULL && arrows) {
+ border = screen_redraw_pane_border(active, x, y, pane_status);
+ if (((i == wp->xoff + 1 &&
+ (cell_type == CELL_LEFTRIGHT ||
+ (cell_type == CELL_TOPJOIN &&
+ border == SCREEN_REDRAW_BORDER_BOTTOM) ||
+ (cell_type == CELL_BOTTOMJOIN &&
+ border == SCREEN_REDRAW_BORDER_TOP))) ||
+ (j == wp->yoff + 1 &&
+ (cell_type == CELL_TOPBOTTOM ||
+ (cell_type == CELL_LEFTJOIN &&
+ border == SCREEN_REDRAW_BORDER_RIGHT) ||
+ (cell_type == CELL_RIGHTJOIN &&
+ border == SCREEN_REDRAW_BORDER_LEFT)))) &&
+ screen_redraw_check_is(x, y, pane_status, active))
+ utf8_set(&gc.data, BORDER_MARKERS[border]);
+ }
+
tty_cell(tty, &gc, &grid_default_cell, NULL);
if (isolates)
tty_puts(tty, START_ISOLATE);