diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2024-10-07 12:58:37 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2024-10-07 12:58:37 +0000 |
commit | f98bbb02a1bdbf449e43d6205fce95d81825810f (patch) | |
tree | 35b9d9a88d1646fa2be807fb608ec11384418780 /usr.bin | |
parent | a7761f0b608ba92176f75331a7abc0773cff9bb3 (diff) |
Add prompt-cursor-colour and prompt-cursor-style to set the style of the
cursor in the command prompt and remove the emulated cursor, from
Alexander Arch in GitHub issue 4170.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/tmux/options-table.c | 18 | ||||
-rw-r--r-- | usr.bin/tmux/server-client.c | 49 | ||||
-rw-r--r-- | usr.bin/tmux/status.c | 20 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.1 | 9 |
4 files changed, 62 insertions, 34 deletions
diff --git a/usr.bin/tmux/options-table.c b/usr.bin/tmux/options-table.c index 69326c19004..44c4506df13 100644 --- a/usr.bin/tmux/options-table.c +++ b/usr.bin/tmux/options-table.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options-table.c,v 1.181 2024/10/07 08:50:47 nicm Exp $ */ +/* $OpenBSD: options-table.c,v 1.182 2024/10/07 12:58:36 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -208,6 +208,7 @@ const struct options_name_map options_other_names[] = { { "display-panes-active-color", "display-panes-active-colour" }, { "clock-mode-color", "clock-mode-colour" }, { "cursor-color", "cursor-colour" }, + { "prompt-cursor-color", "prompt-cursor-colour" }, { "pane-colors", "pane-colours" }, { NULL, NULL } }; @@ -832,6 +833,21 @@ const struct options_table_entry options_table[] = { .text = "Style of the status line." }, + { .name = "prompt-cursor-colour", + .type = OPTIONS_TABLE_COLOUR, + .scope = OPTIONS_TABLE_SESSION, + .default_num = 6, + .text = "Colour of the cursor when in the command prompt." + }, + + { .name = "prompt-cursor-style", + .type = OPTIONS_TABLE_CHOICE, + .scope = OPTIONS_TABLE_SESSION, + .choices = options_table_cursor_style_list, + .default_num = 0, + .text = "Style of the cursor when in the command prompt." + }, + { .name = "update-environment", .type = OPTIONS_TABLE_STRING, .scope = OPTIONS_TABLE_SESSION, diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c index 5c4539fada0..65cf1f9bc52 100644 --- a/usr.bin/tmux/server-client.c +++ b/usr.bin/tmux/server-client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server-client.c,v 1.412 2024/10/07 08:50:47 nicm Exp $ */ +/* $OpenBSD: server-client.c,v 1.413 2024/10/07 12:58:36 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -2473,7 +2473,7 @@ server_client_reset_state(struct client *c) /* Move cursor to pane cursor and offset. */ if (c->prompt_string != NULL) { - n = options_get_number(c->session->options, "status-position"); + n = options_get_number(oo, "status-position"); if (n == 0) cy = 0; else { @@ -2484,22 +2484,37 @@ server_client_reset_state(struct client *c) cy = tty->sy - n; } cx = c->prompt_cursor; - mode &= ~MODE_CURSOR; - } else if (c->overlay_draw == NULL) { - cursor = 0; - tty_window_offset(tty, &ox, &oy, &sx, &sy); - if (wp->xoff + s->cx >= ox && wp->xoff + s->cx <= ox + sx && - wp->yoff + s->cy >= oy && wp->yoff + s->cy <= oy + sy) { - cursor = 1; - - cx = wp->xoff + s->cx - ox; - cy = wp->yoff + s->cy - oy; - - if (status_at_line(c) == 0) - cy += status_line_size(c); + + n = options_get_number(oo, "prompt-cursor-colour"); + s->default_ccolour = n; + n = options_get_number(oo, "prompt-cursor-style"); + screen_set_cursor_style(n, &s->default_cstyle, + &s->default_mode); + } else { + n = options_get_number(wp->options, "cursor-colour"); + s->default_ccolour = n; + n = options_get_number(wp->options, "cursor-style"); + screen_set_cursor_style(n, &s->default_cstyle, + &s->default_mode); + + if (c->overlay_draw == NULL) { + cursor = 0; + tty_window_offset(tty, &ox, &oy, &sx, &sy); + if (wp->xoff + s->cx >= ox && + wp->xoff + s->cx <= ox + sx && + wp->yoff + s->cy >= oy && + wp->yoff + s->cy <= oy + sy) { + cursor = 1; + + cx = wp->xoff + s->cx - ox; + cy = wp->yoff + s->cy - oy; + + if (status_at_line(c) == 0) + cy += status_line_size(c); + } + if (!cursor) + mode &= ~MODE_CURSOR; } - if (!cursor) - mode &= ~MODE_CURSOR; } log_debug("%s: cursor to %u,%u", __func__, cx, cy); tty_cursor(tty, cx, cy); diff --git a/usr.bin/tmux/status.c b/usr.bin/tmux/status.c index 65a5f84ddd2..5b6483216d1 100644 --- a/usr.bin/tmux/status.c +++ b/usr.bin/tmux/status.c @@ -1,4 +1,4 @@ -/* $OpenBSD: status.c,v 1.246 2024/10/04 19:16:13 nicm Exp $ */ +/* $OpenBSD: status.c,v 1.247 2024/10/07 12:58:36 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -660,7 +660,7 @@ status_prompt_set(struct client *c, struct cmd_find_state *fs, c->prompt_mode = PROMPT_ENTRY; if (~flags & PROMPT_INCREMENTAL) - c->tty.flags |= (TTY_NOCURSOR|TTY_FREEZE); + c->tty.flags |= TTY_FREEZE; c->flags |= CLIENT_REDRAWSTATUS; if (flags & PROMPT_INCREMENTAL) @@ -738,7 +738,7 @@ status_prompt_redraw(struct client *c) struct screen old_screen; u_int i, lines, offset, left, start, width; u_int pcursor, pwidth, promptline; - struct grid_cell gc, cursorgc; + struct grid_cell gc; struct format_tree *ft; if (c->tty.sx == 0 || c->tty.sy == 0) @@ -761,9 +761,6 @@ status_prompt_redraw(struct client *c) style_apply(&gc, s->options, "message-style", ft); format_free(ft); - memcpy(&cursorgc, &gc, sizeof cursorgc); - cursorgc.attr ^= GRID_ATTR_REVERSE; - start = format_width(c->prompt_string); if (start > c->tty.sx) start = c->tty.sx; @@ -808,16 +805,9 @@ status_prompt_redraw(struct client *c) if (width > offset + pwidth) break; - if (i != c->prompt_index) { - utf8_copy(&gc.data, &c->prompt_buffer[i]); - screen_write_cell(&ctx, &gc); - } else { - utf8_copy(&cursorgc.data, &c->prompt_buffer[i]); - screen_write_cell(&ctx, &cursorgc); - } + utf8_copy(&gc.data, &c->prompt_buffer[i]); + screen_write_cell(&ctx, &gc); } - if (sl->active->cx < screen_size_x(sl->active) && c->prompt_index >= i) - screen_write_putc(&ctx, &cursorgc, ' '); finished: screen_write_stop(&ctx); diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 0bb20ae6d61..bd93f84663e 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.963 2024/10/07 08:50:47 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.964 2024/10/07 12:58:36 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> .\" @@ -4550,6 +4550,13 @@ waits after .Ic prefix is input before dismissing it. Can be set to zero to disable any timeout. +.It Ic prompt-cursor-colour Ar colour +Set the colour of the cursor in the command prompt. +.It Ic prompt-cursor-style Ar style +Set the style of the cursor in the command prompt. +See the +.Ic cursor-style +options for available styles. .It Xo Ic renumber-windows .Op Ic on | off .Xc |