From 37cd4ed50409a6328da0c0ad00a625530c4f771e Mon Sep 17 00:00:00 2001 From: Bananymous Date: Thu, 22 Aug 2024 14:04:45 +0300 Subject: [PATCH] Kernel: Add support for CSI @, b, d to VirtualTerminal --- kernel/include/kernel/Terminal/VirtualTTY.h | 1 + kernel/kernel/Terminal/VirtualTTY.cpp | 27 ++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/kernel/include/kernel/Terminal/VirtualTTY.h b/kernel/include/kernel/Terminal/VirtualTTY.h index a2ac4e2e..92c879a0 100644 --- a/kernel/include/kernel/Terminal/VirtualTTY.h +++ b/kernel/include/kernel/Terminal/VirtualTTY.h @@ -74,6 +74,7 @@ namespace Kernel uint32_t m_width { 0 }; uint32_t m_height { 0 }; + uint32_t m_last_graphic_char { 0 }; uint32_t m_saved_row { 0 }; uint32_t m_saved_column { 0 }; diff --git a/kernel/kernel/Terminal/VirtualTTY.cpp b/kernel/kernel/Terminal/VirtualTTY.cpp index 131881b1..d850ad9d 100644 --- a/kernel/kernel/Terminal/VirtualTTY.cpp +++ b/kernel/kernel/Terminal/VirtualTTY.cpp @@ -305,7 +305,31 @@ namespace Kernel m_row = m_saved_row; m_column = m_saved_column; return reset_ansi(); - + case '@': + if (m_ansi_state.nums[0] == -1) + m_ansi_state.nums[0] = 1; + reset_ansi(); + for (int i = 0; i < m_ansi_state.nums[0]; i++) + putchar_impl(' '); + return; + case 'b': + if (m_ansi_state.nums[0] == -1) + m_ansi_state.nums[0] = 1; + reset_ansi(); + if (m_last_graphic_char) + { + char buffer[5] {}; + BAN::UTF8::from_codepoints(&m_last_graphic_char, 1, buffer); + for (int i = 0; i < m_ansi_state.nums[0]; i++) + for (int j = 0; buffer[j]; j++) + putchar_impl(buffer[j]); + } + return; + case 'd': + if (m_ansi_state.nums[0] == -1) + m_ansi_state.nums[0] = 1; + m_row = BAN::Math::clamp(m_ansi_state.nums[0], 1, m_height) - 1; + return reset_ansi(); case '?': if (m_ansi_state.index != 0 || m_ansi_state.nums[0] != -1) { @@ -439,6 +463,7 @@ namespace Kernel break;; default: putchar_at(codepoint, m_column, m_row); + m_last_graphic_char = codepoint; m_column++; break; }