The branch, jr/pane-colours has been created
        at  f0bc364b2ac9701a0708c4fe30bdd80ae4bde063 (commit)

- Log -----------------------------------------------------------------
commit f0bc364b2ac9701a0708c4fe30bdd80ae4bde063
Author: Thomas Adam <tho...@xteddy.org>
Commit: Thomas Adam <tho...@xteddy.org>

    REVIEW:  Pane colours
---
 cmd-display-panes.c |  116 ++++++++++++++++++++++++++++++++++++++
 cmd.c               |    1 +
 colour.c            |   13 ++++
 screen-redraw.c     |   10 ++-
 tmux.h              |   12 ++++-
 tty.c               |  155 +++++++++++++++++++++++++++++++++++++++++++++++----
 window.c            |    8 +++
 7 files changed, 298 insertions(+), 17 deletions(-)

diff --git a/cmd-display-panes.c b/cmd-display-panes.c
index 9ce8971..054447d 100644
--- a/cmd-display-panes.c
+++ b/cmd-display-panes.c
@@ -18,14 +18,28 @@
 
 #include <sys/types.h>
 
+#include <stdlib.h>
+#include <string.h>
+
 #include "tmux.h"
 
 /*
  * Display panes on a client.
+ *
+ * Set or get pane default fg/bg colours.
  */
 
+enum cmd_retval         cmd_colour_pane_exec(struct cmd *, struct cmd_q *);
 enum cmd_retval         cmd_display_panes_exec(struct cmd *, struct cmd_q *);
 
+const struct cmd_entry cmd_colour_pane_entry = {
+       "colour-pane", "colourp",
+       "gt:APW", 0, 1,
+       CMD_TARGET_PANE_USAGE " [-A|P|W] colour-style",
+       0,
+       cmd_colour_pane_exec
+};
+
 const struct cmd_entry cmd_display_panes_entry = {
        "display-panes", "displayp",
        "t:", 0, 0,
@@ -47,3 +61,105 @@ cmd_display_panes_exec(struct cmd *self, struct cmd_q *cmdq)
 
        return (CMD_RETURN_NORMAL);
 }
