aboutsummaryrefslogtreecommitdiff
path: root/kern/src/print.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'kern/src/print.cpp')
-rw-r--r--kern/src/print.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/kern/src/print.cpp b/kern/src/print.cpp
new file mode 100644
index 0000000..64e2c65
--- /dev/null
+++ b/kern/src/print.cpp
@@ -0,0 +1,76 @@
+
+#include "kern/print.hpp"
+
+#include <string_view>
+
+namespace teachos
+{
+ namespace
+ {
+ print_handler * current_print_handler{};
+ println_handler * current_println_handler{};
+ print_handler * current_print_error_handler{};
+ println_handler * current_println_error_handler{};
+ } // namespace
+
+ auto print(std::string_view text) -> void
+ {
+ if (current_print_handler)
+ {
+ current_print_handler(text);
+ }
+ }
+
+ auto println(std::string_view text) -> void
+ {
+ if (current_println_handler)
+ {
+ current_println_handler(text);
+ }
+ }
+
+ auto print_error(std::string_view text) -> void
+ {
+ if (current_print_error_handler)
+ {
+ current_print_error_handler(text);
+ }
+ }
+
+ auto println_error(std::string_view text) -> void
+ {
+ if (current_println_error_handler)
+ {
+ current_println_error_handler(text);
+ }
+ }
+
+ auto set_print_handler(print_handler handler) -> print_handler *
+ {
+ auto old = current_print_handler;
+ current_print_handler = handler;
+ return old;
+ }
+
+ auto set_println_handler(println_handler handler) -> print_handler *
+ {
+ auto old = current_println_handler;
+ current_println_handler = handler;
+ return old;
+ }
+
+ auto set_print_error_handler(print_handler handler) -> print_handler *
+ {
+ auto old = current_print_error_handler;
+ current_print_error_handler = handler;
+ return old;
+ }
+
+ auto set_println_error_handler(println_handler handler) -> print_handler *
+ {
+ auto old = current_println_error_handler;
+ current_println_error_handler = handler;
+ return old;
+ }
+
+} // namespace teachos