Terminal: add bg color handling + PDBG

Set the right bg color instead of using a dimmed version of the fg
color. The colors are stored in the first 6 bits of the color index.
Thereby the first 3 bits contain the fg and the second 3 bits the
bg color.

The debug message in _handle_esc_seq5() now shows the sequence in
question.

Fixes #495.
This commit is contained in:
Josef Söntgen 2012-11-12 16:25:01 +01:00 committed by Norman Feske
parent 3c562d042d
commit b7d1c40460
2 changed files with 30 additions and 16 deletions

View File

@ -369,6 +369,9 @@ namespace Terminal {
|| (_escape_stack[5].type != Escape_stack::Entry::NUMBER)) || (_escape_stack[5].type != Escape_stack::Entry::NUMBER))
return false; return false;
int const p1 = _escape_stack[1].value;
int const p2 = _escape_stack[2].value;
int const p3 = _escape_stack[3].value;
int const command = _escape_stack[6].value; int const command = _escape_stack[6].value;
switch (command) { switch (command) {
@ -378,7 +381,7 @@ namespace Terminal {
* Currently returning true w/o actually handling the * Currently returning true w/o actually handling the
* sequence * sequence
*/ */
PDBG("Sequence '[X;Y;Zm' is not implemented"); PDBG("Sequence '[%d;%d;%d%c' is not implemented", p1, p2, p3, command);
return true; return true;
default: return false; default: return false;
} }

View File

@ -97,32 +97,36 @@ struct Char_cell
{ {
unsigned char attr; unsigned char attr;
unsigned char ascii; unsigned char ascii;
unsigned char color;
enum { ATTR_COLIDX_MASK = 0x07, enum { ATTR_COLIDX_MASK = 0x07,
ATTR_CURSOR = 0x10, ATTR_CURSOR = 0x10,
ATTR_INVERSE = 0x20, ATTR_INVERSE = 0x20,
ATTR_HIGHLIGHT = 0x40 }; ATTR_HIGHLIGHT = 0x40 };
enum { COLOR_MASK = 0x3f }; /* 111111 */
Char_cell() : attr(0), ascii(0) { } Char_cell() : attr(0), ascii(0) { }
Char_cell(unsigned char c, Font_family::Face f, Char_cell(unsigned char c, Font_family::Face f,
int colidx, bool inv, bool highlight) int colidx, bool inv, bool highlight)
: :
attr(f | (colidx & ATTR_COLIDX_MASK) attr(f | (inv ? ATTR_INVERSE : 0)
| (inv ? ATTR_INVERSE : 0)
| (highlight ? ATTR_HIGHLIGHT : 0)), | (highlight ? ATTR_HIGHLIGHT : 0)),
ascii(c) ascii(c),
color(colidx & COLOR_MASK)
{ } { }
Font_family::Face font_face() const { return (Font_family::Face)(attr & 0x3); } Font_family::Face font_face() const { return (Font_family::Face)(attr & 0x3); }
int colidx() const { return attr & ATTR_COLIDX_MASK; } int colidx_fg() const { return color & ATTR_COLIDX_MASK; }
bool inverse() const { return attr & ATTR_INVERSE; } int colidx_bg() const { return (color >> 3) & ATTR_COLIDX_MASK; }
bool highlight() const { return attr & ATTR_HIGHLIGHT; } bool inverse() const { return attr & ATTR_INVERSE; }
bool highlight() const { return attr & ATTR_HIGHLIGHT; }
Color fg_color() const Color fg_color() const
{ {
Color col = color_palette[colidx() + (highlight() ? 8 : 0)]; Color col = color_palette[colidx_fg() + (highlight() ? 8 : 0)];
if (inverse()) if (inverse())
col = Color(col.r/2, col.g/2, col.b/2); col = Color(col.r/2, col.g/2, col.b/2);
@ -132,12 +136,12 @@ struct Char_cell
Color bg_color() const Color bg_color() const
{ {
Color col = color_palette[colidx() + (highlight() ? 8 : 0)]; Color col = color_palette[colidx_bg() + (highlight() ? 8 : 0)];
if (inverse()) if (inverse())
return Color((col.r + 255)/2, (col.g + 255)/2, (col.b + 255)/2); return Color((col.r + 255)/2, (col.g + 255)/2, (col.b + 255)/2);
else
return Color(0, 0, 0); return col;
} }
void set_cursor() { attr |= ATTR_CURSOR; } void set_cursor() { attr |= ATTR_CURSOR; }
@ -158,6 +162,10 @@ class Char_cell_array_character_screen : public Terminal::Character_screen
Cell_array<Char_cell> &_char_cell_array; Cell_array<Char_cell> &_char_cell_array;
Terminal::Boundary _boundary; Terminal::Boundary _boundary;
Terminal::Position _cursor_pos; Terminal::Position _cursor_pos;
/**
* Color index contains the fg color in the first 3 bits
* and the bg color in the second 3 bits (0bbbbfff).
*/
int _color_index; int _color_index;
bool _inverse; bool _inverse;
bool _highlight; bool _highlight;
@ -166,7 +174,7 @@ class Char_cell_array_character_screen : public Terminal::Character_screen
int _region_end; int _region_end;
int _tab_size; int _tab_size;
enum { DEFAULT_COLOR_INDEX = 7, DEFAULT_TAB_SIZE = 8 }; enum { DEFAULT_COLOR_INDEX_BG = 0, DEFAULT_COLOR_INDEX = 7, DEFAULT_TAB_SIZE = 8 };
struct Cursor_guard struct Cursor_guard
{ {
@ -415,7 +423,7 @@ class Char_cell_array_character_screen : public Terminal::Character_screen
void op() void op()
{ {
_color_index = DEFAULT_COLOR_INDEX; _color_index = DEFAULT_COLOR_INDEX | (DEFAULT_COLOR_INDEX_BG << 3);
} }
void rc() { PDBG("not implemented"); } void rc() { PDBG("not implemented"); }
@ -426,12 +434,15 @@ class Char_cell_array_character_screen : public Terminal::Character_screen
void setab(int value) void setab(int value)
{ {
_inverse = (value != 0); //_inverse = (value != 0);
_color_index &= ~0x38; /* clear 111000 */
_color_index |= (((value == 9) ? DEFAULT_COLOR_INDEX_BG : value) << 3);
} }
void setaf(int value) void setaf(int value)
{ {
_color_index = value; _color_index &= ~0x7; /* clear 000111 */
_color_index |= (value == 9) ? DEFAULT_COLOR_INDEX : value;
} }
void sgr(int value) void sgr(int value)
@ -441,7 +452,7 @@ class Char_cell_array_character_screen : public Terminal::Character_screen
/* sgr 0 is the command to reset all attributes, including color */ /* sgr 0 is the command to reset all attributes, including color */
if (value == 0) if (value == 0)
_color_index = DEFAULT_COLOR_INDEX; _color_index = DEFAULT_COLOR_INDEX | (DEFAULT_COLOR_INDEX_BG << 3);
} }
void sgr0() void sgr0()