From 57ae74f908b9cda36bca33b958888c16086adb3c Mon Sep 17 00:00:00 2001 From: Bananymous Date: Thu, 26 Sep 2024 15:07:08 +0300 Subject: [PATCH] Terminal: Implement more ANSI escape handling This patch adds L and M codes for inserting and deleting lines and SGR 7 for inverting colors --- userspace/programs/Terminal/Terminal.cpp | 40 ++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/userspace/programs/Terminal/Terminal.cpp b/userspace/programs/Terminal/Terminal.cpp index d4269894c9..6b66177ee9 100644 --- a/userspace/programs/Terminal/Terminal.cpp +++ b/userspace/programs/Terminal/Terminal.cpp @@ -269,6 +269,12 @@ void Terminal::handle_sgr() m_bg_color = s_colors_dark[0]; m_fg_color = s_colors_bright[7]; break; + case 1: + // FIXME: bold + break; + case 7: + BAN::swap(m_fg_color, m_bg_color); + break; case 30: case 31: case 32: case 33: case 34: case 35: case 36: case 37: m_fg_color = s_colors_dark[m_csi_info.fields[0] - 30]; break; @@ -397,6 +403,40 @@ Rectangle Terminal::handle_csi(char ch) break; } + case 'L': + { + const uint32_t count = (m_csi_info.fields[0] == -1) ? 1 : m_csi_info.fields[0]; + const uint32_t src_y = m_cursor.y * m_font.height(); + const uint32_t dst_y = src_y + count * m_font.height(); + + m_window->copy_horizontal_slice(dst_y, src_y, m_window->height() - dst_y, m_bg_color); + m_window->fill_rect(0, src_y, m_window->width(), count * m_font.height(), m_bg_color); + should_invalidate = { + 0, + src_y, + m_window->width(), + m_window->height() - src_y + }; + + break; + } + case 'M': + { + const uint32_t count = (m_csi_info.fields[0] == -1) ? 1 : m_csi_info.fields[0]; + const uint32_t dst_y = m_cursor.y * m_font.height(); + const uint32_t src_y = dst_y + count * m_font.height(); + + m_window->copy_horizontal_slice(dst_y, src_y, m_window->height() - dst_y, m_bg_color); + m_window->fill_rect(0, m_window->height() - count * m_font.height(), m_window->width(), count * m_font.height(), m_bg_color); + should_invalidate = { + 0, + src_y, + m_window->width(), + m_window->height() - src_y + }; + + break; + } case 'm': handle_sgr(); break;