+
+enum cmd_retval
+cmd_colour_pane_exec(struct cmd *self, struct cmd_q *cmdq)
+{
+       struct args             *args = self->args;
+       struct session          *s;
+       struct winlink          *wl;
+       struct window_pane      *wp;
+       int                      ret, nflags = 0;
+       struct grid_cell         *gc;
+       const char               *str;
+
+
+
+       if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp)) == NULL)
+               return (CMD_RETURN_ERROR);
+
+       if (args_has(args, 'g')) nflags++;
+       if (args_has(args, 'A')) nflags++;
+       if (args_has(args, 'P')) nflags++;
+       if (args_has(args, 'W')) nflags++;
+
+       if (nflags == 0 || nflags > 1) {
+               cmdq_error(cmdq, "need exactly 1 of -g, -A, -P, or -W");
+               return (CMD_RETURN_ERROR);
+       }
+
+       if (args_has(args, 'g')) {
+               if (args->argc > 0) {
+                       cmdq_error(cmdq, "don't specify style with -g");
+                       return (CMD_RETURN_ERROR);
+               }
+
+               gc = wp->window->apcolgc;
+               if (gc == NULL)
+                       str = "\"\"";
+               else
+                       str = style_tostring(gc);
+               cmdq_print(cmdq, "active-pane %s", str);
+
+
+               gc = wp->colgc;
+               if (gc == NULL)
+                       str = "\"\"";
+               else
+                       str = style_tostring(gc);
+               cmdq_print(cmdq, "pane %s", str);
+
+
+               gc = wp->window->colgc;
+               if (gc == NULL)
+                       str = "\"\"";
+               else
+                       str = style_tostring(gc);
+               cmdq_print(cmdq, "window %s", str);
+
+               return (CMD_RETURN_NORMAL);
+       }
+
+       if (args->argc == 0) {
+               cmdq_error(cmdq, "need a style argument");
+               return (CMD_RETURN_ERROR);
+       }
+
+       str = args->argv[0];
+       if (*str == '\0')
+               gc = NULL;
+       else {
+               gc = xmalloc(sizeof *gc);
+               memcpy(gc, &grid_default_cell, sizeof *gc);
+               ret = style_parse(&grid_default_cell, gc, str);
+
+               if (ret == -1) {
+                       free(gc);
+                       cmdq_error(cmdq, "bad colour style");
+                       return (CMD_RETURN_ERROR);
+               }
+       }
+
+       if (args_has(args, 'A')) {
+               free(wp->window->apcolgc);
+               wp->window->apcolgc = gc;
+               server_redraw_window(wp->window);
+               return (CMD_RETURN_NORMAL);
+       }
+
+       if (args_has(args, 'P')) {
+               free(wp->colgc);
+               wp->colgc = gc;
+               wp->flags |= PANE_REDRAW;
+               return (CMD_RETURN_NORMAL);
+       }
+
+       if (args_has(args, 'W')) {
+               free(wp->window->colgc);
+               wp->window->colgc = gc;
+               server_redraw_window(wp->window);
+               return (CMD_RETURN_NORMAL);
+       }
+
+       return (CMD_RETURN_NORMAL);
+}
diff --git a/cmd.c b/cmd.c
index eeffe4c..e54b23e 100644
--- a/cmd.c
+++ b/cmd.c
@@ -39,6 +39,7 @@ const struct cmd_entry *cmd_table[] = {
        &cmd_choose_window_entry,
        &cmd_clear_history_entry,
        &cmd_clock_mode_entry,
+       &cmd_colour_pane_entry,
        &cmd_command_prompt_entry,
        &cmd_confirm_before_entry,
        &cmd_copy_mode_entry,
diff --git a/colour.c b/colour.c
index 9e90596..eeb6625 100644
--- a/colour.c
+++ b/colour.c
@@ -287,3 +287,16 @@ colour_256to16(u_char c)
 
        return (table[c]);
 }
+
+const struct grid_cell *
+get_wp_default_grid_colours(const struct window_pane *wp)
+{
+       if (wp->colgc != NULL)
+               return (wp->colgc);
+
+       if (wp == wp->window->active && wp->window->apcolgc != NULL)
+               return (wp->window->apcolgc);
+
+
+       return (wp->window->colgc);
+}
diff --git a/screen-redraw.c b/screen-redraw.c
index c2b2ece..4a780f6 100644
--- a/screen-redraw.c
+++ b/screen-redraw.c
@@ -266,7 +266,8 @@ screen_redraw_pane(struct client *c, struct window_pane *wp)
                yoff++;
 
        for (i = 0; i < wp->sy; i++)
-               tty_draw_line(&c->tty, wp->screen, i, wp->xoff, yoff);
+               tty_draw_line(&c->tty, wp->screen, i, wp->xoff, yoff,
+                   get_wp_default_grid_colours(wp));
        tty_reset(&c->tty);
 }
 
@@ -354,7 +355,8 @@ screen_redraw_draw_panes(struct client *c, u_int top)
                        continue;
                s = wp->screen;
                for (i = 0; i < wp->sy; i++)
-                       tty_draw_line(tty, s, i, wp->xoff, top + wp->yoff);
+                       tty_draw_line(tty, s, i, wp->xoff, top + wp->yoff,
+                           get_wp_default_grid_colours(wp));
                if (c->flags & CLIENT_IDENTIFY)
                        screen_redraw_draw_number(c, wp);
        }
@@ -367,9 +369,9 @@ screen_redraw_draw_status(struct client *c, u_int top)
        struct tty      *tty = &c->tty;
 
        if (top)
-               tty_draw_line(tty, &c->status, 0, 0, 0);
+               tty_draw_line(tty, &c->status, 0, 0, 0, NULL);
        else
-               tty_draw_line(tty, &c->status, 0, 0, tty->sy - 1);
+               tty_draw_line(tty, &c->status, 0, 0, tty->sy - 1, NULL);
 }
 
 /* Draw number on a pane. */
diff --git a/tmux.h b/tmux.h
index e296ac7..28a1b62 100644
--- a/tmux.h
+++ b/tmux.h
@@ -900,6 +900,9 @@ struct window_pane {
 
        struct input_ctx ictx;
 
+       /* Default fg/bg grid cell colours */
+       struct grid_cell *colgc;
+
        int              pipe_fd;
        struct bufferevent *pipe_event;
        size_t           pipe_off;
@@ -953,6 +956,10 @@ struct window {
 
        struct options   options;
 
+       /* Default fg/bg grid cell colours for window and active pane */
+       struct grid_cell *colgc;
+       struct grid_cell *apcolgc;
+
        u_int            references;
 };
 ARRAY_DECL(windows, struct window *);
@@ -1628,7 +1635,8 @@ void      tty_stop_tty(struct tty *);
 void   tty_set_title(struct tty *, const char *);
 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);
+void   tty_draw_line(struct tty *, struct screen *, u_int, u_int, u_int,
+           const struct grid_cell *);
 int    tty_open(struct tty *, char **);
 void   tty_close(struct tty *);
 void   tty_free(struct tty *);
@@ -1739,6 +1747,7 @@ extern const struct cmd_entry cmd_choose_tree_entry;
 extern const struct cmd_entry cmd_choose_window_entry;
 extern const struct cmd_entry cmd_clear_history_entry;
 extern const struct cmd_entry cmd_clock_mode_entry;
+extern const struct cmd_entry cmd_colour_pane_entry;
 extern const struct cmd_entry cmd_command_prompt_entry;
 extern const struct cmd_entry cmd_confirm_before_entry;
 extern const struct cmd_entry cmd_copy_mode_entry;
@@ -1956,6 +1965,7 @@ void       colour_set_bg(struct grid_cell *, int);
 const char *colour_tostring(int);
 int     colour_fromstring(const char *);
 u_char  colour_256to16(u_char);
+const struct grid_cell *get_wp_default_grid_colours(const struct window_pane 
*);
 
 /* attributes.c */
 const char *attributes_tostring(u_char);
diff --git a/tty.c b/tty.c
index 1bb8981..ffc25e2 100644
--- a/tty.c
+++ b/tty.c
@@ -604,22 +604,26 @@ tty_redraw_region(struct tty *tty, const struct tty_ctx 
*ctx)
 
        if (ctx->ocy < ctx->orupper || ctx->ocy > ctx->orlower) {
                for (i = ctx->ocy; i < screen_size_y(s); i++)
-                       tty_draw_line(tty, s, i, ctx->xoff, ctx->yoff);
+                       tty_draw_line(tty, s, i, ctx->xoff, ctx->yoff,
+                           get_wp_default_grid_colours(wp));
        } else {
                for (i = ctx->orupper; i <= ctx->orlower; i++)
-                       tty_draw_line(tty, s, i, ctx->xoff, ctx->yoff);
+                       tty_draw_line(tty, s, i, ctx->xoff, ctx->yoff,
+                           get_wp_default_grid_colours(wp));
        }
 }
 
 void
-tty_draw_line(struct tty *tty, struct screen *s, u_int py, u_int ox, u_int oy)
+tty_draw_line(struct tty *tty, struct screen *s, u_int py, u_int ox, u_int oy,
+    const struct grid_cell *colgc)
 {
        const struct grid_cell  *gc;
        struct grid_line        *gl;
-       struct grid_cell         tmpgc;
+       struct grid_cell         tmpgc, colourgc;
        struct utf8_data         ud;
        u_int                    i, sx;
 
+
        tty_update_mode(tty, tty->mode & ~MODE_CURSOR, s);
 
        sx = screen_size_x(s);
@@ -628,6 +632,7 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int py, 
u_int ox, u_int oy)
        if (sx > tty->sx)
                sx = tty->sx;
 
