Compare commits
No commits in common. "703c1a485ce14ba0798179316118e917880afbea" and "7c6966a9c45a8a53f37d3c64c3b7333634ea234c" have entirely different histories.
703c1a485c
...
7c6966a9c4
|
@ -41,6 +41,7 @@ namespace Kernel
|
|||
|
||||
virtual uint32_t height() const = 0;
|
||||
virtual uint32_t width() const = 0;
|
||||
void putchar(uint8_t ch);
|
||||
|
||||
virtual dev_t rdev() const final override { return m_rdev; }
|
||||
|
||||
|
@ -59,13 +60,10 @@ namespace Kernel
|
|||
TTY(mode_t mode, uid_t uid, gid_t gid);
|
||||
|
||||
virtual void putchar_impl(uint8_t ch) = 0;
|
||||
virtual void update_cursor() {}
|
||||
|
||||
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override;
|
||||
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) override;
|
||||
|
||||
private:
|
||||
void putchar(uint8_t ch);
|
||||
void do_backspace();
|
||||
|
||||
protected:
|
||||
|
|
|
@ -24,7 +24,6 @@ namespace Kernel
|
|||
protected:
|
||||
virtual BAN::StringView name() const override { return m_name; }
|
||||
virtual void putchar_impl(uint8_t ch) override;
|
||||
void update_cursor() override;
|
||||
|
||||
private:
|
||||
VirtualTTY(BAN::RefPtr<TerminalDriver>);
|
||||
|
@ -79,7 +78,6 @@ namespace Kernel
|
|||
uint32_t m_saved_row { 0 };
|
||||
uint32_t m_saved_column { 0 };
|
||||
|
||||
bool m_cursor_shown { true };
|
||||
uint32_t m_row { 0 };
|
||||
uint32_t m_column { 0 };
|
||||
Cell* m_buffer { nullptr };
|
||||
|
|
|
@ -64,9 +64,7 @@ namespace Kernel
|
|||
|
||||
const uint32_t indices_per_block = blksize() / sizeof(uint32_t);
|
||||
|
||||
uint32_t divisor = 1;
|
||||
for (uint32_t i = 1; i < depth; i++)
|
||||
divisor *= indices_per_block;
|
||||
const uint32_t divisor = (depth > 1) ? indices_per_block * (depth - 1) : 1;
|
||||
|
||||
const uint32_t next_block = block_buffer.span().as_span<uint32_t>()[(index / divisor) % indices_per_block];
|
||||
if (next_block == 0)
|
||||
|
|
|
@ -19,8 +19,6 @@ namespace Kernel
|
|||
{
|
||||
const uint8_t* glyph = m_font.has_glyph(ch) ? m_font.glyph(ch) : m_font.glyph('?');
|
||||
|
||||
const bool update_cursor = m_cursor_shown && x == m_cursor_x && y == m_cursor_y;
|
||||
|
||||
x *= m_font.width();
|
||||
y *= m_font.height();
|
||||
|
||||
|
@ -36,18 +34,17 @@ namespace Kernel
|
|||
|
||||
m_framebuffer_device->sync_pixels_rectangle(x, y, m_font.width(), m_font.height());
|
||||
|
||||
if (update_cursor)
|
||||
if (x == m_cursor_x && y == m_cursor_y)
|
||||
{
|
||||
read_cursor();
|
||||
show_cursor(false);
|
||||
}
|
||||
}
|
||||
|
||||
bool FramebufferTerminalDriver::scroll(Color color)
|
||||
{
|
||||
if (m_cursor_shown)
|
||||
show_cursor(true);
|
||||
m_framebuffer_device->scroll(m_font.height(), color.rgb);
|
||||
m_framebuffer_device->sync_pixels_full();
|
||||
if (m_cursor_shown)
|
||||
show_cursor(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -65,21 +62,25 @@ namespace Kernel
|
|||
void FramebufferTerminalDriver::read_cursor()
|
||||
{
|
||||
const uint32_t cursor_h = m_font.height() / 8;
|
||||
const uint32_t cursor_w = m_font.width();
|
||||
const uint32_t cursor_top = m_font.height() * 13 / 16;
|
||||
|
||||
const uint32_t x = m_cursor_x * m_font.width();
|
||||
const uint32_t y = m_cursor_y * m_font.height();
|
||||
|
||||
for (uint32_t dy = 0; dy < cursor_h; dy++)
|
||||
for (uint32_t dx = 0; dx < cursor_w; dx++)
|
||||
m_cursor_data[dy * cursor_w + dx] = m_framebuffer_device->get_pixel(x + dx, y + cursor_top + dy);
|
||||
for (uint32_t dx = 0; dx < m_font.width(); dx++)
|
||||
m_cursor_data[dy * m_font.width() + dx] = m_framebuffer_device->get_pixel(x + dx, y + cursor_top + dy);
|
||||
}
|
||||
|
||||
void FramebufferTerminalDriver::show_cursor(bool use_data)
|
||||
{
|
||||
if (!use_data)
|
||||
read_cursor();
|
||||
const auto get_color =
|
||||
[this, use_data](uint32_t x, uint32_t y) -> uint32_t
|
||||
{
|
||||
if (!use_data)
|
||||
return m_cursor_color.rgb;
|
||||
return m_cursor_data[y * m_font.width() + x];
|
||||
};
|
||||
|
||||
const uint32_t cursor_h = m_font.height() / 8;
|
||||
const uint32_t cursor_w = m_font.width();
|
||||
|
@ -88,14 +89,6 @@ namespace Kernel
|
|||
const uint32_t x = m_cursor_x * m_font.width();
|
||||
const uint32_t y = m_cursor_y * m_font.height();
|
||||
|
||||
const auto get_color =
|
||||
[&](uint32_t x, uint32_t y) -> uint32_t
|
||||
{
|
||||
if (!use_data)
|
||||
return m_cursor_color.rgb;
|
||||
return m_cursor_data[y * cursor_w + x];
|
||||
};
|
||||
|
||||
for (uint32_t dy = 0; dy < cursor_h; dy++)
|
||||
for (uint32_t dx = 0; dx < cursor_w; dx++)
|
||||
m_framebuffer_device->set_pixel(x + dx, y + cursor_top + dy, get_color(dx, dy));
|
||||
|
@ -107,14 +100,20 @@ namespace Kernel
|
|||
if (m_cursor_shown == shown)
|
||||
return;
|
||||
m_cursor_shown = shown;
|
||||
show_cursor(!m_cursor_shown);
|
||||
|
||||
if (m_cursor_shown)
|
||||
{
|
||||
read_cursor();
|
||||
show_cursor(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
show_cursor(true);
|
||||
}
|
||||
}
|
||||
|
||||
void FramebufferTerminalDriver::set_cursor_position(uint32_t x, uint32_t y)
|
||||
{
|
||||
if (x == m_cursor_x && y == m_cursor_y)
|
||||
return;
|
||||
|
||||
if (!m_cursor_shown)
|
||||
{
|
||||
m_cursor_x = x;
|
||||
|
@ -125,6 +124,7 @@ namespace Kernel
|
|||
show_cursor(true);
|
||||
m_cursor_x = x;
|
||||
m_cursor_y = y;
|
||||
read_cursor();
|
||||
show_cursor(false);
|
||||
}
|
||||
|
||||
|
|
|
@ -215,7 +215,6 @@ namespace Kernel
|
|||
auto* ptr = reinterpret_cast<const uint8_t*>(ansi_c_str);
|
||||
while (*ptr)
|
||||
handle_input_byte(*ptr++);
|
||||
update_cursor();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -359,7 +358,6 @@ namespace Kernel
|
|||
SpinLockGuard _(m_write_lock);
|
||||
for (size_t i = 0; i < buffer.size(); i++)
|
||||
putchar(buffer[i]);
|
||||
update_cursor();
|
||||
return buffer.size();
|
||||
}
|
||||
|
||||
|
@ -368,7 +366,6 @@ namespace Kernel
|
|||
ASSERT(s_tty);
|
||||
SpinLockGuard _(s_tty->m_write_lock);
|
||||
s_tty->putchar(ch);
|
||||
s_tty->update_cursor();
|
||||
}
|
||||
|
||||
bool TTY::is_initialized()
|
||||
|
|
|
@ -357,7 +357,7 @@ namespace Kernel
|
|||
case 'l':
|
||||
if (m_ansi_state.question && m_ansi_state.nums[0] == 25)
|
||||
{
|
||||
m_cursor_shown = (ch == 'h');
|
||||
m_terminal_driver->set_cursor_shown(ch == 'h');
|
||||
return reset_ansi();
|
||||
}
|
||||
reset_ansi();
|
||||
|
@ -518,21 +518,8 @@ namespace Kernel
|
|||
}
|
||||
|
||||
putcodepoint(codepoint);
|
||||
}
|
||||
|
||||
void VirtualTTY::update_cursor()
|
||||
{
|
||||
static bool last_shown = !m_cursor_shown;
|
||||
if (m_cursor_shown != last_shown)
|
||||
m_terminal_driver->set_cursor_shown(m_cursor_shown);
|
||||
last_shown = m_cursor_shown;
|
||||
|
||||
static uint32_t last_column = -1;
|
||||
static uint32_t last_row = -1;
|
||||
if (last_column != m_column || last_row != m_row)
|
||||
m_terminal_driver->set_cursor_position(m_column, m_row);
|
||||
last_column = m_column;
|
||||
last_row = m_row;
|
||||
m_terminal_driver->set_cursor_position(m_column, m_row);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue