1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:57:44 +00:00

LibVT: Respect the Negative attribute when drawing text

This makes the "reverse video" SGR actually work.
This commit is contained in:
AnotherTest 2021-01-10 16:41:48 +03:30 committed by Andreas Kling
parent 2f3b901f7f
commit 44305ea214
4 changed files with 12 additions and 9 deletions

View file

@ -274,11 +274,11 @@ static inline u8 attribute_to_vga(const VT::Attribute& attribute)
// Background color
vga_attr &= ~0x70;
vga_attr |= xterm_color_to_vga(attribute.background_color) << 8;
vga_attr |= xterm_color_to_vga(attribute.effective_background_color()) << 8;
// Foreground color
vga_attr &= ~0x7;
vga_attr |= xterm_color_to_vga(attribute.foreground_color);
vga_attr |= xterm_color_to_vga(attribute.effective_foreground_color());
return vga_attr;
}

View file

@ -104,9 +104,9 @@ bool Line::has_only_one_background_color() const
if (!m_length)
return true;
// FIXME: Cache this result?
auto color = m_attributes[0].background_color;
auto color = m_attributes[0].effective_background_color();
for (size_t i = 1; i < m_length; ++i) {
if (m_attributes[i].background_color != color)
if (m_attributes[i].effective_background_color() != color)
return false;
}
return true;

View file

@ -47,6 +47,9 @@ struct Attribute {
u32 foreground_color;
u32 background_color;
u32 effective_background_color() const { return flags & Negative ? foreground_color : background_color; }
u32 effective_foreground_color() const { return flags & Negative ? background_color : foreground_color; }
String href;
String href_id;

View file

@ -343,7 +343,7 @@ void TerminalWidget::paint_event(GUI::PaintEvent& event)
if (visual_beep_active)
painter.clear_rect(row_rect, Color::Red);
else if (has_only_one_background_color)
painter.clear_rect(row_rect, color_from_rgb(line.attributes()[0].background_color).with_alpha(m_opacity));
painter.clear_rect(row_rect, color_from_rgb(line.attributes()[0].effective_background_color()).with_alpha(m_opacity));
for (size_t column = 0; column < line.length(); ++column) {
bool should_reverse_fill_for_cursor_or_selection = m_cursor_blink_state
@ -354,9 +354,9 @@ void TerminalWidget::paint_event(GUI::PaintEvent& event)
auto attribute = line.attributes()[column];
auto character_rect = glyph_rect(visual_row, column);
auto cell_rect = character_rect.inflated(0, m_line_spacing);
auto text_color = color_from_rgb(should_reverse_fill_for_cursor_or_selection ? attribute.background_color : attribute.foreground_color);
auto text_color = color_from_rgb(should_reverse_fill_for_cursor_or_selection ? attribute.effective_background_color() : attribute.effective_foreground_color());
if ((!visual_beep_active && !has_only_one_background_color) || should_reverse_fill_for_cursor_or_selection) {
painter.clear_rect(cell_rect, color_from_rgb(should_reverse_fill_for_cursor_or_selection ? attribute.foreground_color : attribute.background_color).with_alpha(m_opacity));
painter.clear_rect(cell_rect, color_from_rgb(should_reverse_fill_for_cursor_or_selection ? attribute.effective_foreground_color() : attribute.effective_background_color()).with_alpha(m_opacity));
}
enum class UnderlineStyle {
@ -415,7 +415,7 @@ void TerminalWidget::paint_event(GUI::PaintEvent& event)
&& visual_row == row_with_cursor
&& column == m_terminal.cursor_column();
should_reverse_fill_for_cursor_or_selection |= selection_contains({ first_row_from_history + visual_row, (int)column });
auto text_color = color_from_rgb(should_reverse_fill_for_cursor_or_selection ? attribute.background_color : attribute.foreground_color);
auto text_color = color_from_rgb(should_reverse_fill_for_cursor_or_selection ? attribute.effective_background_color() : attribute.effective_foreground_color());
u32 code_point = line.code_point(column);
if (code_point == ' ')
@ -440,7 +440,7 @@ void TerminalWidget::paint_event(GUI::PaintEvent& event)
auto& cursor_line = m_terminal.line(first_row_from_history + row_with_cursor);
if (m_terminal.cursor_row() < (m_terminal.rows() - rows_from_history)) {
auto cell_rect = glyph_rect(row_with_cursor, m_terminal.cursor_column()).inflated(0, m_line_spacing);
painter.draw_rect(cell_rect, color_from_rgb(cursor_line.attributes()[m_terminal.cursor_column()].foreground_color));
painter.draw_rect(cell_rect, color_from_rgb(cursor_line.attributes()[m_terminal.cursor_column()].effective_foreground_color()));
}
}
}