2959.
-/* $OpenBSD: input.c,v 1.193 2021/10/05 12:46:02 nicm Exp $ */
+/* $OpenBSD: input.c,v 1.194 2021/11/01 09:34:49 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
static void input_osc_4(struct input_ctx *, const char *);
static void input_osc_10(struct input_ctx *, const char *);
static void input_osc_11(struct input_ctx *, const char *);
+static void input_osc_12(struct input_ctx *, const char *);
static void input_osc_52(struct input_ctx *, const char *);
static void input_osc_104(struct input_ctx *, const char *);
static void input_osc_110(struct input_ctx *, const char *);
static void input_osc_111(struct input_ctx *, const char *);
+static void input_osc_112(struct input_ctx *, const char *);
/* Transition entry/exit handlers. */
static void input_clear(struct input_ctx *);
input_osc_11(ictx, p);
break;
case 12:
- if (utf8_isvalid(p) && *p != '?') /* ? is colour request */
- screen_set_cursor_colour(sctx->s, p);
+ input_osc_12(ictx, p);
break;
case 52:
input_osc_52(ictx, p);
input_osc_111(ictx, p);
break;
case 112:
- if (*p == '\0') /* no arguments allowed */
- screen_set_cursor_colour(sctx->s, "");
+ input_osc_112(ictx, p);
break;
default:
log_debug("%s: unknown '%u'", __func__, option);
u_char r, g, b;
const char *end;
- if (c == 8 || (~c & COLOUR_FLAG_RGB))
+ if (c != -1)
+ c = colour_force_rgb(c);
+ if (c == -1)
return;
colour_split_rgb(c, &r, &g, &b);
}
}
-/* Handle the OSC 110 sequence for resetting background colour. */
+/* Handle the OSC 110 sequence for resetting foreground colour. */
static void
input_osc_110(struct input_ctx *ictx, const char *p)
{
}
}
+/* Handle the OSC 12 sequence for setting and querying cursor colour. */
+static void
+input_osc_12(struct input_ctx *ictx, const char *p)
+{
+ struct window_pane *wp = ictx->wp;
+ int c;
+
+ if (strcmp(p, "?") == 0) {
+ if (wp != NULL) {
+ c = ictx->ctx.s->ccolour;
+ if (c == -1)
+ c = ictx->ctx.s->default_ccolour;
+ input_osc_colour_reply(ictx, 12, c);
+ }
+ return;
+ }
+
+ if ((c = input_osc_parse_colour(p)) == -1) {
+ log_debug("bad OSC 12: %s", p);
+ return;
+ }
+ screen_set_cursor_colour(ictx->ctx.s, c);
+}
+
+/* Handle the OSC 112 sequence for resetting cursor colour. */
+static void
+input_osc_112(struct input_ctx *ictx, const char *p)
+{
+ if (*p == '\0') /* no arguments allowed */
+ screen_set_cursor_colour(ictx->ctx.s, -1);
+}
+
+
/* Handle the OSC 52 sequence for setting the clipboard. */
static void
input_osc_52(struct input_ctx *ictx, const char *p)
-/* $OpenBSD: options-table.c,v 1.152 2021/10/14 13:19:01 nicm Exp $ */
+/* $OpenBSD: options-table.c,v 1.153 2021/11/01 09:34:49 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com>
{ "display-panes-color", "display-panes-colour" },
{ "display-panes-active-color", "display-panes-active-colour" },
{ "clock-mode-color", "clock-mode-colour" },
+ { "cursor-color", "cursor-colour" },
{ "pane-colors", "pane-colours" },
{ NULL, NULL }
};
"If empty, no command is run."
},
+ { .name = "cursor-colour",
+ .type = OPTIONS_TABLE_COLOUR,
+ .scope = OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE,
+ .default_num = -1,
+ .text = "Colour of the cursor."
+ },
+
{ .name = "default-terminal",
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_SERVER,
-/* $OpenBSD: options.c,v 1.65 2021/10/14 13:19:01 nicm Exp $ */
+/* $OpenBSD: options.c,v 1.66 2021/11/01 09:34:49 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
struct session *s;
struct window *w;
struct window_pane *wp;
+ int c;
if (strcmp(name, "automatic-rename") == 0) {
RB_FOREACH(w, windows, &windows) {
if (w->active == NULL)
continue;
- if (options_get_number(w->options, "automatic-rename"))
+ if (options_get_number(w->options, name))
w->active->flags |= PANE_CHANGED;
}
}
+ if (strcmp(name, "cursor-colour") == 0) {
+ RB_FOREACH(wp, window_pane_tree, &all_window_panes) {
+ c = options_get_number(wp->options, name);
+ wp->screen->default_ccolour = c;
+ }
+ }
if (strcmp(name, "key-table") == 0) {
TAILQ_FOREACH(loop, &clients, entry)
server_client_set_key_table(loop, NULL);
-/* $OpenBSD: screen.c,v 1.76 2021/10/05 12:46:02 nicm Exp $ */
+/* $OpenBSD: screen.c,v 1.77 2021/11/01 09:34:49 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
s->path = NULL;
s->cstyle = SCREEN_CURSOR_DEFAULT;
- s->ccolour = xstrdup("");
+ s->ccolour = -1;
+ s->default_ccolour = -1;
s->tabs = NULL;
s->sel = NULL;
free(s->tabs);
free(s->path);
free(s->title);
- free(s->ccolour);
if (s->write_list != NULL)
screen_write_free_list(s);
/* Set screen cursor colour. */
void
-screen_set_cursor_colour(struct screen *s, const char *colour)
+screen_set_cursor_colour(struct screen *s, int colour)
{
- free(s->ccolour);
- s->ccolour = xstrdup(colour);
+ s->ccolour = colour;
}
/* Set screen title. */
-.\" $OpenBSD: tmux.1,v 1.867 2021/10/25 21:21:16 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.868 2021/11/01 09:34:49 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.\"
.\" 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: October 25 2021 $
+.Dd $Mdocdate: November 1 2021 $
.Dt TMUX 1
.Os
.Sh NAME
interactive application starts and restores it on exit, so that any output
visible before the application starts reappears unchanged after it exits.
.Pp
+.It Ic cursor-colour Ar colour
+Set the colour of the cursor.
+.Pp
.It Ic pane-colours[] Ar colour
The default colour palette.
Each entry in the array defines the colour
-/* $OpenBSD: tmux.h,v 1.1152 2021/10/28 18:54:33 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.1153 2021/11/01 09:34:49 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
u_int cy; /* cursor y */
enum screen_cursor_style cstyle; /* cursor style */
- char *ccolour; /* cursor colour */
+ int ccolour; /* cursor colour */
+ int default_ccolour;
u_int rupper; /* scroll region top */
u_int rlower; /* scroll region bottom */
u_int cx;
u_int cy;
enum screen_cursor_style cstyle;
- char *ccolour;
+ int ccolour;
int oflag;
u_int oox;
void screen_free(struct screen *);
void screen_reset_tabs(struct screen *);
void screen_set_cursor_style(struct screen *, u_int);
-void screen_set_cursor_colour(struct screen *, const char *);
+void screen_set_cursor_colour(struct screen *, int);
int screen_set_title(struct screen *, const char *);
void screen_set_path(struct screen *, const char *);
void screen_push_title(struct screen *);
-/* $OpenBSD: tty.c,v 1.409 2021/10/28 18:57:06 nicm Exp $ */
+/* $OpenBSD: tty.c,v 1.410 2021/11/01 09:34:49 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
static void tty_set_italics(struct tty *);
static int tty_try_colour(struct tty *, int, const char *);
-static void tty_force_cursor_colour(struct tty *, const char *);
+static void tty_force_cursor_colour(struct tty *, int);
static void tty_cursor_pane(struct tty *, const struct tty_ctx *, u_int,
u_int);
static void tty_cursor_pane_unless_wrap(struct tty *,
tty->client = c;
tty->cstyle = SCREEN_CURSOR_DEFAULT;
- tty->ccolour = xstrdup("");
+ tty->ccolour = -1;
if (tcgetattr(c->fd, &tty->tio) != 0)
return (-1);
tty->flags |= TTY_STARTED;
tty_invalidate(tty);
- if (*tty->ccolour != '\0')
- tty_force_cursor_colour(tty, "");
+ if (tty->ccolour != -1)
+ tty_force_cursor_colour(tty, -1);
tty->mouse_drag_flag = 0;
tty->mouse_drag_update = NULL;
}
if (tty->mode & MODE_BRACKETPASTE)
tty_raw(tty, tty_term_string(tty->term, TTYC_DSBP));
- if (*tty->ccolour != '\0')
+ if (tty->ccolour != -1)
tty_raw(tty, tty_term_string(tty->term, TTYC_CR));
tty_raw(tty, tty_term_string(tty->term, TTYC_CNORM));
tty_free(struct tty *tty)
{
tty_close(tty);
- free(tty->ccolour);
}
void
}
static void
-tty_force_cursor_colour(struct tty *tty, const char *ccolour)
+tty_force_cursor_colour(struct tty *tty, int c)
{
- if (*ccolour == '\0')
+ u_char r, g, b;
+ char s[13] = "";
+
+ if (c != -1)
+ c = colour_force_rgb(c);
+ if (c == tty->ccolour)
+ return;
+ if (c == -1)
tty_putcode(tty, TTYC_CR);
- else
- tty_putcode_ptr1(tty, TTYC_CS, ccolour);
- free(tty->ccolour);
- tty->ccolour = xstrdup(ccolour);
+ else {
+ colour_split_rgb(c, &r, &g, &b);
+ xsnprintf(s, sizeof s, "rgb:%02hhx/%02hhx/%02hhx", r, g, b);
+ tty_putcode_ptr1(tty, TTYC_CS, s);
+ }
+ tty->ccolour = c;
}
static void
tty_update_cursor(struct tty *tty, int mode, int changed, struct screen *s)
{
- enum screen_cursor_style cstyle;
+ enum screen_cursor_style cstyle;
+ int ccolour;
/* Set cursor colour if changed. */
- if (s != NULL && strcmp(s->ccolour, tty->ccolour) != 0)
- tty_force_cursor_colour(tty, s->ccolour);
+ if (s != NULL) {
+ ccolour = s->ccolour;
+ if (s->ccolour == -1)
+ ccolour = s->default_ccolour;
+ tty_force_cursor_colour(tty, ccolour);
+ }
/* If cursor is off, set as invisible. */
if (~mode & MODE_CURSOR) {