Terminal: Implement more ANSI escape handling

This patch adds L and M codes for inserting and deleting lines and SGR 7
for inverting colors
This commit is contained in:
Bananymous 2024-09-26 15:07:08 +03:00
parent 1a6804b4b4
commit 57ae74f908
1 changed files with 40 additions and 0 deletions

View File

@ -269,6 +269,12 @@ void Terminal::handle_sgr()
m_bg_color = s_colors_dark[0]; m_bg_color = s_colors_dark[0];
m_fg_color = s_colors_bright[7]; m_fg_color = s_colors_bright[7];
break; 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: 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]; m_fg_color = s_colors_dark[m_csi_info.fields[0] - 30];
break; break;
@ -397,6 +403,40 @@ Rectangle Terminal::handle_csi(char ch)
break; 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': case 'm':
handle_sgr(); handle_sgr();
break; break;