diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-01-13 10:14:22 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-01-13 10:14:22 +0100 |
| commit | 1cba17bf7b23c5b098af2301e5abce5f5761f061 (patch) | |
| tree | a3a41a083a071203127e1c5d1c475f7fa291cbc2 /arch | |
| parent | fb1c180c431e3ac07ca56f53299edea316883842 (diff) | |
| download | teachos-1cba17bf7b23c5b098af2301e5abce5f5761f061.tar.xz teachos-1cba17bf7b23c5b098af2301e5abce5f5761f061.zip | |
x86_64/vga: extract special character handling
Diffstat (limited to 'arch')
| -rw-r--r-- | arch/x86_64/include/x86_64/vga/text.hpp | 19 | ||||
| -rw-r--r-- | arch/x86_64/src/vga/text.cpp | 38 |
2 files changed, 49 insertions, 8 deletions
diff --git a/arch/x86_64/include/x86_64/vga/text.hpp b/arch/x86_64/include/x86_64/vga/text.hpp index fcda67f..64cb2b9 100644 --- a/arch/x86_64/include/x86_64/vga/text.hpp +++ b/arch/x86_64/include/x86_64/vga/text.hpp @@ -129,6 +129,25 @@ namespace teachos::vga::x86_64::text [[nodiscard]] auto column() const noexcept -> std::ptrdiff_t; [[nodiscard]] auto line() const noexcept -> std::ptrdiff_t; + //! Process the semantics of special code points, for example newlines and carriage returns. + //! + //! @param code_point The code point to process. + //! @param attribute The attribute to use when writing to the text buffer. + //! @return @p true iff. the code point was handled, @p false otherwise. + auto handle_special_code_point(char code_point, attribute attribute) -> bool; + + //! Perform the actual output to the buffer. + //! + //! @param code_points The code points to output.. + //! @param attribute The attribute to use when writing to the text buffer. + auto put(std::string_view code_points, attribute attribute) -> void; + + //! Perform the actual output to the buffer. + //! + //! @param code_point The code point to output. + //! @param attribute The attribute to use when writing to the text buffer. + auto put(char code_point, attribute attribute) -> void; + /** * @brief Move the cursor to a new line, scrolling the buffer if necessary. */ 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<std::byte>(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<std::byte>(attribute)}; }; } // namespace teachos::vga::x86_64::text |
