Skip to content

Commit

Permalink
Sync OpenBSD patchset 916:
Browse files Browse the repository at this point in the history
Support DECSCUSR sequence to set the cursor style with two new
terminfo(5) extensions, Cs and Csr. Written by Ailin Nemui.
  • Loading branch information
tcunha committed May 22, 2011
1 parent 8eb31ec commit 792c930
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 7 deletions.
8 changes: 7 additions & 1 deletion input.c
@@ -1,4 +1,4 @@
/* $Id: input.c,v 1.118 2011/05/22 16:25:02 tcunha Exp $ */
/* $Id: input.c,v 1.119 2011/05/22 16:26:09 tcunha Exp $ */

/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
Expand Down Expand Up @@ -126,6 +126,7 @@ enum input_csi_type {
INPUT_CSI_CUU,
INPUT_CSI_DA,
INPUT_CSI_DCH,
INPUT_CSI_DECSCUSR,
INPUT_CSI_DECSTBM,
INPUT_CSI_DL,
INPUT_CSI_DSR,
Expand Down Expand Up @@ -168,6 +169,7 @@ const struct input_table_entry input_csi_table[] = {
{ 'l', "?", INPUT_CSI_RM_PRIVATE },
{ 'm', "", INPUT_CSI_SGR },
{ 'n', "", INPUT_CSI_DSR },
{ 'q', " ", INPUT_CSI_DECSCUSR },
{ 'r', "", INPUT_CSI_DECSTBM },
};

Expand Down Expand Up @@ -1259,6 +1261,10 @@ input_csi_dispatch(struct input_ctx *ictx)
n = input_get(ictx, 0, 1, 1);
screen_write_cursormove(sctx, s->cx, n - 1);
break;
case INPUT_CSI_DECSCUSR:
n = input_get(ictx, 0, 0, 0);
screen_set_cursor_style(s, n);
break;
}

return (0);
Expand Down
3 changes: 2 additions & 1 deletion options-table.c
@@ -1,4 +1,4 @@
/* $Id: options-table.c,v 1.11 2011/05/22 16:25:02 tcunha Exp $ */
/* $Id: options-table.c,v 1.12 2011/05/22 16:26:09 tcunha Exp $ */

/*
* Copyright (c) 2011 Nicholas Marriott <nicm@users.sourceforge.net>
Expand Down Expand Up @@ -367,6 +367,7 @@ const struct options_table_entry session_options_table[] = {
.default_str = "*88col*:colors=88,*256col*:colors=256"
",xterm*:XT:Ms=\\E]52;%p1%s;%p2%s\\007"
":Cc=\\E]12;%p1%s\\007:Cr=\\E]112\\007"
":Cs=\\E[%p1%d q:Csr=\\E[2 q"
},

{ .name = "update-environment",
Expand Down
11 changes: 10 additions & 1 deletion screen.c
@@ -1,4 +1,4 @@
/* $Id: screen.c,v 1.105 2011/05/22 16:25:02 tcunha Exp $ */
/* $Id: screen.c,v 1.106 2011/05/22 16:26:09 tcunha Exp $ */

/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
Expand Down Expand Up @@ -41,6 +41,7 @@ screen_init(struct screen *s, u_int sx, u_int sy, u_int hlimit)
else
s->title = xstrdup("");

s->cstyle = 0;
s->ccolour = xstrdup("");
s->tabs = NULL;

Expand Down Expand Up @@ -92,6 +93,14 @@ screen_reset_tabs(struct screen *s)
bit_set(s->tabs, i);
}

/* Set screen cursor style. */
void
screen_set_cursor_style(struct screen *s, u_int style)
{
if (style <= 4)
s->cstyle = style;
}

/* Set screen cursor colour. */
void
screen_set_cursor_colour(struct screen *s, const char *colour_string)
Expand Down
15 changes: 14 additions & 1 deletion tmux.1
@@ -1,4 +1,4 @@
.\" $Id: tmux.1,v 1.315 2011/05/22 16:25:02 tcunha Exp $
.\" $Id: tmux.1,v 1.316 2011/05/22 16:26:09 tcunha Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
.\"
Expand Down Expand Up @@ -2836,6 +2836,19 @@ See the
option above and the
.Xr xterm 1
man page.
.It Em Cs, Csr
Change the cursor style.
If set allows a sequence such as:
.Bd -literal -offset indent
$ printf '\e033[4 q'
.Ed
.Pp
To change the cursor to an underline.
If
.Em Csr
is set, it will be used to reset the cursor style instead
of
.Em Cs .
.It Em Cc, Cr
The first takes one string argument and is used to set the cursor colour;
the second takes no arguments and restores the default cursor colour.
Expand Down
7 changes: 6 additions & 1 deletion tmux.h
@@ -1,4 +1,4 @@
/* $Id: tmux.h,v 1.626 2011/05/22 16:25:02 tcunha Exp $ */
/* $Id: tmux.h,v 1.627 2011/05/22 16:26:09 tcunha Exp $ */

