From 1cba17bf7b23c5b098af2301e5abce5f5761f061 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Tue, 13 Jan 2026 10:14:22 +0100 Subject: x86_64/vga: extract special character handling --- arch/x86_64/src/vga/text.cpp | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) (limited to 'arch/x86_64/src/vga/text.cpp') diff --git a/arch/x86_64/src/vga/text.cpp b/arch/x86_64/src/vga/text.cpp index 8f6214e..1249cc3 100644 --- a/arch/x86_64/src/vga/text.cpp +++ b/arch/x86_64/src/vga/text.cpp @@ -58,6 +58,34 @@ namespace teachos::vga::x86_64::text return m_position / DEFAULT_TEXT_BUFFER_WIDTH; } + auto device::handle_special_code_point(char code_point, attribute attribute) -> bool + { + switch (code_point) + { + case '\n': + newline(); + return true; + case '\r': + m_position -= column(); + return true; + case '\t': + put(" ", attribute); + return true; + default: + return false; + } + } + + auto device::put(std::string_view code_points, attribute attribute) -> void + { + std::ranges::for_each(code_points, [&](auto code_point) -> void { put(code_point, attribute); }); + } + + auto device::put(char code_point, attribute attribute) -> void + { + buffer[m_position++] = std::pair{code_point, std::bit_cast(attribute)}; + } + auto device::newline() -> void { auto free_glyphs_in_line = DEFAULT_TEXT_BUFFER_WIDTH - column(); @@ -103,16 +131,10 @@ namespace teachos::vga::x86_64::text scroll(); } - if (code_point == '\n') + if (!handle_special_code_point(code_point, attribute)) { - if (column()) - { - newline(); - } - return; + put(code_point, attribute); } - - buffer[m_position++] = std::pair{code_point, std::bit_cast(attribute)}; }; } // namespace teachos::vga::x86_64::text -- cgit v1.2.3