diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-02-01 05:40:27 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-02-01 05:40:27 +0100 |
commit | 240b5fe677109e1cdc6fb964a6fb49750303f305 (patch) | |
tree | ed39b32bc74ec996e369f298243efb5d35d00818 | |
parent | b7967d129211ea280de3d9132d8ef3ff74b0d434 (diff) | |
download | serenity-240b5fe677109e1cdc6fb964a6fb49750303f305.zip |
Terminal: Draw the cursor by reversing foreground/background color.
This makes the cursor pleasantly see-through.
-rw-r--r-- | Terminal/Terminal.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/Terminal/Terminal.cpp b/Terminal/Terminal.cpp index 93cd0cb8a3..c85f747581 100644 --- a/Terminal/Terminal.cpp +++ b/Terminal/Terminal.cpp @@ -633,6 +633,9 @@ void Terminal::paint() } m_rows_to_scroll_backing_store = 0; + // Always redraw the line with the cursor on it. + line(m_cursor_row).dirty = true; + for (word row = 0; row < m_rows; ++row) { auto& line = this->line(row); if (!line.dirty) @@ -642,25 +645,23 @@ void Terminal::paint() if (has_only_one_background_color) painter.fill_rect(row_rect(row), line.attributes[0].background_color); for (word column = 0; column < m_columns; ++column) { + bool should_reverse_fill_for_cursor = m_in_active_window && row == m_cursor_row && column == m_cursor_column; auto& attribute = line.attributes[column]; line.did_paint = true; char ch = line.characters[column]; auto character_rect = glyph_rect(row, column); - if (!has_only_one_background_color) { - auto character_background = ansi_color(attribute.background_color); - painter.fill_rect(character_rect, character_background); - } + if (!has_only_one_background_color || should_reverse_fill_for_cursor) + painter.fill_rect(character_rect, ansi_color(should_reverse_fill_for_cursor ? attribute.foreground_color : attribute.background_color)); if (ch == ' ') continue; - painter.draw_glyph(character_rect.location(), ch, ansi_color(attribute.foreground_color)); + painter.draw_glyph(character_rect.location(), ch, ansi_color(should_reverse_fill_for_cursor ? attribute.background_color : attribute.foreground_color)); } } - auto cursor_rect = glyph_rect(m_cursor_row, m_cursor_column); - if (m_in_active_window) - painter.fill_rect(cursor_rect, Color::MidGray); - else - painter.draw_rect(cursor_rect, Color::MidGray); + if (!m_in_active_window) { + auto cursor_rect = glyph_rect(m_cursor_row, m_cursor_column); + painter.draw_rect(cursor_rect, ansi_color(line(m_cursor_row).attributes[m_cursor_column].foreground_color)); + } line(m_cursor_row).did_paint = true; |