From 462336ed495b653e96c568acb66c638c47b0358e Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 19 Aug 2019 19:07:52 +0200 Subject: [PATCH] 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(). --- Libraries/LibVT/Terminal.cpp | 7 +++++++ Libraries/LibVT/Terminal.h | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/Libraries/LibVT/Terminal.cpp b/Libraries/LibVT/Terminal.cpp index 4b2cd501f8d..afbe8d4ab6e 100644 --- a/Libraries/LibVT/Terminal.cpp +++ b/Libraries/LibVT/Terminal.cpp @@ -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(m_columns)); m_need_full_flush = true; diff --git a/Libraries/LibVT/Terminal.h b/Libraries/LibVT/Terminal.h index f52eda5e2a4..d6bf5e736b9 100644 --- a/Libraries/LibVT/Terminal.h +++ b/Libraries/LibVT/Terminal.h @@ -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& history() const { return m_history; } + private: typedef Vector ParamVector; @@ -137,6 +141,7 @@ private: TerminalClient& m_client; + NonnullOwnPtrVector m_history; NonnullOwnPtrVector m_lines; int m_scroll_region_top { 0 };