From 944b5e6fa04e014501f465e3898315c84d10bd9e Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Fri, 20 May 2011 19:03:58 +0000 Subject: Support xterm(1) cursor colour change sequences through terminfo(5) Cc (set) and Cr (reset) extensions. Originally by Sean Estabrooks, tweaked by me and Ailin Nemui. --- tty.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'tty.c') diff --git a/tty.c b/tty.c index 04503b60..5f3ada8e 100644 --- a/tty.c +++ b/tty.c @@ -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 -- cgit v1.2.3