/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
Expand Down Expand Up @@ -185,7 +185,9 @@ enum tty_code_code {
TTYC_CNORM, /* cursor_normal, ve */
TTYC_COLORS, /* max_colors, Co */
TTYC_CR, /* restore cursor colour, Cr */
TTYC_CS1, /* set cursor style, Cs */
TTYC_CSR, /* change_scroll_region, cs */
TTYC_CSR1, /* reset cursor style, Csr */
TTYC_CUB, /* parm_left_cursor, LE */
TTYC_CUB1, /* cursor_left, le */
TTYC_CUD, /* parm_down_cursor, DO */
Expand Down Expand Up @@ -712,6 +714,7 @@ struct screen {
u_int cx; /* cursor x */
u_int cy; /* cursor y */

u_int cstyle; /* cursor style */
char *ccolour; /* cursor colour string */

u_int rupper; /* scroll region top */
Expand Down Expand Up @@ -1010,6 +1013,7 @@ struct tty {

u_int cx;
u_int cy;
u_int cstyle;
char *ccolour;

int mode;
Expand Down Expand Up @@ -1846,6 +1850,7 @@ void screen_init(struct screen *, u_int, u_int, u_int);
void screen_reinit(struct screen *);
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_title(struct screen *, const char *);
void screen_resize(struct screen *, u_int, u_int);
Expand Down
4 changes: 3 additions & 1 deletion tty-term.c
@@ -1,4 +1,4 @@
/* $Id: tty-term.c,v 1.50 2011/05/22 16:25:02 tcunha Exp $ */
/* $Id: tty-term.c,v 1.51 2011/05/22 16:26:09 tcunha Exp $ */

/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
Expand Down Expand Up @@ -47,7 +47,9 @@ const struct tty_term_code_entry tty_term_codes[NTTYCODE] = {
{ TTYC_CNORM, TTYCODE_STRING, "cnorm" },
{ TTYC_COLORS, TTYCODE_NUMBER, "colors" },
{ TTYC_CR, TTYCODE_STRING, "Cr" },
{ TTYC_CS1, TTYCODE_STRING, "Cs" },
{ TTYC_CSR, TTYCODE_STRING, "csr" },
{ TTYC_CSR1, TTYCODE_STRING, "Csr" },
{ TTYC_CUB, TTYCODE_STRING, "cub" },
{ TTYC_CUB1, TTYCODE_STRING, "cub1" },
{ TTYC_CUD, TTYCODE_STRING, "cud" },
Expand Down
19 changes: 18 additions & 1 deletion tty.c
@@ -1,4 +1,4 @@
/* $Id: tty.c,v 1.211 2011/05/22 16:25:02 tcunha Exp $ */
/* $Id: tty.c,v 1.212 2011/05/22 16:26:09 tcunha Exp $ */

/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
Expand Down Expand Up @@ -69,6 +69,7 @@ tty_init(struct tty *tty, int fd, char *term)
if ((path = ttyname(fd)) == NULL)
fatalx("ttyname failed");
tty->path = xstrdup(path);
tty->cstyle = 0;
tty->ccolour = xstrdup("");

tty->flags = 0;
Expand Down Expand Up @@ -244,6 +245,12 @@ tty_stop_tty(struct tty *tty)
tty_raw(tty, tty_term_string(tty->term, TTYC_SGR0));
tty_raw(tty, tty_term_string(tty->term, TTYC_RMKX));
tty_raw(tty, tty_term_string(tty->term, TTYC_CLEAR));
if (tty_term_has(tty->term, TTYC_CS1) && tty->cstyle != 0) {
if (tty_term_has(tty->term, TTYC_CSR1))
tty_raw(tty, tty_term_string(tty->term, TTYC_CSR1));
else if (tty_term_has(tty->term, TTYC_CS1))
tty_raw(tty, tty_term_string1(tty->term, TTYC_CS1, 0));
}
tty_raw(tty, tty_term_string(tty->term, TTYC_CR));

tty_raw(tty, tty_term_string(tty->term, TTYC_CNORM));
Expand Down Expand Up @@ -429,6 +436,16 @@ tty_update_mode(struct tty *tty, int mode, struct screen *s)
else
tty_putcode(tty, TTYC_CIVIS);
}
if (tty->cstyle != s->cstyle) {
if (tty_term_has(tty->term, TTYC_CS1)) {
if (s->cstyle == 0 &&
tty_term_has(tty->term, TTYC_CSR1))
tty_putcode(tty, TTYC_CSR1);
else
tty_putcode1(tty, TTYC_CS1, s->cstyle);
}
tty->cstyle = s->cstyle;
}
if (changed & ALL_MOUSE_MODES) {
if (mode & ALL_MOUSE_MODES) {
if (mode & MODE_MOUSE_UTF8)
Expand Down

0 comments on commit 792c930

Please sign in to comment.