diff --git a/input.c b/input.c index c8e6b018..989f4757 100644 --- a/input.c +++ b/input.c @@ -1,4 +1,4 @@ -/* $Id: input.c,v 1.117 2011-03-19 23:30:37 tcunha Exp $ */ +/* $Id: input.c,v 1.118 2011-05-22 16:25:02 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -1445,17 +1445,39 @@ input_enter_osc(struct input_ctx *ictx) void input_exit_osc(struct input_ctx *ictx) { + u_char *p = ictx->input_buf; + int option; + if (ictx->flags & INPUT_DISCARD) return; - log_debug("%s: \"%s\"", __func__, ictx->input_buf); - - if (ictx->input_len < 2 || ictx->input_buf[1] != ';') - return; - if (ictx->input_buf[0] != '0' && ictx->input_buf[0] != '2') + if (ictx->input_len < 1 || *p < '0' || *p > '9') return; - screen_set_title(ictx->ctx.s, ictx->input_buf + 2); - server_status_window(ictx->wp->window); + log_debug("%s: \"%s\"", __func__, p); + + option = 0; + while (*p >= '0' && *p <= '9') + option = option * 10 + *p++ - '0'; + if (*p == ';') + p++; + + switch (option) { + case 0: + case 2: + screen_set_title(ictx->ctx.s, p); + server_status_window(ictx->wp->window); + break; + case 12: + screen_set_cursor_colour(ictx->ctx.s, p); + break; + case 112: + if (*p == '\0') /* No arguments allowed. */ + screen_set_cursor_colour(ictx->ctx.s, ""); + break; + default: + log_debug("%s: unknown '%u'", __func__, option); + break; + } } /* APC string started. */ diff --git a/options-table.c b/options-table.c index c068cc48..407ab6c1 100644 --- a/options-table.c +++ b/options-table.c @@ -1,4 +1,4 @@ -/* $Id: options-table.c,v 1.10 2011-05-22 16:23:07 tcunha Exp $ */ +/* $Id: options-table.c,v 1.11 2011-05-22 16:25:02 tcunha Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott @@ -365,13 +365,14 @@ const struct options_table_entry session_options_table[] = { { .name = "terminal-overrides", .type = OPTIONS_TABLE_STRING, .default_str = "*88col*:colors=88,*256col*:colors=256" - ",xterm*:XT:Ms=\\E]52;%p1%s;%p2%s\\007" + ",xterm*:XT:Ms=\\E]52;%p1%s;%p2%s\\007" + ":Cc=\\E]12;%p1%s\\007:Cr=\\E]112\\007" }, { .name = "update-environment", .type = OPTIONS_TABLE_STRING, .default_str = "DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID " - "SSH_CONNECTION WINDOWID XAUTHORITY" + "SSH_CONNECTION WINDOWID XAUTHORITY" }, diff --git a/screen.c b/screen.c index 292a5f03..07e0c33b 100644 --- a/screen.c +++ b/screen.c @@ -1,4 +1,4 @@ -/* $Id: screen.c,v 1.104 2011-05-05 10:10:57 tcunha Exp $ */ +/* $Id: screen.c,v 1.105 2011-05-22 16:25:02 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -41,6 +41,7 @@ screen_init(struct screen *s, u_int sx, u_int sy, u_int hlimit) else s->title = xstrdup(""); + s->ccolour = xstrdup(""); s->tabs = NULL; screen_reinit(s); @@ -72,6 +73,7 @@ screen_free(struct screen *s) if (s->tabs != NULL) xfree(s->tabs); xfree(s->title); + xfree(s->ccolour); grid_destroy(s->grid); } @@ -90,6 +92,14 @@ screen_reset_tabs(struct screen *s) bit_set(s->tabs, i); } +/* Set screen cursor colour. */ +void +screen_set_cursor_colour(struct screen *s, const char *colour_string) +{ + xfree(s->ccolour); + s->ccolour = xstrdup(colour_string); +} + /* Set screen title. */ void screen_set_title(struct screen *s, const char *title) diff --git a/server-client.c b/server-client.c index ea3cb47d..805b1ca7 100644 --- a/server-client.c +++ b/server-client.c @@ -1,4 +1,4 @@ -/* $Id: server-client.c,v 1.61 2011-05-18 20:31:32 tcunha Exp $ */ +/* $Id: server-client.c,v 1.62 2011-05-22 16:25:02 tcunha Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -520,7 +520,7 @@ server_client_reset_state(struct client *c) mode &= ~MODE_MOUSE_UTF8; /* Set the terminal mode and reset attributes. */ - tty_update_mode(&c->tty, mode); + tty_update_mode(&c->tty, mode, s); tty_reset(&c->tty); } diff --git a/tmux.1 b/tmux.1 index e3fa54f2..b4f51cb7 100644 --- a/tmux.1 +++ b/tmux.1 @@ -1,4 +1,4 @@ -.\" $Id: tmux.1,v 1.314 2011-05-22 16:23:07 tcunha Exp $ +.\" $Id: tmux.1,v 1.315 2011-05-22 16:25:02 tcunha Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott .\" @@ -14,7 +14,7 @@ .\" 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: May 18 2011 $ +.Dd $Mdocdate: May 20 2011 $ .Dt TMUX 1 .Os .Sh NAME @@ -2836,6 +2836,15 @@ See the option above and the .Xr xterm 1 man page. +.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. +If they present, a sequence such as this may be used to change the +cursor colour from inside +.Nm : +.Bd -literal -offset indent +$ printf '\e033]12;red\e033\e\e' +.Ed .El .Sh FILES .Bl -tag -width "/etc/tmux.confXXX" -compact diff --git a/tmux.h b/tmux.h index 4d0bb878..249881d5 100644 --- a/tmux.h +++ b/tmux.h @@ -1,4 +1,4 @@ -/* $Id: tmux.h,v 1.625 2011-05-22 16:23:07 tcunha Exp $ */ +/* $Id: tmux.h,v 1.626 2011-05-22 16:25:02 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -179,10 +179,12 @@ enum tty_code_code { TTYC_BEL, /* bell, bl */ TTYC_BLINK, /* enter_blink_mode, mb */ TTYC_BOLD, /* enter_bold_mode, md */ + TTYC_CC, /* set colour cursor, Cc */ TTYC_CIVIS, /* cursor_invisible, vi */ TTYC_CLEAR, /* clear_screen, cl */ TTYC_CNORM, /* cursor_normal, ve */ TTYC_COLORS, /* max_colors, Co */ + TTYC_CR, /* restore cursor colour, Cr */ TTYC_CSR, /* change_scroll_region, cs */ TTYC_CUB, /* parm_left_cursor, LE */ TTYC_CUB1, /* cursor_left, le */ @@ -710,6 +712,8 @@ struct screen { u_int cx; /* cursor x */ u_int cy; /* cursor y */ + char *ccolour; /* cursor colour string */ + u_int rupper; /* scroll region top */ u_int rlower; /* scroll region bottom */ @@ -1006,6 +1010,7 @@ struct tty { u_int cx; u_int cy; + char *ccolour; int mode; @@ -1410,6 +1415,7 @@ void tty_cursor(struct tty *, u_int, u_int); void tty_putcode(struct tty *, enum tty_code_code); void tty_putcode1(struct tty *, enum tty_code_code, int); void tty_putcode2(struct tty *, enum tty_code_code, int, int); +void tty_putcode_ptr1(struct tty *, enum tty_code_code, const void *); void tty_putcode_ptr2(struct tty *, enum tty_code_code, const void *, const void *); void tty_puts(struct tty *, const char *); void tty_putc(struct tty *, u_char); @@ -1419,7 +1425,8 @@ int tty_resize(struct tty *); void tty_start_tty(struct tty *); void tty_stop_tty(struct tty *); void tty_set_title(struct tty *, const char *); -void tty_update_mode(struct tty *, int); +void tty_update_mode(struct tty *, int, struct screen *); +void tty_force_cursor_colour(struct tty *, const char *); void tty_draw_line(struct tty *, struct screen *, u_int, u_int, u_int); int tty_open(struct tty *, const char *, char **); void tty_close(struct tty *); @@ -1455,6 +1462,8 @@ const char *tty_term_string(struct tty_term *, enum tty_code_code); const char *tty_term_string1(struct tty_term *, enum tty_code_code, int); const char *tty_term_string2( struct tty_term *, enum tty_code_code, int, int); +const char *tty_term_ptr1( + struct tty_term *, enum tty_code_code, const void *); const char *tty_term_ptr2( struct tty_term *, enum tty_code_code, const void *, const void *); int tty_term_number(struct tty_term *, enum tty_code_code); @@ -1837,6 +1846,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_colour(struct screen *, const char *); void screen_set_title(struct screen *, const char *); void screen_resize(struct screen *, u_int, u_int); void screen_set_selection(struct screen *, diff --git a/tty-term.c b/tty-term.c index f987ab34..0d594076 100644 --- a/tty-term.c +++ b/tty-term.c @@ -1,4 +1,4 @@ -/* $Id: tty-term.c,v 1.49 2011-05-22 16:23:07 tcunha Exp $ */ +/* $Id: tty-term.c,v 1.50 2011-05-22 16:25:02 tcunha Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott @@ -41,10 +41,12 @@ const struct tty_term_code_entry tty_term_codes[NTTYCODE] = { { TTYC_BEL, TTYCODE_STRING, "bel" }, { TTYC_BLINK, TTYCODE_STRING, "blink" }, { TTYC_BOLD, TTYCODE_STRING, "bold" }, + { TTYC_CC, TTYCODE_STRING, "Cc" }, { TTYC_CIVIS, TTYCODE_STRING, "civis" }, { TTYC_CLEAR, TTYCODE_STRING, "clear" }, { TTYC_CNORM, TTYCODE_STRING, "cnorm" }, { TTYC_COLORS, TTYCODE_NUMBER, "colors" }, + { TTYC_CR, TTYCODE_STRING, "Cr" }, { TTYC_CSR, TTYCODE_STRING, "csr" }, { TTYC_CUB, TTYCODE_STRING, "cub" }, { TTYC_CUB1, TTYCODE_STRING, "cub1" }, @@ -498,6 +500,12 @@ tty_term_string2(struct tty_term *term, enum tty_code_code code, int a, int b) return (tparm((char *) tty_term_string(term, code), a, b)); } +const char * +tty_term_ptr1(struct tty_term *term, enum tty_code_code code, const void *a) +{ + return (tparm((char *) tty_term_string(term, code), a)); +} + const char * tty_term_ptr2(struct tty_term *term, enum tty_code_code code, const void *a, const void *b) { diff --git a/tty.c b/tty.c index 021e8a25..7464c337 100644 --- a/tty.c +++ b/tty.c @@ -1,4 +1,4 @@ -/* $Id: tty.c,v 1.210 2011-05-22 16:23:07 tcunha Exp $ */ +/* $Id: tty.c,v 1.211 2011-05-22 16:25:02 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -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->ccolour = xstrdup(""); tty->flags = 0; tty->term_flags = 0; @@ -210,6 +211,8 @@ tty_start_tty(struct tty *tty) tty->mode = MODE_CURSOR; tty->flags |= TTY_STARTED; + + tty_force_cursor_colour(tty, ""); } void @@ -241,6 +244,7 @@ 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)); + tty_raw(tty, tty_term_string(tty->term, TTYC_CR)); tty_raw(tty, tty_term_string(tty->term, TTYC_CNORM)); if (tty_term_has(tty->term, TTYC_KMOUS)) @@ -280,6 +284,7 @@ tty_free(struct tty *tty) { tty_close(tty); + xfree(tty->ccolour); if (tty->path != NULL) xfree(tty->path); if (tty->termname != NULL) @@ -314,6 +319,13 @@ tty_putcode2(struct tty *tty, enum tty_code_code code, int a, int b) tty_puts(tty, tty_term_string2(tty->term, code, a, b)); } +void +tty_putcode_ptr1(struct tty *tty, enum tty_code_code code, const void *a) +{ + if (a != NULL) + tty_puts(tty, tty_term_ptr1(tty->term, code, a)); +} + void tty_putcode_ptr2(struct tty *tty, enum tty_code_code code, const void *a, const void *b) { @@ -389,10 +401,24 @@ tty_set_title(struct tty *tty, const char *title) } void -tty_update_mode(struct tty *tty, int mode) +tty_force_cursor_colour(struct tty *tty, const char *ccolour) +{ + if (*ccolour == '\0') + tty_putcode(tty, TTYC_CR); + else + tty_putcode_ptr1(tty, TTYC_CC, ccolour); + xfree(tty->ccolour); + tty->ccolour = xstrdup(ccolour); +} + +void +tty_update_mode(struct tty *tty, int mode, struct screen *s) { int changed; + if (strcmp(s->ccolour, tty->ccolour)) + tty_force_cursor_colour(tty, s->ccolour); + if (tty->flags & TTY_NOCURSOR) mode &= ~MODE_CURSOR; @@ -486,7 +512,7 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int py, u_int ox, u_int oy) const struct grid_utf8 *gu; u_int i, sx; - tty_update_mode(tty, tty->mode & ~MODE_CURSOR); + tty_update_mode(tty, tty->mode & ~MODE_CURSOR, s); sx = screen_size_x(s); if (sx > s->grid->linedata[s->grid->hsize + py].cellsize) @@ -526,7 +552,7 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int py, u_int ox, u_int oy) } if (sx >= tty->sx) { - tty_update_mode(tty, tty->mode); + tty_update_mode(tty, tty->mode, s); return; } tty_reset(tty); @@ -538,7 +564,7 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int py, u_int ox, u_int oy) for (i = sx; i < screen_size_x(s); i++) tty_putc(tty, ' '); } - tty_update_mode(tty, tty->mode); + tty_update_mode(tty, tty->mode, s); } void