From 2813398593436119d04d15bd0ebe46397ae91831 Mon Sep 17 00:00:00 2001
From: algiuxass <33424336+algj@users.noreply.github.com>
Date: Mon, 29 Jul 2024 01:32:59 +0300
Subject: [PATCH] Clear output action
Clear text while leaving current line intact, keeping selection and clearing scrollback buffer. Appears in shortcut list in `Terminal -> Clear output` and right-click menu as `Clear`.
Update terminal.d
---
data/gsettings/com.gexperts.Tilix.gschema.xml | 4 ++++
data/resources/ui/shortcuts.ui | 6 ++++++
source/gx/tilix/terminal/actions.d | 1 +
source/gx/tilix/terminal/terminal.d | 21 +++++++++++++++++++
4 files changed, 32 insertions(+)
diff --git a/data/gsettings/com.gexperts.Tilix.gschema.xml b/data/gsettings/com.gexperts.Tilix.gschema.xml
index bcf4cff75..ba31e4182 100644
--- a/data/gsettings/com.gexperts.Tilix.gschema.xml
+++ b/data/gsettings/com.gexperts.Tilix.gschema.xml
@@ -1201,6 +1201,10 @@
'disabled'
Keyboard shortcut to unselect all text in terminal
+
+ 'disabled'
+ Keyboard shortcut to clear the output buffer, excluding the last line, similar to how 'clear' works in a shell
+
'<Ctrl>plus'
Keyboard shortcut to make font larger
diff --git a/data/resources/ui/shortcuts.ui b/data/resources/ui/shortcuts.ui
index 912f91a47..3cf205f61 100644
--- a/data/resources/ui/shortcuts.ui
+++ b/data/resources/ui/shortcuts.ui
@@ -437,6 +437,12 @@
Unselect all
+
+
+
diff --git a/source/gx/tilix/terminal/actions.d b/source/gx/tilix/terminal/actions.d
index 4fd5eaf3e..2fa5c5812 100644
--- a/source/gx/tilix/terminal/actions.d
+++ b/source/gx/tilix/terminal/actions.d
@@ -26,6 +26,7 @@ enum ACTION_COPY_LINK = "copy-link";
enum ACTION_OPEN_LINK = "open-link";
enum ACTION_SELECT_ALL = "select-all";
enum ACTION_UNSELECT_ALL = "unselect-all";
+enum ACTION_CLEAR = "clear";
enum ACTION_ZOOM_IN = "zoom-in";
enum ACTION_ZOOM_OUT = "zoom-out";
enum ACTION_ZOOM_NORMAL = "zoom-normal";
diff --git a/source/gx/tilix/terminal/terminal.d b/source/gx/tilix/terminal/terminal.d
index 01f920866..861689768 100644
--- a/source/gx/tilix/terminal/terminal.d
+++ b/source/gx/tilix/terminal/terminal.d
@@ -576,6 +576,21 @@ private:
registerActionWithSettings(group, ACTION_PREFIX, ACTION_SELECT_ALL, gsShortcuts, delegate(GVariant, SimpleAction) { vte.selectAll(); });
registerActionWithSettings(group, ACTION_PREFIX, ACTION_UNSELECT_ALL, gsShortcuts, delegate(GVariant, SimpleAction) { vte.unselectAll(); });
+ registerActionWithSettings(group, ACTION_PREFIX, ACTION_CLEAR, gsShortcuts, delegate(GVariant, SimpleAction) {
+ //Clear text while leaving current line intact, keeping selection and clearing scrollback buffer
+ long totalRows = vte.getRowCount();
+ string toFeed = "";
+ //Move down
+ foreach (i; 1 .. totalRows) toFeed ~= "\n";
+ //Clear scrollback buffer
+ toFeed ~= "\033[3J";
+ //Move cursor up
+ toFeed ~= format("\033[%dA", totalRows);
+ //Remove text below current line
+ if (totalRows > 1) toFeed ~= "\033[s\033[E\033[0J\033[u";
+ vte.reset(true, false);
+ vte.feed(toFeed);
+ });
//Link Actions, no shortcuts, context menu only
registerAction(group, ACTION_PREFIX, ACTION_COPY_LINK, null, delegate(GVariant, SimpleAction) {
@@ -1854,6 +1869,12 @@ private:
mmContext.appendItem(clipItem);
}
+
+ //Section for screen actions (clearing output)
+ GMenu screenSection = new GMenu();
+ screenSection.append(_("Clear"), getActionDetailedName(ACTION_PREFIX, ACTION_CLEAR));
+ mmContext.appendSection(null, screenSection);
+
//Check if titlebar is hidden and add extra items
if (!bTitle.isVisible()) {
GMenu windowSection = new GMenu();