LibVT: Add scrollback history to VT::Terminal

The default (hard-coded) history size is 500 lines. When the history is
altered, the TerminalClient is notified via terminal_history_changed().
This commit is contained in:
Andreas Kling 2019-08-19 19:07:52 +02:00
parent a5cdd0afa5
commit 462336ed49
Notes: sideshowbarker 2024-07-19 12:35:37 +09:00
2 changed files with 12 additions and 0 deletions

View file

@ -666,6 +666,13 @@ void Terminal::scroll_up()
{
// NOTE: We have to invalidate the cursor first.
invalidate_cursor();
if (m_scroll_region_top == 0) {
auto line = move(m_lines.ptr_at(m_scroll_region_top));
m_history.append(move(line));
while (m_history.size() > max_history_size())
m_history.take_first();
m_client.terminal_history_changed();
}
m_lines.remove(m_scroll_region_top);
m_lines.insert(m_scroll_region_bottom, make<Line>(m_columns));
m_need_full_flush = true;

View file

@ -14,6 +14,7 @@ public:
virtual void beep() = 0;
virtual void set_window_title(const StringView&) = 0;
virtual void terminal_did_resize(u16 columns, u16 rows) = 0;
virtual void terminal_history_changed() = 0;
};
struct Attribute {
@ -98,6 +99,9 @@ public:
return m_lines[index];
}
int max_history_size() const { return 500; }
const NonnullOwnPtrVector<Line>& history() const { return m_history; }
private:
typedef Vector<unsigned, 4> ParamVector;
@ -137,6 +141,7 @@ private:
TerminalClient& m_client;
NonnullOwnPtrVector<Line> m_history;
NonnullOwnPtrVector<Line> m_lines;
int m_scroll_region_top { 0 };