aboutsummaryrefslogtreecommitdiff
path: root/arch/x86_64/src
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-01-13 10:14:22 +0100
committerFelix Morgner <felix.morgner@ost.ch>2026-01-13 10:14:22 +0100
commit1cba17bf7b23c5b098af2301e5abce5f5761f061 (patch)
treea3a41a083a071203127e1c5d1c475f7fa291cbc2 /arch/x86_64/src
parentfb1c180c431e3ac07ca56f53299edea316883842 (diff)
downloadteachos-1cba17bf7b23c5b098af2301e5abce5f5761f061.tar.xz
teachos-1cba17bf7b23c5b098af2301e5abce5f5761f061.zip
x86_64/vga: extract special character handling
Diffstat (limited to 'arch/x86_64/src')
-rw-r--r--arch/x86_64/src/vga/text.cpp38
1 files changed, 30 insertions, 8 deletions
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