summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnotherTest <ali.mpfard@gmail.com>2021-01-10 16:41:48 +0330
committerAndreas Kling <kling@serenityos.org>2021-01-10 16:58:08 +0100
commit44305ea21419f0fdd5c98e6c4c749cd73a840123 (patch)
treeb7e357d6b038af68908475e928ca6c3402aa7ecb
parent2f3b901f7fe230cbbf489f5a0f38fbb34a07af8c (diff)
downloadserenity-44305ea21419f0fdd5c98e6c4c749cd73a840123.zip
LibVT: Respect the Negative attribute when drawing text
This makes the "reverse video" SGR actually work.
-rw-r--r--Kernel/TTY/VirtualConsole.cpp4
-rw-r--r--Libraries/LibVT/Line.cpp4
-rw-r--r--Libraries/LibVT/Line.h3
-rw-r--r--Libraries/LibVT/TerminalWidget.cpp10
4 files changed, 12 insertions, 9 deletions
diff --git a/Kernel/TTY/VirtualConsole.cpp b/Kernel/TTY/VirtualConsole.cpp
index 6b00892a3d..f6e530b2ee 100644
--- a/Kernel/TTY/VirtualConsole.cpp
+++ b/Kernel/TTY/VirtualConsole.cpp
@@ -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;
}
diff --git a/Libraries/LibVT/Line.cpp b/Libraries/LibVT/Line.cpp
index 9b1e42a58b..56f776e9cb 100644
--- a/Libraries/LibVT/Line.cpp
+++ b/Libraries/LibVT/Line.cpp
@@ -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;
diff --git a/Libraries/LibVT/Line.h b/Libraries/LibVT/Line.h
index 3bbeadf1f1..5b3bcbd5c7 100644
--- a/Libraries/LibVT/Line.h
+++ b/Libraries/LibVT/Line.h
@@ -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;
diff --git a/Libraries/LibVT/TerminalWidget.cpp b/Libraries/LibVT/TerminalWidget.cpp
index f3b8f1b4e9..5fe579a2b4 100644
--- a/Libraries/LibVT/TerminalWidget.cpp
+++ b/Libraries/LibVT/TerminalWidget.cpp
@@ -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()));
}
}
}