2009-08-31 20:46:19 +00:00
|
|
|
/* $OpenBSD$ */
|
|
|
|
|
|
|
|
/*
|
2016-01-19 15:59:12 +00:00
|
|
|
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
2009-08-31 20:46:19 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2016-06-16 10:55:47 +00:00
|
|
|
#include <stdlib.h>
|
2019-05-07 20:01:41 +00:00
|
|
|
#include <string.h>
|
2016-06-16 10:55:47 +00:00
|
|
|
|
2009-08-31 20:46:19 +00:00
|
|
|
#include "tmux.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Display panes on a client.
|
|
|
|
*/
|
|
|
|
|
2021-08-25 08:51:55 +00:00
|
|
|
static enum args_parse_type cmd_display_panes_args_parse(struct args *,
|
|
|
|
u_int, char **);
|
|
|
|
static enum cmd_retval cmd_display_panes_exec(struct cmd *,
|
|
|
|
struct cmdq_item *);
|
2016-06-16 10:55:47 +00:00
|
|
|
|
2009-08-31 20:46:19 +00:00
|
|
|
const struct cmd_entry cmd_display_panes_entry = {
|
2015-12-13 21:53:57 +00:00
|
|
|
.name = "display-panes",
|
|
|
|
.alias = "displayp",
|
|
|
|
|
2021-08-25 08:51:55 +00:00
|
|
|
.args = { "bd:Nt:", 0, 1, cmd_display_panes_args_parse },
|
2020-11-26 09:19:10 +00:00
|
|
|
.usage = "[-bN] [-d duration] " CMD_TARGET_CLIENT_USAGE " [template]",
|
2015-12-13 21:53:57 +00:00
|
|
|
|
2020-04-13 20:51:57 +00:00
|
|
|
.flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG,
|
2015-12-13 21:53:57 +00:00
|
|
|
.exec = cmd_display_panes_exec
|
2009-08-31 20:46:19 +00:00
|
|
|
};
|
|
|
|
|
2019-05-07 20:01:41 +00:00
|
|
|
struct cmd_display_panes_data {
|
2021-08-23 12:33:55 +00:00
|
|
|
struct cmdq_item *item;
|
|
|
|
struct args_command_state *state;
|
2019-05-07 20:01:41 +00:00
|
|
|
};
|
|
|
|
|
2021-08-25 08:51:55 +00:00
|
|
|
static enum args_parse_type
|
|
|
|
cmd_display_panes_args_parse(__unused struct args *args, __unused u_int idx,
|
|
|
|
__unused char **cause)
|
|
|
|
{
|
|
|
|
return (ARGS_PARSE_COMMANDS_OR_STRING);
|
|
|
|
}
|
|
|
|
|
2019-05-07 20:01:41 +00:00
|
|
|
static void
|
|
|
|
cmd_display_panes_draw_pane(struct screen_redraw_ctx *ctx,
|
|
|
|
struct window_pane *wp)
|
2009-08-31 20:46:19 +00:00
|
|
|
{
|
2019-05-07 20:01:41 +00:00
|
|
|
struct client *c = ctx->c;
|
|
|
|
struct tty *tty = &c->tty;
|
|
|
|
struct session *s = c->session;
|
|
|
|
struct options *oo = s->options;
|
|
|
|
struct window *w = wp->window;
|
2020-09-01 08:50:14 +00:00
|
|
|
struct grid_cell fgc, bgc;
|
|
|
|
u_int pane, idx, px, py, i, j, xoff, yoff, sx, sy;
|
2019-05-07 20:01:41 +00:00
|
|
|
int colour, active_colour;
|
2020-09-01 08:50:14 +00:00
|
|
|
char buf[16], lbuf[16], rbuf[16], *ptr;
|
|
|
|
size_t len, llen, rlen;
|
2017-04-22 10:22:39 +00:00
|
|
|
|
2019-05-07 20:01:41 +00:00
|
|
|
if (wp->xoff + wp->sx <= ctx->ox ||
|
|
|
|
wp->xoff >= ctx->ox + ctx->sx ||
|
|
|
|
wp->yoff + wp->sy <= ctx->oy ||
|
|
|
|
wp->yoff >= ctx->oy + ctx->sy)
|
|
|
|
return;
|
2016-06-16 10:55:47 +00:00
|
|
|
|
2019-05-07 20:01:41 +00:00
|
|
|
if (wp->xoff >= ctx->ox && wp->xoff + wp->sx <= ctx->ox + ctx->sx) {
|
|
|
|
/* All visible. */
|
|
|
|
xoff = wp->xoff - ctx->ox;
|
|
|
|
sx = wp->sx;
|
|
|
|
} else if (wp->xoff < ctx->ox &&
|
|
|
|
wp->xoff + wp->sx > ctx->ox + ctx->sx) {
|
|
|
|
/* Both left and right not visible. */
|
|
|
|
xoff = 0;
|
|
|
|
sx = ctx->sx;
|
|
|
|
} else if (wp->xoff < ctx->ox) {
|
|
|
|
/* Left not visible. */
|
|
|
|
xoff = 0;
|
|
|
|
sx = wp->sx - (ctx->ox - wp->xoff);
|
|
|
|
} else {
|
|
|
|
/* Right not visible. */
|
|
|
|
xoff = wp->xoff - ctx->ox;
|
|
|
|
sx = wp->sx - xoff;
|
|
|
|
}
|
|
|
|
if (wp->yoff >= ctx->oy && wp->yoff + wp->sy <= ctx->oy + ctx->sy) {
|
|
|
|
/* All visible. */
|
|
|
|
yoff = wp->yoff - ctx->oy;
|
|
|
|
sy = wp->sy;
|
|
|
|
} else if (wp->yoff < ctx->oy &&
|
|
|
|
wp->yoff + wp->sy > ctx->oy + ctx->sy) {
|
|
|
|
/* Both top and bottom not visible. */
|
|
|
|
yoff = 0;
|
|
|
|
sy = ctx->sy;
|
|
|
|
} else if (wp->yoff < ctx->oy) {
|
|
|
|
/* Top not visible. */
|
|
|
|
yoff = 0;
|
|
|
|
sy = wp->sy - (ctx->oy - wp->yoff);
|
|
|
|
} else {
|
|
|
|
/* Bottom not visible. */
|
|
|
|
yoff = wp->yoff - ctx->oy;
|
|
|
|
sy = wp->sy - yoff;
|
|
|
|
}
|
2016-06-16 10:55:47 +00:00
|
|
|
|
2019-05-07 20:01:41 +00:00
|
|
|
if (ctx->statustop)
|
|
|
|
yoff += ctx->statuslines;
|
|
|
|
px = sx / 2;
|
|
|
|
py = sy / 2;
|
|
|
|
|
2020-09-01 08:50:14 +00:00
|
|
|
if (window_pane_index(wp, &pane) != 0)
|
2019-05-07 20:01:41 +00:00
|
|
|
fatalx("index not found");
|
2020-09-01 08:50:14 +00:00
|
|
|
len = xsnprintf(buf, sizeof buf, "%u", pane);
|
2019-05-07 20:01:41 +00:00
|
|
|
|
|
|
|
if (sx < len)
|
|
|
|
return;
|
|
|
|
colour = options_get_number(oo, "display-panes-colour");
|
|
|
|
active_colour = options_get_number(oo, "display-panes-active-colour");
|
|
|
|
|
2020-09-01 08:50:14 +00:00
|
|
|
memcpy(&fgc, &grid_default_cell, sizeof fgc);
|
|
|
|
memcpy(&bgc, &grid_default_cell, sizeof bgc);
|
|
|
|
if (w->active == wp) {
|
|
|
|
fgc.fg = active_colour;
|
|
|
|
bgc.bg = active_colour;
|
|
|
|
} else {
|
|
|
|
fgc.fg = colour;
|
|
|
|
bgc.bg = colour;
|
|
|
|
}
|
|
|
|
|
|
|
|
rlen = xsnprintf(rbuf, sizeof rbuf, "%ux%u", wp->sx, wp->sy);
|
|
|
|
if (pane > 9 && pane < 35)
|
|
|
|
llen = xsnprintf(lbuf, sizeof lbuf, "%c", 'a' + (pane - 10));
|
|
|
|
else
|
|
|
|
llen = 0;
|
|
|
|
|
2019-05-07 20:01:41 +00:00
|
|
|
if (sx < len * 6 || sy < 5) {
|
2022-06-30 09:55:53 +00:00
|
|
|
tty_attributes(tty, &fgc, &grid_default_cell, NULL, NULL);
|
2020-09-01 08:50:14 +00:00
|
|
|
if (sx >= len + llen + 1) {
|
|
|
|
len += llen + 1;
|
|
|
|
tty_cursor(tty, xoff + px - len / 2, yoff + py);
|
2021-08-25 08:51:55 +00:00
|
|
|
tty_putn(tty, buf, len, len);
|
2020-09-01 08:50:14 +00:00
|
|
|
tty_putn(tty, " ", 1, 1);
|
|
|
|
tty_putn(tty, lbuf, llen, llen);
|
|
|
|
} else {
|
|
|
|
tty_cursor(tty, xoff + px - len / 2, yoff + py);
|
|
|
|
tty_putn(tty, buf, len, len);
|
|
|
|
}
|
|
|
|
goto out;
|
2019-05-07 20:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
px -= len * 3;
|
|
|
|
py -= 2;
|
|
|
|
|
2022-06-30 09:55:53 +00:00
|
|
|
tty_attributes(tty, &bgc, &grid_default_cell, NULL, NULL);
|
2019-05-07 20:01:41 +00:00
|
|
|
for (ptr = buf; *ptr != '\0'; ptr++) {
|
|
|
|
if (*ptr < '0' || *ptr > '9')
|
|
|
|
continue;
|
|
|
|
idx = *ptr - '0';
|
|
|
|
|
|
|
|
for (j = 0; j < 5; j++) {
|
|
|
|
for (i = px; i < px + 5; i++) {
|
|
|
|
tty_cursor(tty, xoff + i, yoff + py + j);
|
|
|
|
if (window_clock_table[idx][j][i - px])
|
|
|
|
tty_putc(tty, ' ');
|
|
|
|
}
|
2017-08-16 12:12:54 +00:00
|
|
|
}
|
2019-05-07 20:01:41 +00:00
|
|
|
px += 6;
|
|
|
|
}
|
2009-08-31 20:46:19 +00:00
|
|
|
|
2020-09-01 08:50:14 +00:00
|
|
|
if (sy <= 6)
|
|
|
|
goto out;
|
2022-06-30 09:55:53 +00:00
|
|
|
tty_attributes(tty, &fgc, &grid_default_cell, NULL, NULL);
|
2020-09-01 08:50:14 +00:00
|
|
|
if (rlen != 0 && sx >= rlen) {
|
|
|
|
tty_cursor(tty, xoff + sx - rlen, yoff);
|
|
|
|
tty_putn(tty, rbuf, rlen, rlen);
|
|
|
|
}
|
|
|
|
if (llen != 0) {
|
|
|
|
tty_cursor(tty, xoff + sx / 2 + len * 3 - llen - 1,
|
|
|
|
yoff + py + 5);
|
|
|
|
tty_putn(tty, lbuf, llen, llen);
|
|
|
|
}
|
2019-05-07 20:01:41 +00:00
|
|
|
|
2020-09-01 08:50:14 +00:00
|
|
|
out:
|
2019-05-07 20:01:41 +00:00
|
|
|
tty_cursor(tty, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-08-13 18:54:54 +00:00
|
|
|
cmd_display_panes_draw(struct client *c, __unused void *data,
|
|
|
|
struct screen_redraw_ctx *ctx)
|
2019-05-07 20:01:41 +00:00
|
|
|
{
|
|
|
|
struct window *w = c->session->curw->window;
|
|
|
|
struct window_pane *wp;
|
|
|
|
|
|
|
|
log_debug("%s: %s @%u", __func__, c->name, w->id);
|
|
|
|
|
|
|
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
|
|
|
if (window_pane_visible(wp))
|
|
|
|
cmd_display_panes_draw_pane(ctx, wp);
|
|
|
|
}
|
2009-08-31 20:46:19 +00:00
|
|
|
}
|
2016-06-16 10:55:47 +00:00
|
|
|
|
|
|
|
static void
|
2021-08-13 18:54:54 +00:00
|
|
|
cmd_display_panes_free(__unused struct client *c, void *data)
|
2016-06-16 10:55:47 +00:00
|
|
|
{
|
2021-08-13 18:54:54 +00:00
|
|
|
struct cmd_display_panes_data *cdata = data;
|
2019-05-07 20:01:41 +00:00
|
|
|
|
|
|
|
if (cdata->item != NULL)
|
2019-06-18 11:08:42 +00:00
|
|
|
cmdq_continue(cdata->item);
|
2021-08-23 12:33:55 +00:00
|
|
|
args_make_commands_free(cdata->state);
|
2019-05-07 20:01:41 +00:00
|
|
|
free(cdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2021-08-13 18:54:54 +00:00
|
|
|
cmd_display_panes_key(struct client *c, void *data, struct key_event *event)
|
2019-05-07 20:01:41 +00:00
|
|
|
{
|
2021-08-13 18:54:54 +00:00
|
|
|
struct cmd_display_panes_data *cdata = data;
|
2021-08-23 12:33:55 +00:00
|
|
|
char *expanded, *error;
|
|
|
|
struct cmdq_item *item = cdata->item, *new_item;
|
|
|
|
struct cmd_list *cmdlist;
|
2019-05-07 20:01:41 +00:00
|
|
|
struct window *w = c->session->curw->window;
|
|
|
|
struct window_pane *wp;
|
2020-09-01 08:50:14 +00:00
|
|
|
u_int index;
|
|
|
|
key_code key;
|
|
|
|
|
|
|
|
if (event->key >= '0' && event->key <= '9')
|
|
|
|
index = event->key - '0';
|
|
|
|
else if ((event->key & KEYC_MASK_MODIFIERS) == 0) {
|
|
|
|
key = (event->key & KEYC_MASK_KEY);
|
|
|
|
if (key >= 'a' && key <= 'z')
|
|
|
|
index = 10 + (key - 'a');
|
|
|
|
else
|
|
|
|
return (-1);
|
|
|
|
} else
|
2019-06-26 18:28:31 +00:00
|
|
|
return (-1);
|
2016-06-16 10:55:47 +00:00
|
|
|
|
2020-09-01 08:50:14 +00:00
|
|
|
wp = window_pane_at_index(w, index);
|
2016-10-16 17:55:14 +00:00
|
|
|
if (wp == NULL)
|
2019-05-07 20:01:41 +00:00
|
|
|
return (1);
|
|
|
|
window_unzoom(w);
|
2018-08-02 07:55:16 +00:00
|
|
|
|
2016-10-16 17:55:14 +00:00
|
|
|
xasprintf(&expanded, "%%%u", wp->id);
|
|
|
|
|
2021-08-23 12:33:55 +00:00
|
|
|
cmdlist = args_make_commands(cdata->state, 1, &expanded, &error);
|
|
|
|
if (cmdlist == NULL) {
|
2020-04-13 18:59:41 +00:00
|
|
|
cmdq_append(c, cmdq_get_error(error));
|
|
|
|
free(error);
|
2021-08-23 12:33:55 +00:00
|
|
|
} else if (item == NULL) {
|
|
|
|
new_item = cmdq_get_command(cmdlist, NULL);
|
|
|
|
cmdq_append(c, new_item);
|
|
|
|
} else {
|
|
|
|
new_item = cmdq_get_command(cmdlist, cmdq_get_state(item));
|
|
|
|
cmdq_insert_after(item, new_item);
|
2019-02-06 07:36:06 +00:00
|
|
|
}
|
2016-10-16 17:55:14 +00:00
|
|
|
|
|
|
|
free(expanded);
|
2019-05-07 20:01:41 +00:00
|
|
|
return (1);
|
|
|
|
}
|
2016-10-16 17:55:14 +00:00
|
|
|
|
2019-05-07 20:01:41 +00:00
|
|
|
static enum cmd_retval
|
|
|
|
cmd_display_panes_exec(struct cmd *self, struct cmdq_item *item)
|
|
|
|
{
|
2020-04-13 08:26:27 +00:00
|
|
|
struct args *args = cmd_get_args(self);
|
2020-04-13 20:51:57 +00:00
|
|
|
struct client *tc = cmdq_get_target_client(item);
|
|
|
|
struct session *s = tc->session;
|
2021-08-25 08:51:55 +00:00
|
|
|
u_int delay;
|
2019-05-07 20:01:41 +00:00
|
|
|
char *cause;
|
|
|
|
struct cmd_display_panes_data *cdata;
|
2021-08-23 12:33:55 +00:00
|
|
|
int wait = !args_has(args, 'b');
|
2019-05-07 20:01:41 +00:00
|
|
|
|
2020-04-13 20:51:57 +00:00
|
|
|
if (tc->overlay_draw != NULL)
|
2019-05-07 20:01:41 +00:00
|
|
|
return (CMD_RETURN_NORMAL);
|
|
|
|
|
|
|
|
if (args_has(args, 'd')) {
|
|
|
|
delay = args_strtonum(args, 'd', 0, UINT_MAX, &cause);
|
|
|
|
if (cause != NULL) {
|
|
|
|
cmdq_error(item, "delay %s", cause);
|
|
|
|
free(cause);
|
|
|
|
return (CMD_RETURN_ERROR);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
delay = options_get_number(s->options, "display-panes-time");
|
|
|
|
|
2021-08-23 12:33:55 +00:00
|
|
|
cdata = xcalloc(1, sizeof *cdata);
|
|
|
|
if (wait)
|
2019-05-07 20:01:41 +00:00
|
|
|
cdata->item = item;
|
2021-08-23 12:33:55 +00:00
|
|
|
cdata->state = args_make_commands_prepare(self, item, 0,
|
|
|
|
"select-pane -t \"%%%\"", wait, 0);
|
2019-05-07 20:01:41 +00:00
|
|
|
|
2020-11-26 09:19:10 +00:00
|
|
|
if (args_has(args, 'N')) {
|
|
|
|
server_client_set_overlay(tc, delay, NULL, NULL,
|
2021-07-21 08:06:36 +00:00
|
|
|
cmd_display_panes_draw, NULL, cmd_display_panes_free, NULL,
|
2020-11-26 09:19:10 +00:00
|
|
|
cdata);
|
|
|
|
} else {
|
|
|
|
server_client_set_overlay(tc, delay, NULL, NULL,
|
|
|
|
cmd_display_panes_draw, cmd_display_panes_key,
|
2021-07-21 08:06:36 +00:00
|
|
|
cmd_display_panes_free, NULL, cdata);
|
2020-11-26 09:19:10 +00:00
|
|
|
}
|
2018-08-02 07:55:16 +00:00
|
|
|
|
2021-08-23 12:33:55 +00:00
|
|
|
if (!wait)
|
2019-05-07 20:01:41 +00:00
|
|
|
return (CMD_RETURN_NORMAL);
|
|
|
|
return (CMD_RETURN_WAIT);
|
2016-06-16 10:55:47 +00:00
|
|
|
}
|