mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:47:37 +00:00
LibVT: Rewrap the terminal history along with the normal buffer
This commit is contained in:
parent
4bf14715a1
commit
fcef84c461
2 changed files with 33 additions and 19 deletions
|
@ -52,8 +52,8 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CursorPosition {
|
struct CursorPosition {
|
||||||
u16 row { 0 };
|
size_t row { 0 };
|
||||||
u16 column { 0 };
|
size_t column { 0 };
|
||||||
|
|
||||||
void clamp(u16 max_row, u16 max_column)
|
void clamp(u16 max_row, u16 max_column)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1502,28 +1502,42 @@ void Terminal::set_size(u16 columns, u16 rows)
|
||||||
return old_cursor;
|
return old_cursor;
|
||||||
};
|
};
|
||||||
|
|
||||||
CursorPosition cursor_tracker { cursor_row(), cursor_column() };
|
auto old_history_size = m_history.size();
|
||||||
resize_and_rewrap(m_normal_screen_buffer, cursor_tracker);
|
m_history.extend(move(m_normal_screen_buffer));
|
||||||
if (m_normal_screen_buffer.size() > rows) {
|
CursorPosition cursor_tracker { cursor_row() + old_history_size, cursor_column() };
|
||||||
if (auto extra_lines = m_normal_screen_buffer.size() - rows) {
|
resize_and_rewrap(m_history, cursor_tracker);
|
||||||
while (extra_lines > 0) {
|
if (auto extra_lines = m_history.size() - rows) {
|
||||||
if (m_normal_screen_buffer.size() <= cursor_tracker.row)
|
while (extra_lines > 0) {
|
||||||
break;
|
if (m_history.size() <= cursor_tracker.row)
|
||||||
if (m_normal_screen_buffer.last().is_empty()) {
|
|
||||||
if (m_normal_screen_buffer[m_normal_screen_buffer.size() - 2].termination_column().has_value())
|
|
||||||
break;
|
|
||||||
--extra_lines;
|
|
||||||
m_normal_screen_buffer.take_last();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
if (m_history.last().is_empty()) {
|
||||||
|
if (m_history.size() >= 2 && m_history[m_history.size() - 2].termination_column().has_value())
|
||||||
|
break;
|
||||||
|
--extra_lines;
|
||||||
|
m_history.take_last();
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < extra_lines; ++i)
|
break;
|
||||||
m_history.append(m_normal_screen_buffer.take_first());
|
|
||||||
m_client.terminal_history_changed(extra_lines);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: This can use a more performant way to move the last N entries
|
||||||
|
// from the history into the normal buffer
|
||||||
|
m_normal_screen_buffer.ensure_capacity(rows);
|
||||||
|
while (m_normal_screen_buffer.size() < rows) {
|
||||||
|
if (!m_history.is_empty())
|
||||||
|
m_normal_screen_buffer.prepend(m_history.take_last());
|
||||||
|
else
|
||||||
|
m_normal_screen_buffer.unchecked_append(make<Line>(columns));
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor_tracker.row -= m_history.size();
|
||||||
|
|
||||||
|
if (m_history.size() != old_history_size) {
|
||||||
|
m_client.terminal_history_changed(-old_history_size);
|
||||||
|
m_client.terminal_history_changed(m_history.size());
|
||||||
|
}
|
||||||
|
|
||||||
CursorPosition dummy_cursor_tracker {};
|
CursorPosition dummy_cursor_tracker {};
|
||||||
resize_and_rewrap(m_alternate_screen_buffer, dummy_cursor_tracker);
|
resize_and_rewrap(m_alternate_screen_buffer, dummy_cursor_tracker);
|
||||||
if (m_alternate_screen_buffer.size() > rows)
|
if (m_alternate_screen_buffer.size() > rows)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue