diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2020-11-29 17:56:02 +0330 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-11-29 20:32:45 +0100 |
commit | 5c8b48053e047a4254929b95289d69a9bf578bd2 (patch) | |
tree | 12c63ad9bdd355657917101f8973058381611bec /Libraries/LibVT | |
parent | 158fe9d9ca17b6dcbd62cad5c2824ab9a31cd972 (diff) | |
download | serenity-5c8b48053e047a4254929b95289d69a9bf578bd2.zip |
LibVT: Make terminal scrollback max size configurable
Diffstat (limited to 'Libraries/LibVT')
-rw-r--r-- | Libraries/LibVT/Terminal.h | 30 | ||||
-rw-r--r-- | Libraries/LibVT/TerminalWidget.h | 3 |
2 files changed, 32 insertions, 1 deletions
diff --git a/Libraries/LibVT/Terminal.h b/Libraries/LibVT/Terminal.h index 091fd34f4b..f74459806e 100644 --- a/Libraries/LibVT/Terminal.h +++ b/Libraries/LibVT/Terminal.h @@ -93,7 +93,31 @@ public: return m_lines[index]; } - size_t max_history_size() const { return 500; } + size_t max_history_size() const { return m_max_history_lines; } + void set_max_history_size(size_t value) + { + if (value == 0) { + m_max_history_lines = 0; + m_history_start = 0; + m_history.clear(); + m_client.terminal_history_changed(); + return; + } + + if (m_max_history_lines > value) { + NonnullOwnPtrVector<Line> new_history; + new_history.ensure_capacity(value); + auto existing_line_count = min(m_history.size(), value); + for (size_t i = m_history.size() - existing_line_count; i < m_history.size(); ++i) { + auto j = (m_history_start + i) % m_history.size(); + new_history.unchecked_append(move(static_cast<Vector<NonnullOwnPtr<Line>>&>(m_history).at(j))); + } + m_history = move(new_history); + m_history_start = 0; + m_client.terminal_history_changed(); + } + m_max_history_lines = value; + } size_t history_size() const { return m_history.size(); } void inject_string(const StringView&); @@ -156,6 +180,9 @@ private: NonnullOwnPtrVector<Line> m_history; void add_line_to_history(NonnullOwnPtr<Line>&& line) { + if (max_history_size() == 0) + return; + if (m_history.size() < max_history_size()) { ASSERT(m_history_start == 0); m_history.append(move(line)); @@ -210,6 +237,7 @@ private: Vector<bool> m_horizontal_tabs; u8 m_final { 0 }; u32 m_last_code_point { 0 }; + size_t m_max_history_lines { 1024 }; }; } diff --git a/Libraries/LibVT/TerminalWidget.h b/Libraries/LibVT/TerminalWidget.h index 3d6ce15f6e..0c869156f2 100644 --- a/Libraries/LibVT/TerminalWidget.h +++ b/Libraries/LibVT/TerminalWidget.h @@ -79,6 +79,9 @@ public: int scroll_length() const; void set_scroll_length(int); + size_t max_history_size() const { return m_terminal.max_history_size(); } + void set_max_history_size(size_t value) { m_terminal.set_max_history_size(value); } + GUI::Action& copy_action() { return *m_copy_action; } GUI::Action& paste_action() { return *m_paste_action; } GUI::Action& clear_including_history_action() { return *m_clear_including_history_action; } |