Kernel: Improve error handling when setting TTY font
This commit is contained in:
parent
d6667844de
commit
cef8779bf7
|
@ -22,7 +22,7 @@ namespace Kernel
|
||||||
|
|
||||||
virtual bool has_font() const override { return true; }
|
virtual bool has_font() const override { return true; }
|
||||||
|
|
||||||
virtual void set_font(const LibFont::Font& font) override { m_font = font; };
|
virtual void set_font(LibFont::Font&& font) override { m_font = BAN::move(font); };
|
||||||
virtual const LibFont::Font& font() const override { return m_font; };
|
virtual const LibFont::Font& font() const override { return m_font; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace Kernel
|
||||||
class TTY : public CharacterDevice
|
class TTY : public CharacterDevice
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void set_font(const LibFont::Font&) {};
|
virtual BAN::ErrorOr<void> set_font(LibFont::Font&&) { return BAN::Error::from_errno(EINVAL); }
|
||||||
|
|
||||||
void set_foreground_pgrp(pid_t pgrp) { m_foreground_pgrp = pgrp; }
|
void set_foreground_pgrp(pid_t pgrp) { m_foreground_pgrp = pgrp; }
|
||||||
pid_t foreground_pgrp() const { return m_foreground_pgrp; }
|
pid_t foreground_pgrp() const { return m_foreground_pgrp; }
|
||||||
|
|
|
@ -37,8 +37,8 @@ namespace Kernel
|
||||||
virtual void set_cursor_position(uint32_t, uint32_t) = 0;
|
virtual void set_cursor_position(uint32_t, uint32_t) = 0;
|
||||||
|
|
||||||
virtual bool has_font() const { return false; }
|
virtual bool has_font() const { return false; }
|
||||||
virtual void set_font(const LibFont::Font&) { ASSERT_NOT_REACHED(); };
|
virtual BAN::ErrorOr<void> set_font(LibFont::Font&&) { return BAN::Error::from_errno(EINVAL); }
|
||||||
virtual const LibFont::Font& font() const { ASSERT_NOT_REACHED(); };
|
virtual const LibFont::Font& font() const { ASSERT_NOT_REACHED(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
extern BAN::RefPtr<TerminalDriver> g_terminal_driver;
|
extern BAN::RefPtr<TerminalDriver> g_terminal_driver;
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace Kernel
|
||||||
public:
|
public:
|
||||||
static BAN::ErrorOr<BAN::RefPtr<VirtualTTY>> create(BAN::RefPtr<TerminalDriver>);
|
static BAN::ErrorOr<BAN::RefPtr<VirtualTTY>> create(BAN::RefPtr<TerminalDriver>);
|
||||||
|
|
||||||
virtual void set_font(const LibFont::Font&) override;
|
virtual BAN::ErrorOr<void> set_font(LibFont::Font&&) override;
|
||||||
|
|
||||||
virtual uint32_t height() const override { return m_height; }
|
virtual uint32_t height() const override { return m_height; }
|
||||||
virtual uint32_t width() const override { return m_width; }
|
virtual uint32_t width() const override { return m_width; }
|
||||||
|
|
|
@ -188,7 +188,7 @@ namespace Kernel
|
||||||
{
|
{
|
||||||
auto absolute_path = TRY(Process::current().absolute_path_of(BAN::StringView(reinterpret_cast<const char*>(argument))));
|
auto absolute_path = TRY(Process::current().absolute_path_of(BAN::StringView(reinterpret_cast<const char*>(argument))));
|
||||||
auto new_font = TRY(LibFont::Font::load(absolute_path));
|
auto new_font = TRY(LibFont::Font::load(absolute_path));
|
||||||
set_font(new_font);
|
TRY(set_font(BAN::move(new_font)));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case TIOCGWINSZ:
|
case TIOCGWINSZ:
|
||||||
|
|
|
@ -55,17 +55,14 @@ namespace Kernel
|
||||||
m_terminal_driver->clear(m_background);
|
m_terminal_driver->clear(m_background);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VirtualTTY::set_font(const LibFont::Font& font)
|
BAN::ErrorOr<void> VirtualTTY::set_font(LibFont::Font&& font)
|
||||||
{
|
{
|
||||||
|
if (!m_terminal_driver->has_font())
|
||||||
|
return BAN::Error::from_errno(EINVAL);
|
||||||
|
|
||||||
SpinLockGuard _(m_write_lock);
|
SpinLockGuard _(m_write_lock);
|
||||||
|
|
||||||
if (!m_terminal_driver->has_font())
|
TRY(m_terminal_driver->set_font(BAN::move(font)));
|
||||||
{
|
|
||||||
dwarnln("terminal driver does not have a font");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_terminal_driver->set_font(font);
|
|
||||||
|
|
||||||
uint32_t new_width = m_terminal_driver->width();
|
uint32_t new_width = m_terminal_driver->width();
|
||||||
uint32_t new_height = m_terminal_driver->height();
|
uint32_t new_height = m_terminal_driver->height();
|
||||||
|
@ -91,6 +88,8 @@ namespace Kernel
|
||||||
for (uint32_t y = 0; y < m_height; y++)
|
for (uint32_t y = 0; y < m_height; y++)
|
||||||
for (uint32_t x = 0; x < m_width; x++)
|
for (uint32_t x = 0; x < m_width; x++)
|
||||||
render_from_buffer(x, y);
|
render_from_buffer(x, y);
|
||||||
|
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void VirtualTTY::set_cursor_position(uint32_t x, uint32_t y)
|
void VirtualTTY::set_cursor_position(uint32_t x, uint32_t y)
|
||||||
|
|
Loading…
Reference in New Issue