summaryrefslogtreecommitdiff
path: root/Libraries/LibVT
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-07-05 23:34:02 +0200
committerAndreas Kling <kling@serenityos.org>2020-07-05 23:34:02 +0200
commit0c4b0c0312e32f802103c84d5061351222ee84ec (patch)
treed7ff901e0559a1e396063928b57b3770cbd631ec /Libraries/LibVT
parente8a59ef842a5c96823b3dcba30a97f861f5bfb75 (diff)
downloadserenity-0c4b0c0312e32f802103c84d5061351222ee84ec.zip
Terminal+LibVT: Add "clear including history" action (Ctrl+Shift+K) :^)
Sometimes you just want to get rid of all your scrollback history in the terminal, and now there's a way to do that.
Diffstat (limited to 'Libraries/LibVT')
-rw-r--r--Libraries/LibVT/Terminal.cpp8
-rw-r--r--Libraries/LibVT/Terminal.h2
-rw-r--r--Libraries/LibVT/TerminalWidget.cpp11
-rw-r--r--Libraries/LibVT/TerminalWidget.h3
4 files changed, 24 insertions, 0 deletions
diff --git a/Libraries/LibVT/Terminal.cpp b/Libraries/LibVT/Terminal.cpp
index 2ae12fcb76..01adcacbd0 100644
--- a/Libraries/LibVT/Terminal.cpp
+++ b/Libraries/LibVT/Terminal.cpp
@@ -49,6 +49,14 @@ void Terminal::clear()
set_cursor(0, 0);
}
+void Terminal::clear_including_history()
+{
+ m_history.clear();
+ clear();
+
+ m_client.terminal_history_changed();
+}
+
inline bool is_valid_parameter_character(u8 ch)
{
return ch >= 0x30 && ch <= 0x3f;
diff --git a/Libraries/LibVT/Terminal.h b/Libraries/LibVT/Terminal.h
index 86de66578a..e1d565cdff 100644
--- a/Libraries/LibVT/Terminal.h
+++ b/Libraries/LibVT/Terminal.h
@@ -59,6 +59,8 @@ public:
void on_input(u8);
void clear();
+ void clear_including_history();
+
void set_size(u16 columns, u16 rows);
u16 columns() const { return m_columns; }
u16 rows() const { return m_rows; }
diff --git a/Libraries/LibVT/TerminalWidget.cpp b/Libraries/LibVT/TerminalWidget.cpp
index a73c312f8a..79e1ad67b1 100644
--- a/Libraries/LibVT/TerminalWidget.cpp
+++ b/Libraries/LibVT/TerminalWidget.cpp
@@ -133,9 +133,15 @@ TerminalWidget::TerminalWidget(int ptm_fd, bool automatic_size_policy, RefPtr<Co
paste();
});
+ m_clear_including_history_action = GUI::Action::create("Clear including history", { Mod_Ctrl | Mod_Shift, Key_K }, [this](auto&) {
+ clear_including_history();
+ });
+
m_context_menu = GUI::Menu::construct();
m_context_menu->add_action(copy_action());
m_context_menu->add_action(paste_action());
+ m_context_menu->add_separator();
+ m_context_menu->add_action(clear_including_history_action());
}
TerminalWidget::~TerminalWidget()
@@ -865,3 +871,8 @@ void TerminalWidget::did_change_font()
if (!size().is_empty())
relayout(size());
}
+
+void TerminalWidget::clear_including_history()
+{
+ m_terminal.clear_including_history();
+}
diff --git a/Libraries/LibVT/TerminalWidget.h b/Libraries/LibVT/TerminalWidget.h
index af6b91d1bf..f4d56e21d8 100644
--- a/Libraries/LibVT/TerminalWidget.h
+++ b/Libraries/LibVT/TerminalWidget.h
@@ -79,9 +79,11 @@ public:
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; }
void copy();
void paste();
+ void clear_including_history();
virtual bool accepts_focus() const override { return true; }
@@ -178,6 +180,7 @@ private:
RefPtr<GUI::Action> m_copy_action;
RefPtr<GUI::Action> m_paste_action;
+ RefPtr<GUI::Action> m_clear_including_history_action;
RefPtr<GUI::Menu> m_context_menu;
RefPtr<GUI::Menu> m_context_menu_for_hyperlink;