Kernel: Shell is no longer singleton
This commit is contained in:
parent
1545850be3
commit
8881c1e117
|
@ -11,17 +11,12 @@ namespace Kernel
|
||||||
class Shell
|
class Shell
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
Shell(TTY*);
|
||||||
Shell(const Shell&) = delete;
|
Shell(const Shell&) = delete;
|
||||||
|
|
||||||
static Shell& Get();
|
|
||||||
|
|
||||||
void SetTTY(TTY* tty);
|
|
||||||
void SetPrompt(BAN::StringView);
|
void SetPrompt(BAN::StringView);
|
||||||
|
|
||||||
void Run();
|
void Run();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Shell();
|
|
||||||
void ReRenderBuffer() const;
|
void ReRenderBuffer() const;
|
||||||
void ProcessCommand(const BAN::Vector<BAN::StringView>&);
|
void ProcessCommand(const BAN::Vector<BAN::StringView>&);
|
||||||
void KeyEventCallback(Input::KeyEvent);
|
void KeyEventCallback(Input::KeyEvent);
|
||||||
|
|
|
@ -18,7 +18,7 @@ namespace Kernel
|
||||||
{
|
{
|
||||||
using namespace BAN;
|
using namespace BAN;
|
||||||
|
|
||||||
static Shell* s_instance = nullptr;
|
static auto s_default_prompt = "\\[\e[32m\\]user\\[\e[m\\]# "_sv;
|
||||||
|
|
||||||
static uint8_t s_pointer[] {
|
static uint8_t s_pointer[] {
|
||||||
________,
|
________,
|
||||||
|
@ -39,18 +39,12 @@ namespace Kernel
|
||||||
X_______,
|
X_______,
|
||||||
};
|
};
|
||||||
|
|
||||||
Shell& Shell::Get()
|
Shell::Shell(TTY* tty)
|
||||||
|
: m_tty(tty)
|
||||||
{
|
{
|
||||||
if (!s_instance)
|
|
||||||
s_instance = new Shell();
|
|
||||||
return *s_instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
Shell::Shell()
|
|
||||||
{
|
|
||||||
SetPrompt("\\[\e[32m\\]user\\[\e[m\\]# "_sv);
|
|
||||||
Input::register_key_event_callback({ &Shell::KeyEventCallback, this });
|
Input::register_key_event_callback({ &Shell::KeyEventCallback, this });
|
||||||
Input::register_mouse_move_event_callback({ &Shell::MouseMoveEventCallback, this });
|
Input::register_mouse_move_event_callback({ &Shell::MouseMoveEventCallback, this });
|
||||||
|
SetPrompt(s_default_prompt);
|
||||||
MUST(m_buffer.PushBack(""_sv));
|
MUST(m_buffer.PushBack(""_sv));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,14 +72,8 @@ namespace Kernel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shell::SetTTY(TTY* tty)
|
|
||||||
{
|
|
||||||
m_tty = tty;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Shell::Run()
|
void Shell::Run()
|
||||||
{
|
{
|
||||||
ASSERT(m_tty);
|
|
||||||
TTY_PRINT("{}", m_prompt);
|
TTY_PRINT("{}", m_prompt);
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
|
|
@ -95,8 +95,7 @@ extern "C" void kernel_main()
|
||||||
|
|
||||||
kprintln("Hello from the kernel!");
|
kprintln("Hello from the kernel!");
|
||||||
|
|
||||||
auto& shell = Kernel::Shell::Get();
|
Kernel::Shell shell(tty1);
|
||||||
shell.SetTTY(tty1);
|
|
||||||
shell.Run();
|
shell.Run();
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
|
|
Loading…
Reference in New Issue