forked from Bananymous/banan-os
Kernel: Shell now actually prints to its TTY
This commit is contained in:
parent
f0fd62c703
commit
2a65c5fd0f
|
@ -9,6 +9,9 @@
|
|||
#include <kernel/Serial.h>
|
||||
#include <kernel/TTY.h>
|
||||
|
||||
#define TTY_PRINT(...) BAN::Formatter::print([this](char c) { m_tty->PutChar(c); }, __VA_ARGS__)
|
||||
#define TTY_PRINTLN(...) BAN::Formatter::println([this](char c) { m_tty->PutChar(c); }, __VA_ARGS__)
|
||||
|
||||
namespace Kernel
|
||||
{
|
||||
|
||||
|
@ -29,7 +32,7 @@ namespace Kernel
|
|||
|
||||
void Shell::PrintPrompt()
|
||||
{
|
||||
kprint("\e[32muser\e[m# ");
|
||||
TTY_PRINT("\e[32muser\e[m# ");
|
||||
}
|
||||
|
||||
void Shell::SetTTY(TTY* tty)
|
||||
|
@ -56,11 +59,11 @@ namespace Kernel
|
|||
{
|
||||
if (arguments.Size() != 1)
|
||||
{
|
||||
kprintln("'date' does not support command line arguments");
|
||||
TTY_PRINTLN("'date' does not support command line arguments");
|
||||
return;
|
||||
}
|
||||
auto time = RTC::GetCurrentTime();
|
||||
kprintln("{}", time);
|
||||
TTY_PRINTLN("{}", time);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -68,11 +71,11 @@ namespace Kernel
|
|||
{
|
||||
if (arguments.Size() > 1)
|
||||
{
|
||||
kprint("{}", arguments[1]);
|
||||
TTY_PRINT("{}", arguments[1]);
|
||||
for (size_t i = 2; i < arguments.Size(); i++)
|
||||
kprint(" {}", arguments[i]);
|
||||
TTY_PRINT(" {}", arguments[i]);
|
||||
}
|
||||
kprintln("");
|
||||
TTY_PRINTLN("");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -80,7 +83,7 @@ namespace Kernel
|
|||
{
|
||||
if (arguments.Size() != 1)
|
||||
{
|
||||
kprintln("'clear' does not support command line arguments");
|
||||
TTY_PRINTLN("'clear' does not support command line arguments");
|
||||
return;
|
||||
}
|
||||
m_tty->Clear();
|
||||
|
@ -95,7 +98,7 @@ namespace Kernel
|
|||
auto start = PIT::ms_since_boot();
|
||||
ProcessCommand(new_args);
|
||||
auto duration = PIT::ms_since_boot() - start;
|
||||
kprintln("took {} ms", duration);
|
||||
TTY_PRINTLN("took {} ms", duration);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -103,12 +106,12 @@ namespace Kernel
|
|||
{
|
||||
if (arguments.Size() != 1)
|
||||
{
|
||||
kprintln("'cpuinfo' does not support command line arguments");
|
||||
TTY_PRINTLN("'cpuinfo' does not support command line arguments");
|
||||
return;
|
||||
}
|
||||
if (!CPUID::IsAvailable())
|
||||
{
|
||||
kprintln("'cpuid' instruction not available");
|
||||
TTY_PRINTLN("'cpuid' instruction not available");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -116,16 +119,16 @@ namespace Kernel
|
|||
auto vendor = CPUID::GetVendor();
|
||||
CPUID::GetFeatures(ecx, edx);
|
||||
|
||||
kprintln("Vendor: '{}'", vendor);
|
||||
TTY_PRINTLN("Vendor: '{}'", vendor);
|
||||
bool first = true;
|
||||
for (int i = 0; i < 32; i++)
|
||||
if (ecx & ((uint32_t)1 << i))
|
||||
kprint("{}{}", first ? (first = false, "") : ", ", CPUID::FeatStringECX((uint32_t)1 << i));
|
||||
TTY_PRINT("{}{}", first ? (first = false, "") : ", ", CPUID::FeatStringECX((uint32_t)1 << i));
|
||||
for (int i = 0; i < 32; i++)
|
||||
if (edx & ((uint32_t)1 << i))
|
||||
kprint("{}{}", first ? (first = false, "") : ", ", CPUID::FeatStringEDX((uint32_t)1 << i));
|
||||
TTY_PRINT("{}{}", first ? (first = false, "") : ", ", CPUID::FeatStringEDX((uint32_t)1 << i));
|
||||
if (!first)
|
||||
kprintln("");
|
||||
TTY_PRINTLN("");
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -134,19 +137,19 @@ namespace Kernel
|
|||
{
|
||||
if (arguments.Size() != 1)
|
||||
{
|
||||
kprintln("'random' does not support command line arguments");
|
||||
TTY_PRINTLN("'random' does not support command line arguments");
|
||||
return;
|
||||
}
|
||||
if (!CPUID::IsAvailable())
|
||||
{
|
||||
kprintln("'cpuid' instruction not available");
|
||||
TTY_PRINTLN("'cpuid' instruction not available");
|
||||
return;
|
||||
}
|
||||
uint32_t ecx, edx;
|
||||
CPUID::GetFeatures(ecx, edx);
|
||||
if (!(ecx & CPUID::Features::ECX_RDRND))
|
||||
{
|
||||
kprintln("cpu does not support RDRAND instruction");
|
||||
TTY_PRINTLN("cpu does not support RDRAND instruction");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -154,7 +157,7 @@ namespace Kernel
|
|||
{
|
||||
uint32_t random;
|
||||
asm volatile("rdrand %0" : "=r"(random));
|
||||
kprintln(" 0x{8H}", random);
|
||||
TTY_PRINTLN(" 0x{8H}", random);
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -164,7 +167,7 @@ namespace Kernel
|
|||
{
|
||||
if (arguments.Size() != 1)
|
||||
{
|
||||
kprintln("'reboot' does not support command line arguments");
|
||||
TTY_PRINTLN("'reboot' does not support command line arguments");
|
||||
return;
|
||||
}
|
||||
uint8_t good = 0x02;
|
||||
|
@ -175,7 +178,7 @@ namespace Kernel
|
|||
return;
|
||||
}
|
||||
|
||||
kprintln("unrecognized command '{}'", arguments.Front());
|
||||
TTY_PRINTLN("unrecognized command '{}'", arguments.Front());
|
||||
}
|
||||
|
||||
static bool IsSingleUnicode(BAN::StringView sv)
|
||||
|
@ -220,7 +223,7 @@ namespace Kernel
|
|||
{
|
||||
if (!m_buffer.Empty())
|
||||
{
|
||||
kprint("\b \b", 3);
|
||||
TTY_PRINT("\b \b", 3);
|
||||
|
||||
uint32_t last_len = GetLastLength(m_buffer);
|
||||
for (uint32_t i = 0; i < last_len; i++)
|
||||
|
@ -232,7 +235,7 @@ namespace Kernel
|
|||
case Keyboard::Key::Enter:
|
||||
case Keyboard::Key::NumpadEnter:
|
||||
{
|
||||
kprint("\n");
|
||||
TTY_PRINT("\n");
|
||||
ProcessCommand(MUST(m_buffer.SV().Split(' ')));
|
||||
m_buffer.Clear();
|
||||
PrintPrompt();
|
||||
|
@ -240,7 +243,7 @@ namespace Kernel
|
|||
}
|
||||
|
||||
case Keyboard::Key::Escape:
|
||||
kprintln("time since boot {} ms", PIT::ms_since_boot());
|
||||
TTY_PRINTLN("time since boot {} ms", PIT::ms_since_boot());
|
||||
break;
|
||||
|
||||
case Keyboard::Key::Tab:
|
||||
|
@ -251,7 +254,7 @@ namespace Kernel
|
|||
const char* utf8 = Keyboard::key_event_to_utf8(event);
|
||||
if (utf8)
|
||||
{
|
||||
kprint("{}", utf8);
|
||||
TTY_PRINT("{}", utf8);
|
||||
m_buffer.Append(utf8);
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue