[Teton] Buffer current command for executing.
This commit is contained in:
parent
c8e5441c7f
commit
faa54bc3dc
|
@ -2,7 +2,7 @@ add_executable(teton
|
|||
framebuffer/console.cpp
|
||||
framebuffer/framebuffer.cpp
|
||||
framebuffer/psf.cpp
|
||||
keyboard_listener.cpp
|
||||
terminal.cpp
|
||||
teton.cpp
|
||||
)
|
||||
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
#include "keyboard_listener.h"
|
||||
|
||||
void KeyboardListener::HandleCharacter(char c) { console_.WriteChar(c); }
|
|
@ -1,12 +0,0 @@
|
|||
#include <mammoth/input/keyboard.h>
|
||||
|
||||
#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_;
|
||||
};
|
|
@ -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>");
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
#include <glacier/string/string_builder.h>
|
||||
#include <mammoth/input/keyboard.h>
|
||||
|
||||
#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_;
|
||||
};
|
|
@ -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());
|
||||
|
||||
|
|
Loading…
Reference in New Issue