+
        /*
         * Don't move the cursor to the start permission if it will wrap there
         * itself.
@@ -642,17 +647,28 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int 
py, u_int ox, u_int oy)
 
        for (i = 0; i < sx; i++) {
                gc = grid_view_peek_cell(s->grid, i, py);
+               memcpy(&colourgc, gc, sizeof *gc);
+               if (colgc != NULL && colourgc.fg == 8) {
+                       colourgc.fg = colgc->fg;
+                       colourgc.flags &= ~GRID_FLAG_FG256;
+                       colourgc.flags |= (colgc->flags & GRID_FLAG_FG256);
+               }
+               if (colgc != NULL && colourgc.bg == 8) {
+                       colourgc.bg = colgc->bg;
+                       colourgc.flags &= ~GRID_FLAG_BG256;
+                       colourgc.flags |= (colgc->flags & GRID_FLAG_BG256);
+               }
                if (screen_check_selection(s, i, py)) {
                        memcpy(&tmpgc, &s->sel.cell, sizeof tmpgc);
-                       grid_cell_get(gc, &ud);
+                       grid_cell_get(&colourgc, &ud);
                        grid_cell_set(&tmpgc, &ud);
-                       tmpgc.flags = gc->flags &
+                       tmpgc.flags = colourgc.flags &
                            ~(GRID_FLAG_FG256|GRID_FLAG_BG256);
                        tmpgc.flags |= s->sel.cell.flags &
                            (GRID_FLAG_FG256|GRID_FLAG_BG256);
                        tty_cell(tty, &tmpgc);
                } else
-                       tty_cell(tty, gc);
+                       tty_cell(tty, &colourgc);
        }
 
        if (sx >= tty->sx) {
@@ -660,6 +676,9 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int py, 
u_int ox, u_int oy)
                return;
        }
        tty_reset(tty);
+       if (colgc != NULL && colgc->bg != 8)
+               tty_colours(tty, colgc);
+
 
        tty_cursor(tty, ox + sx, oy + py);
        if (sx != screen_size_x(s) && ox + screen_size_x(s) >= tty->sx &&
@@ -668,6 +687,7 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int py, 
u_int ox, u_int oy)
        else
                tty_repeat_space(tty, screen_size_x(s) - sx);
        tty_update_mode(tty, tty->mode, s);
+
 }
 
 void
@@ -711,13 +731,19 @@ void
 tty_cmd_insertcharacter(struct tty *tty, const struct tty_ctx *ctx)
 {
        struct window_pane      *wp = ctx->wp;
+       const struct grid_cell  *colgc;
+
+       colgc = get_wp_default_grid_colours(wp);
 
        if (!tty_pane_full_width(tty, ctx)) {
-               tty_draw_line(tty, wp->screen, ctx->ocy, ctx->xoff, ctx->yoff);
+               tty_draw_line(tty, wp->screen, ctx->ocy, ctx->xoff, ctx->yoff,
+                   colgc);
                return;
        }
 
        tty_reset(tty);
+       if (colgc != NULL)
+               tty_colours(tty, colgc);
 
        tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
 
@@ -725,22 +751,29 @@ tty_cmd_insertcharacter(struct tty *tty, const struct 
tty_ctx *ctx)
            tty_term_has(tty->term, TTYC_ICH1))
                tty_emulate_repeat(tty, TTYC_ICH, TTYC_ICH1, ctx->num);
        else
-               tty_draw_line(tty, wp->screen, ctx->ocy, ctx->xoff, ctx->yoff);
+               tty_draw_line(tty, wp->screen, ctx->ocy, ctx->xoff, ctx->yoff,
+                   get_wp_default_grid_colours(wp));
 }
 
 void
 tty_cmd_deletecharacter(struct tty *tty, const struct tty_ctx *ctx)
 {
        struct window_pane      *wp = ctx->wp;
+       const struct grid_cell  *colgc;
+
+       colgc = get_wp_default_grid_colours(wp);
 
        if (!tty_pane_full_width(tty, ctx) ||
            (!tty_term_has(tty->term, TTYC_DCH) &&
            !tty_term_has(tty->term, TTYC_DCH1))) {
-               tty_draw_line(tty, wp->screen, ctx->ocy, ctx->xoff, ctx->yoff);
+               tty_draw_line(tty, wp->screen, ctx->ocy, ctx->xoff, ctx->yoff,
+                   colgc);
                return;
        }
 
        tty_reset(tty);
+       if (colgc != NULL)
+               tty_colours(tty, colgc);
 
        tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
 
@@ -753,8 +786,14 @@ void
 tty_cmd_clearcharacter(struct tty *tty, const struct tty_ctx *ctx)
 {
        u_int   i;
+       struct window_pane      *wp = ctx->wp;
+       const struct grid_cell  *colgc;
+
+       colgc = get_wp_default_grid_colours(wp);
 
        tty_reset(tty);
+       if (colgc != NULL)
+               tty_colours(tty, colgc);
 
        tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
 
@@ -769,6 +808,11 @@ tty_cmd_clearcharacter(struct tty *tty, const struct 
tty_ctx *ctx)
 void
 tty_cmd_insertline(struct tty *tty, const struct tty_ctx *ctx)
 {
+       struct window_pane      *wp = ctx->wp;
+       const struct grid_cell  *colgc;
+
+       colgc = get_wp_default_grid_colours(wp);
+
        if (!tty_pane_full_width(tty, ctx) ||
            !tty_term_has(tty->term, TTYC_CSR) ||
            !tty_term_has(tty->term, TTYC_IL1)) {
@@ -777,6 +821,8 @@ tty_cmd_insertline(struct tty *tty, const struct tty_ctx 
*ctx)
        }
 
        tty_reset(tty);
+       if (colgc != NULL)
+               tty_colours(tty, colgc);
 
        tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower);
        tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
@@ -787,6 +833,11 @@ tty_cmd_insertline(struct tty *tty, const struct tty_ctx 
*ctx)
 void
 tty_cmd_deleteline(struct tty *tty, const struct tty_ctx *ctx)
 {
+       struct window_pane      *wp = ctx->wp;
+       const struct grid_cell  *colgc;
+
+       colgc = get_wp_default_grid_colours(wp);
+
        if (!tty_pane_full_width(tty, ctx) ||
            !tty_term_has(tty->term, TTYC_CSR) ||
            !tty_term_has(tty->term, TTYC_DL1)) {
@@ -795,6 +846,8 @@ tty_cmd_deleteline(struct tty *tty, const struct tty_ctx 
*ctx)
        }
 
        tty_reset(tty);
+       if (colgc != NULL)
+               tty_colours(tty, colgc);
 
        tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower);
        tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
@@ -807,8 +860,13 @@ tty_cmd_clearline(struct tty *tty, const struct tty_ctx 
*ctx)
 {
        struct window_pane      *wp = ctx->wp;
        struct screen           *s = wp->screen;
+       const struct grid_cell  *colgc;
+
+       colgc = get_wp_default_grid_colours(wp);
 
        tty_reset(tty);
+       if (colgc != NULL)
+               tty_colours(tty, colgc);
 
        tty_cursor_pane(tty, ctx, 0, ctx->ocy);
 
@@ -823,8 +881,13 @@ tty_cmd_clearendofline(struct tty *tty, const struct 
tty_ctx *ctx)
 {
        struct window_pane      *wp = ctx->wp;
        struct screen           *s = wp->screen;
+       const struct grid_cell  *colgc;
+
+       colgc = get_wp_default_grid_colours(wp);
 
        tty_reset(tty);
+       if (colgc != NULL)
+               tty_colours(tty, colgc);
 
        tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
 
@@ -837,7 +900,14 @@ tty_cmd_clearendofline(struct tty *tty, const struct 
tty_ctx *ctx)
 void
 tty_cmd_clearstartofline(struct tty *tty, const struct tty_ctx *ctx)
 {
+       struct window_pane      *wp = ctx->wp;
+       const struct grid_cell  *colgc;
+
+       colgc = get_wp_default_grid_colours(wp);
+
        tty_reset(tty);
+       if (colgc != NULL)
+               tty_colours(tty, colgc);
 
        if (ctx->xoff == 0 && tty_term_has(tty->term, TTYC_EL1)) {
                tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
@@ -851,6 +921,11 @@ tty_cmd_clearstartofline(struct tty *tty, const struct 
tty_ctx *ctx)
 void
 tty_cmd_reverseindex(struct tty *tty, const struct tty_ctx *ctx)
 {
+       struct window_pane      *wp = ctx->wp;
+       const struct grid_cell  *colgc;
+
+       colgc = get_wp_default_grid_colours(wp);
+
        if (ctx->ocy != ctx->orupper)
                return;
 
@@ -862,6 +937,8 @@ tty_cmd_reverseindex(struct tty *tty, const struct tty_ctx 
*ctx)
        }
 
        tty_reset(tty);
+       if (colgc != NULL)
+               tty_colours(tty, colgc);
 
        tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower);
        tty_cursor_pane(tty, ctx, ctx->ocx, ctx->orupper);
@@ -873,6 +950,9 @@ void
 tty_cmd_linefeed(struct tty *tty, const struct tty_ctx *ctx)
 {
        struct window_pane      *wp = ctx->wp;
+       const struct grid_cell  *colgc;
+
+       colgc = get_wp_default_grid_colours(wp);
 
        if (ctx->ocy != ctx->orlower)
                return;
@@ -895,6 +975,8 @@ tty_cmd_linefeed(struct tty *tty, const struct tty_ctx *ctx)
                return;
 
        tty_reset(tty);
+       if (colgc != NULL)
+               tty_colours(tty, colgc);
 
        tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower);
        tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
@@ -908,8 +990,13 @@ tty_cmd_clearendofscreen(struct tty *tty, const struct 
tty_ctx *ctx)
        struct window_pane      *wp = ctx->wp;
        struct screen           *s = wp->screen;
        u_int                    i, j;
+       const struct grid_cell  *colgc;
+
+       colgc = get_wp_default_grid_colours(wp);
 
        tty_reset(tty);
+       if (colgc != NULL)
+               tty_colours(tty, colgc);
 
        tty_region_pane(tty, ctx, 0, screen_size_y(s) - 1);
        tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
@@ -941,8 +1028,13 @@ tty_cmd_clearstartofscreen(struct tty *tty, const struct 
tty_ctx *ctx)
        struct window_pane      *wp = ctx->wp;
        struct screen           *s = wp->screen;
        u_int                    i, j;
+       const struct grid_cell  *colgc;
+
+       colgc = get_wp_default_grid_colours(wp);
 
        tty_reset(tty);
+       if (colgc != NULL)
+               tty_colours(tty, colgc);
 
        tty_region_pane(tty, ctx, 0, screen_size_y(s) - 1);
        tty_cursor_pane(tty, ctx, 0, 0);
@@ -968,8 +1060,13 @@ tty_cmd_clearscreen(struct tty *tty, const struct tty_ctx 
*ctx)
        struct window_pane      *wp = ctx->wp;
        struct screen           *s = wp->screen;
        u_int                    i, j;
+       const struct grid_cell  *colgc;
+
+       colgc = get_wp_default_grid_colours(wp);
 
        tty_reset(tty);
+       if (colgc != NULL)
+               tty_colours(tty, colgc);
 
        tty_region_pane(tty, ctx, 0, screen_size_y(s) - 1);
        tty_cursor_pane(tty, ctx, 0, 0);
@@ -996,8 +1093,13 @@ tty_cmd_alignmenttest(struct tty *tty, const struct 
tty_ctx *ctx)
        struct window_pane      *wp = ctx->wp;
        struct screen           *s = wp->screen;
        u_int                    i, j;
+       const struct grid_cell  *colgc;
+
+       colgc = get_wp_default_grid_colours(wp);
 
        tty_reset(tty);
+       if (colgc != NULL)
+               tty_colours(tty, colgc);
 
        tty_region_pane(tty, ctx, 0, screen_size_y(s) - 1);
 
@@ -1015,6 +1117,10 @@ tty_cmd_cell(struct tty *tty, const struct tty_ctx *ctx)
        struct screen           *s = wp->screen;
        u_int                    cx;
        u_int                    width;
+       struct grid_cell         tmpgc;
+       const struct grid_cell  *colgc;
+
+       colgc = get_wp_default_grid_colours(wp);
 
        tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower);
 
@@ -1043,19 +1149,37 @@ tty_cmd_cell(struct tty *tty, const struct tty_ctx *ctx)
        } else
                tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
 
-       tty_cell(tty, ctx->cell);
+
+       memcpy(&tmpgc, ctx->cell, sizeof tmpgc);
+       if (colgc != NULL) {
+               if (ctx->cell->fg == 8) {
+                       tmpgc.fg = colgc->fg;
+                       tmpgc.flags &= ~GRID_FLAG_FG256;
+                       tmpgc.flags |= (colgc->flags & GRID_FLAG_FG256);
+               }
+               if (ctx->cell->bg == 8) {
+                       tmpgc.bg = colgc->bg;
+                       tmpgc.flags &= ~GRID_FLAG_BG256;
+                       tmpgc.flags |= (colgc->flags & GRID_FLAG_BG256);
+               }
+       }
+
+       tty_cell(tty, &tmpgc);
 }
 
 void
 tty_cmd_utf8character(struct tty *tty, const struct tty_ctx *ctx)
 {
        struct window_pane      *wp = ctx->wp;
+       const struct grid_cell  *colgc;
+
+       colgc = get_wp_default_grid_colours(wp);
 
        /*
         * Cannot rely on not being a partial character, so just redraw the
         * whole line.
         */
-       tty_draw_line(tty, wp->screen, ctx->ocy, ctx->xoff, ctx->yoff);
+       tty_draw_line(tty, wp->screen, ctx->ocy, ctx->xoff, ctx->yoff, colgc);
 }
 
 void
@@ -1079,6 +1203,11 @@ tty_cmd_setselection(struct tty *tty, const struct 
tty_ctx *ctx)
 void
 tty_cmd_rawstring(struct tty *tty, const struct tty_ctx *ctx)
 {
+       struct window_pane      *wp = ctx->wp;
+       const struct grid_cell  *colgc;
+
+       colgc = get_wp_default_grid_colours(wp);
+
        u_int    i;
        u_char  *str = ctx->ptr;
 
@@ -1089,6 +1218,8 @@ tty_cmd_rawstring(struct tty *tty, const struct tty_ctx 
*ctx)
        tty->rupper = tty->rlower = UINT_MAX;
 
        tty_reset(tty);
+       if (colgc != NULL)
+               tty_colours(tty, colgc);
        tty_cursor(tty, 0, 0);
 }
 
diff --git a/window.c b/window.c
index 5412963..ca44cbe 100644
--- a/window.c
+++ b/window.c
@@ -288,6 +288,9 @@ window_create1(u_int sx, u_int sy)
        w->sx = sx;
        w->sy = sy;
 
+       w->colgc = NULL;
+       w->apcolgc = NULL;
+
        options_init(&w->options, &global_w_options);
        if (options_get_number(&w->options, "automatic-rename"))
                queue_window_name(w);
@@ -357,6 +360,8 @@ window_destroy(struct window *w)
        window_destroy_panes(w);
 
        free(w->name);
+       free(w->colgc);
+       free(w->apcolgc);
        free(w);
 }
 
@@ -704,6 +709,8 @@ window_pane_create(struct window *w, u_int sx, u_int sy, 
u_int hlimit)
 
        wp->saved_grid = NULL;
 
+       wp->colgc = NULL;
+
        screen_init(&wp->base, sx, sy, hlimit);
        wp->screen = &wp->base;
 
@@ -742,6 +749,7 @@ window_pane_destroy(struct window_pane *wp)
        RB_REMOVE(window_pane_tree, &all_window_panes, wp);
 
        close(wp->cwd);
+       free(wp->colgc);
        free(wp->shell);
        cmd_free_argv(wp->argc, wp->argv);
        free(wp);


-----------------------------------------------------------------------


hooks/post-receive
-- 
tmux

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
tmux-cvs mailing list
tmux-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-cvs

Reply via email to