Compare commits
3 Commits
6f14bf553f
...
cda036ce70
Author | SHA1 | Date | |
---|---|---|---|
cda036ce70 | |||
83492339ec | |||
89ad6869a4 |
@ -2,6 +2,7 @@
|
||||
#include "video/TextConsole.h"
|
||||
#include <luna/Buffer.h>
|
||||
#include <luna/CString.h>
|
||||
#include <luna/Vector.h>
|
||||
|
||||
static Buffer g_console_input;
|
||||
|
||||
@ -34,7 +35,24 @@ bool ConsoleDevice::blocking() const
|
||||
return g_console_input.size() == 0;
|
||||
}
|
||||
|
||||
static Vector<u8> g_temp_input;
|
||||
|
||||
void ConsoleDevice::did_press_key(char key)
|
||||
{
|
||||
*g_console_input.slice_at_end(1).value() = (u8)key;
|
||||
if (key == '\b')
|
||||
{
|
||||
if (g_temp_input.try_pop().has_value()) TextConsole::putwchar(L'\b');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
g_temp_input.try_append(key).value();
|
||||
|
||||
if (key == '\n')
|
||||
{
|
||||
g_console_input.append_data(g_temp_input.data(), g_temp_input.size()).value();
|
||||
g_temp_input.clear();
|
||||
}
|
||||
|
||||
TextConsole::putchar(key);
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ class Buffer
|
||||
|
||||
Result<u8*> slice(usize offset, usize size);
|
||||
|
||||
Result<void> append_data(u8* data, usize size);
|
||||
|
||||
u8* data()
|
||||
{
|
||||
return m_data;
|
||||
|
@ -160,6 +160,12 @@ template <typename T> class Vector
|
||||
return m_size;
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
m_size = m_capacity = 0;
|
||||
free_impl(m_data);
|
||||
}
|
||||
|
||||
private:
|
||||
T* m_data { nullptr };
|
||||
usize m_capacity { 0 };
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include <luna/Buffer.h>
|
||||
#include <luna/CString.h>
|
||||
#include <luna/Heap.h>
|
||||
|
||||
Buffer::Buffer()
|
||||
@ -44,3 +45,10 @@ Result<u8*> Buffer::slice(usize offset, usize size)
|
||||
if (offset + size > m_size) { TRY(try_resize(offset + size)); }
|
||||
return m_data + offset;
|
||||
}
|
||||
|
||||
Result<void> Buffer::append_data(u8* data, usize size)
|
||||
{
|
||||
memcpy(TRY(slice_at_end(size)), data, size);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user