kernel: Implement reading from /dev/console
This commit is contained in:
parent
51f0bdff0e
commit
d33fccc66f
@ -4,9 +4,11 @@
|
||||
#include "arch/Timer.h"
|
||||
#include "arch/x86_64/CPU.h"
|
||||
#include "arch/x86_64/IO.h"
|
||||
#include "fs/devices/ConsoleDevice.h"
|
||||
#include "memory/MemoryManager.h"
|
||||
#include "sys/Syscall.h"
|
||||
#include "thread/Scheduler.h"
|
||||
#include "video/TextConsole.h"
|
||||
#include <cpuid.h>
|
||||
#include <luna/CString.h>
|
||||
#include <luna/CircularQueue.h>
|
||||
@ -124,7 +126,11 @@ void io_thread()
|
||||
while (!scancode_queue.try_pop(scancode)) { kernel_sleep(10); }
|
||||
|
||||
char key;
|
||||
if (Keyboard::decode_scancode(scancode).try_set_value(key)) { kdbgln("Read key: %c", key); }
|
||||
if (Keyboard::decode_scancode(scancode).try_set_value(key))
|
||||
{
|
||||
TextConsole::putchar(key);
|
||||
ConsoleDevice::did_press_key(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,15 +1,26 @@
|
||||
#include "fs/devices/ConsoleDevice.h"
|
||||
#include "video/TextConsole.h"
|
||||
#include <luna/Buffer.h>
|
||||
#include <luna/CString.h>
|
||||
|
||||
static Buffer g_console_input;
|
||||
|
||||
Result<SharedPtr<Device>> ConsoleDevice::create()
|
||||
{
|
||||
return (SharedPtr<Device>)TRY(make_shared<ConsoleDevice>());
|
||||
}
|
||||
|
||||
// FIXME: Read from the keyboard.
|
||||
Result<usize> ConsoleDevice::read(u8*, usize, usize) const
|
||||
Result<usize> ConsoleDevice::read(u8* buf, usize, usize length) const
|
||||
{
|
||||
return 0;
|
||||
if (length > g_console_input.size()) length = g_console_input.size();
|
||||
|
||||
memcpy(buf, g_console_input.data(), length);
|
||||
|
||||
memmove(g_console_input.data(), g_console_input.data() + length, g_console_input.size() - length);
|
||||
|
||||
g_console_input.try_resize(g_console_input.size() - length).release_value();
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
Result<usize> ConsoleDevice::write(const u8* buf, usize, usize length)
|
||||
@ -20,5 +31,10 @@ Result<usize> ConsoleDevice::write(const u8* buf, usize, usize length)
|
||||
|
||||
bool ConsoleDevice::blocking() const
|
||||
{
|
||||
return false;
|
||||
return g_console_input.size() == 0;
|
||||
}
|
||||
|
||||
void ConsoleDevice::did_press_key(char key)
|
||||
{
|
||||
*g_console_input.slice_at_end(1).value() = (u8)key;
|
||||
}
|
||||
|
@ -11,6 +11,8 @@ class ConsoleDevice : public Device
|
||||
|
||||
Result<usize> write(const u8*, usize, usize) override;
|
||||
|
||||
static void did_press_key(char key);
|
||||
|
||||
bool blocking() const override;
|
||||
|
||||
virtual ~ConsoleDevice() = default;
|
||||
|
Loading…
Reference in New Issue
Block a user