Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions test/test-vt.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,23 @@ static void test_term(const char *name, int red, int palette196, int rgb123, int
extended_pair_content(reserved, &fg, &bg);
CHECK(fg == COLOR_BLUE && bg == -1);
CHECK(vt_color_reserve(COLOR_BLUE, -1) == reserved);
vt_destroy(t);

/* default colors are applied when drawing, not stored in the cells */
t = vt_create(2, 80, 0);
vt_default_colors_set(t, A_NORMAL, COLOR_GREEN, -1);
feed(t, "a\033[31mb");
drawn(0, &fg, &bg);
CHECK(fg == COLOR_GREEN);
CHECK(strstr(content(t), "\033[39m\033[49ma"));

/* new defaults, e.g. from a color rule after a title change, apply to existing text */
vt_default_colors_set(t, A_NORMAL, COLOR_BLUE, -1);
vt_draw(t, pad, 0, 0);
drawn(0, &fg, &bg);
CHECK(fg == COLOR_BLUE);
drawn(1, &fg, &bg);
CHECK(fg == COLOR_RED);

vt_destroy(t);
delwin(pad);
Expand Down
16 changes: 8 additions & 8 deletions vt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1478,9 +1478,12 @@ int vt_process(Vt *t)

void vt_default_colors_set(Vt *t, attr_t attrs, int fg, int bg)
{
if (t->defattrs == attrs && t->deffg == fg && t->defbg == bg)
return;
t->defattrs = attrs;
t->deffg = fg;
t->defbg = bg;
vt_dirty(t);
}

Vt *vt_create(int rows, int cols, int scroll_size)
Expand Down Expand Up @@ -1561,14 +1564,11 @@ void vt_draw(Vt *t, WINDOW *win, int srow, int scol)
if (!prev_cell || cell->attr != prev_cell->attr
|| cell->fg != prev_cell->fg
|| cell->bg != prev_cell->bg) {
if (cell->attr == A_NORMAL)
cell->attr = t->defattrs;
if (cell->fg == -1)
cell->fg = t->deffg;
if (cell->bg == -1)
cell->bg = t->defbg;
int pair = vt_color_get(t, cell->fg, cell->bg);
wattr_set(win, cell->attr << NCURSES_ATTR_SHIFT, pair, PAIR_OPTS(pair));
attr_t attr = cell->attr == A_NORMAL ? t->defattrs : cell->attr;
int fg = cell->fg == -1 ? t->deffg : cell->fg;
int bg = cell->bg == -1 ? t->defbg : cell->bg;
int pair = vt_color_get(t, fg, bg);
wattr_set(win, attr << NCURSES_ATTR_SHIFT, pair, PAIR_OPTS(pair));
}

if (is_utf8 && cell->text >= 128) {
Expand Down
Loading