diff --git a/sys/teton/CMakeLists.txt b/sys/teton/CMakeLists.txt index d24f2c5..19a6706 100644 --- a/sys/teton/CMakeLists.txt +++ b/sys/teton/CMakeLists.txt @@ -2,7 +2,7 @@ add_executable(teton framebuffer/console.cpp framebuffer/framebuffer.cpp framebuffer/psf.cpp - keyboard_listener.cpp + terminal.cpp teton.cpp ) diff --git a/sys/teton/keyboard_listener.cpp b/sys/teton/keyboard_listener.cpp deleted file mode 100644 index ae2ddff..0000000 --- a/sys/teton/keyboard_listener.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include "keyboard_listener.h" - -void KeyboardListener::HandleCharacter(char c) { console_.WriteChar(c); } diff --git a/sys/teton/keyboard_listener.h b/sys/teton/keyboard_listener.h deleted file mode 100644 index d0e8eb8..0000000 --- a/sys/teton/keyboard_listener.h +++ /dev/null @@ -1,12 +0,0 @@ -#include - -#include "framebuffer/console.h" - -class KeyboardListener : public mmth::KeyboardListenerBase { - public: - KeyboardListener(Console& c) : mmth::KeyboardListenerBase(), console_(c) {} - virtual void HandleCharacter(char c) override; - - private: - Console& console_; -}; diff --git a/sys/teton/terminal.cpp b/sys/teton/terminal.cpp new file mode 100644 index 0000000..c1215a6 --- /dev/null +++ b/sys/teton/terminal.cpp @@ -0,0 +1,20 @@ +#include "terminal.h" + +void Terminal::HandleCharacter(char c) { + console_.WriteChar(c); + if (c == '\n') { + glcr::String str = current_command_.ToString(); + ExecuteCommand(str); + current_command_.Reset(); + } else if (c == '\b') { + current_command_.DeleteLast(); + } else { + current_command_.PushBack(c); + } +} + +void Terminal::ExecuteCommand(const glcr::String& command) { + console_.WriteString("Executing: "); + console_.WriteString(command); + console_.WriteString("\n>"); +} diff --git a/sys/teton/terminal.h b/sys/teton/terminal.h new file mode 100644 index 0000000..3628141 --- /dev/null +++ b/sys/teton/terminal.h @@ -0,0 +1,17 @@ +#include +#include + +#include "framebuffer/console.h" + +class Terminal : public mmth::KeyboardListenerBase { + public: + Terminal(Console& c) : mmth::KeyboardListenerBase(), console_(c) {} + + virtual void HandleCharacter(char c) override; + + void ExecuteCommand(const glcr::String& command); + + private: + Console& console_; + glcr::VariableStringBuilder current_command_; +}; diff --git a/sys/teton/teton.cpp b/sys/teton/teton.cpp index e02254e..fb56e1c 100644 --- a/sys/teton/teton.cpp +++ b/sys/teton/teton.cpp @@ -7,7 +7,7 @@ #include "framebuffer/console.h" #include "framebuffer/framebuffer.h" #include "framebuffer/psf.h" -#include "keyboard_listener.h" +#include "terminal.h" uint64_t main(uint64_t init_port) { ParseInitPort(init_port); @@ -34,10 +34,10 @@ uint64_t main(uint64_t init_port) { Console console(fbuf, psf); console.WriteChar('>'); - KeyboardListener listener(console); - listener.Register(); + Terminal terminal(console); + terminal.Register(); - Thread lthread = listener.Listen(); + Thread lthread = terminal.Listen(); check(lthread.Join());