Hi I was just about to apply this slightly tweaked diff (sorry for the delay) when I noticed that when I change the cursor colour in a window it appears to make moving to the window visible redraw the screen much more slowly than for other windows.
Do you see this as well? Is this a bug or an artifact of xterm? Index: input.c =================================================================== RCS file: /cvs/src/usr.bin/tmux/input.c,v retrieving revision 1.37 diff -u -p -r1.37 input.c --- input.c 7 Mar 2011 23:46:27 -0000 1.37 +++ input.c 24 Apr 2011 21:26:12 -0000 @@ -1445,17 +1445,36 @@ input_enter_osc(struct input_ctx *ictx) void input_exit_osc(struct input_ctx *ictx) { - if (ictx->flags & INPUT_DISCARD) - return; - log_debug("%s: \"%s\"", __func__, ictx->input_buf); + u_char *p = ictx->input_buf; + int option; - if (ictx->input_len < 2 || ictx->input_buf[1] != ';') + if (ictx->flags & INPUT_DISCARD) 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: + case 112: + screen_set_cursor_colour(ictx->ctx.s, p); + break; + default: + log_debug("%s: unknown '%u'", __func__, option); + break; + } } /* APC string started. */ Index: screen.c =================================================================== RCS file: /cvs/src/usr.bin/tmux/screen.c,v retrieving revision 1.17 diff -u -p -r1.17 screen.c --- screen.c 11 Dec 2010 17:56:01 -0000 1.17 +++ screen.c 24 Apr 2011 21:26:13 -0000 @@ -41,6 +41,7 @@ screen_init(struct screen *s, u_int sx, 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); } @@ -88,6 +90,14 @@ screen_reset_tabs(struct screen *s) fatal("bit_alloc failed"); for (i = 8; i < screen_size_x(s); i += 8) 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. */ Index: server-client.c =================================================================== RCS file: /cvs/src/usr.bin/tmux/server-client.c,v retrieving revision 1.54 diff -u -p -r1.54 server-client.c --- server-client.c 19 Apr 2011 21:31:33 -0000 1.54 +++ server-client.c 24 Apr 2011 21:26:13 -0000 @@ -491,7 +491,7 @@ server_client_reset_state(struct client mode &= ~MODE_MOUSE_UTF8; /* Set the terminal mode and reset attributes. */ - tty_update_mode(&c->tty, mode); + tty_update_mode(&c->tty, mode, s->ccolour); tty_reset(&c->tty); } Index: tmux.1 =================================================================== RCS file: /cvs/src/usr.bin/tmux/tmux.1,v retrieving revision 1.223 diff -u -p -r1.223 tmux.1 --- tmux.1 19 Apr 2011 21:31:33 -0000 1.223 +++ tmux.1 24 Apr 2011 21:26:15 -0000 @@ -2789,6 +2789,28 @@ If the command doesn't return success, t .D1 (alias: Ic info ) Show server information and terminal details. .El +.Sh TERMINFO EXTENSIONS +.Nm +understands two extensions to +.Xr terminfo 5 : +.Em tmuxscc +and +.Em tmuxecc . +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 these are not set and +.Ev TERM +includes the string "xterm", they are filled in with appropriate values for +.Xr xterm 1 +and compatible terminals. +If +.Em tmuxscc +and +.Em tmuxecc +are present, a sequence such as this may be used to change the cursor colour: +.Bd -literal -offset indent +$ printf '\e033]112;red\e033\e\e' +.Ed .Sh FILES .Bl -tag -width "/etc/tmux.confXXX" -compact .It Pa ~/.tmux.conf Index: tmux.h =================================================================== RCS file: /cvs/src/usr.bin/tmux/tmux.h,v retrieving revision 1.282 diff -u -p -r1.282 tmux.h --- tmux.h 19 Apr 2011 21:31:33 -0000 1.282 +++ tmux.h 24 Apr 2011 21:26:15 -0000 @@ -326,8 +326,10 @@ enum tty_code_code { TTYC_SITM, /* enter_italics_mode, it */ TTYC_VPA, /* row_address, cv */ TTYC_XENL, /* eat_newline_glitch, xn */ + TTYC_TMUX_SCC, /* start colour cursor, tmuxscc */ + TTYC_TMUX_ECC, /* end colour coursor, tmuxecc */ }; -#define NTTYCODE (TTYC_XENL + 1) +#define NTTYCODE (TTYC_TMUX_ECC + 1) /* Termcap types. */ enum tty_code_type { @@ -706,6 +708,7 @@ 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 */ @@ -1003,6 +1006,7 @@ struct tty { u_int cx; u_int cy; + char * ccolour; int mode; @@ -1404,6 +1408,7 @@ void tty_cursor(struct tty *, u_int, u_i 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_puts(struct tty *, const char *); void tty_putc(struct tty *, u_char); void tty_pututf8(struct tty *, const struct grid_utf8 *); @@ -1412,7 +1417,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, const char *); +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 *); @@ -1447,6 +1453,8 @@ const char *tty_term_string(struct tty_t 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 *); int tty_term_number(struct tty_term *, enum tty_code_code); int tty_term_flag(struct tty_term *, enum tty_code_code); @@ -1826,6 +1834,7 @@ void screen_init(struct screen *, 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 *, Index: tty-term.c =================================================================== RCS file: /cvs/src/usr.bin/tmux/tty-term.c,v retrieving revision 1.21 diff -u -p -r1.21 tty-term.c --- tty-term.c 9 Apr 2011 07:48:08 -0000 1.21 +++ tty-term.c 24 Apr 2011 21:26:16 -0000 @@ -181,6 +181,8 @@ const struct tty_term_code_entry tty_ter { TTYC_SITM, TTYCODE_STRING, "sitm" }, { TTYC_VPA, TTYCODE_STRING, "vpa" }, { TTYC_XENL, TTYCODE_FLAG, "xenl" }, + { TTYC_TMUX_SCC, TTYCODE_STRING, "tmuxscc" }, + { TTYC_TMUX_ECC, TTYCODE_STRING, "tmuxecc" }, }; char * @@ -374,6 +376,18 @@ tty_term_find(char *name, int fd, const break; } } + + /* Fill in custom tmux strings and apply overrides. */ + if ((!tty_term_has(term, TTYC_TMUX_SCC) || + !tty_term_has(term, TTYC_TMUX_ECC)) && + strstr(term->name, "xterm") != NULL) { + code = &term->codes[TTYC_TMUX_ECC]; + code->value.string = xstrdup("\033]112\007"); + code->type = TTYCODE_STRING; + code = &term->codes[TTYC_TMUX_SCC]; + code->value.string = xstrdup("\033]12;%p1%s\007"); + code->type = TTYCODE_STRING; + } tty_term_override(term, overrides); /* Delete curses data. */ @@ -475,6 +489,12 @@ const char * 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)); } int Index: tty.c =================================================================== RCS file: /cvs/src/usr.bin/tmux/tty.c,v retrieving revision 1.104 diff -u -p -r1.104 tty.c --- tty.c 9 Apr 2011 07:48:08 -0000 1.104 +++ tty.c 24 Apr 2011 21:26:16 -0000 @@ -66,6 +66,7 @@ tty_init(struct tty *tty, int fd, char * if ((path = ttyname(fd)) == NULL) fatalx("ttyname failed"); tty->path = xstrdup(path); + tty->ccolour = xstrdup(""); tty->flags = 0; tty->term_flags = 0; @@ -207,6 +208,8 @@ tty_start_tty(struct tty *tty) tty->mode = MODE_CURSOR; tty->flags |= TTY_STARTED; + + tty_force_cursor_colour(tty, ""); } void @@ -238,6 +241,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_TMUX_ECC)); tty_raw(tty, tty_term_string(tty->term, TTYC_CNORM)); if (tty_term_has(tty->term, TTYC_KMOUS)) @@ -277,6 +281,7 @@ tty_free(struct tty *tty) { tty_close(tty); + xfree(tty->ccolour); if (tty->path != NULL) xfree(tty->path); if (tty->termname != NULL) @@ -312,6 +317,13 @@ tty_putcode2(struct tty *tty, enum tty_c } 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_puts(struct tty *tty, const char *s) { if (*s == '\0') @@ -380,10 +392,24 @@ tty_set_title(struct tty *tty, const cha } 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_TMUX_ECC); + else + tty_putcode_ptr1(tty, TTYC_TMUX_SCC, ccolour); + xfree(tty->ccolour); + tty->ccolour = xstrdup(ccolour); +} + +void +tty_update_mode(struct tty *tty, int mode, const char *ccolour) { int changed; + if (strcmp(ccolour, tty->ccolour)) + tty_force_cursor_colour(tty, ccolour); + if (tty->flags & TTY_NOCURSOR) mode &= ~MODE_CURSOR; @@ -477,7 +503,7 @@ tty_draw_line(struct tty *tty, struct sc 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->ccolour); sx = screen_size_x(s); if (sx > s->grid->linedata[s->grid->hsize + py].cellsize) @@ -517,7 +543,7 @@ tty_draw_line(struct tty *tty, struct sc } if (sx >= tty->sx) { - tty_update_mode(tty, tty->mode); + tty_update_mode(tty, tty->mode, s->ccolour); return; } tty_reset(tty); @@ -529,7 +555,7 @@ tty_draw_line(struct tty *tty, struct sc 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->ccolour); } void ------------------------------------------------------------------------------ Fulfilling the Lean Software Promise Lean software platforms are now widely adopted and the benefits have been demonstrated beyond question. Learn why your peers are replacing JEE containers with lightweight application servers - and what you can gain from the move. http://p.sf.net/sfu/vmware-sfemails _______________________________________________ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users