Skip to content

Commit 2813398

Browse files
committed
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
1 parent 5d16a5f commit 2813398

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

data/gsettings/com.gexperts.Tilix.gschema.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,10 @@
12011201
<default>'disabled'</default>
12021202
<summary>Keyboard shortcut to unselect all text in terminal</summary>
12031203
</key>
1204+
<key name="terminal-clear" type="s">
1205+
<default>'disabled'</default>
1206+
<summary>Keyboard shortcut to clear the output buffer, excluding the last line, similar to how 'clear' works in a shell</summary>
1207+
</key>
12041208
<key name="terminal-zoom-in" type="s">
12051209
<default>'&lt;Ctrl&gt;plus'</default>
12061210
<summary>Keyboard shortcut to make font larger</summary>

data/resources/ui/shortcuts.ui

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,12 @@
437437
<property name="title" translatable="yes" context="shortcut window">Unselect all</property>
438438
</object>
439439
</child>
440+
<child>
441+
<object class="GtkShortcutsShortcut" id ="terminal-clear">
442+
<property name="visible">1</property>
443+
<property name="title" translatable="yes" context="shortcut window">Clear output</property>
444+
</object>
445+
</child>
440446
</object>
441447
</child>
442448
<child>

source/gx/tilix/terminal/actions.d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ enum ACTION_COPY_LINK = "copy-link";
2626
enum ACTION_OPEN_LINK = "open-link";
2727
enum ACTION_SELECT_ALL = "select-all";
2828
enum ACTION_UNSELECT_ALL = "unselect-all";
29+
enum ACTION_CLEAR = "clear";
2930
enum ACTION_ZOOM_IN = "zoom-in";
3031
enum ACTION_ZOOM_OUT = "zoom-out";
3132
enum ACTION_ZOOM_NORMAL = "zoom-normal";

source/gx/tilix/terminal/terminal.d

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,21 @@ private:
576576

577577
registerActionWithSettings(group, ACTION_PREFIX, ACTION_SELECT_ALL, gsShortcuts, delegate(GVariant, SimpleAction) { vte.selectAll(); });
578578
registerActionWithSettings(group, ACTION_PREFIX, ACTION_UNSELECT_ALL, gsShortcuts, delegate(GVariant, SimpleAction) { vte.unselectAll(); });
579+
registerActionWithSettings(group, ACTION_PREFIX, ACTION_CLEAR, gsShortcuts, delegate(GVariant, SimpleAction) {
580+
//Clear text while leaving current line intact, keeping selection and clearing scrollback buffer
581+
long totalRows = vte.getRowCount();
582+
string toFeed = "";
583+
//Move down
584+
foreach (i; 1 .. totalRows) toFeed ~= "\n";
585+
//Clear scrollback buffer
586+
toFeed ~= "\033[3J";
587+
//Move cursor up
588+
toFeed ~= format("\033[%dA", totalRows);
589+
//Remove text below current line
590+
if (totalRows > 1) toFeed ~= "\033[s\033[E\033[0J\033[u";
591+
vte.reset(true, false);
592+
vte.feed(toFeed);
593+
});
579594

580595
//Link Actions, no shortcuts, context menu only
581596
registerAction(group, ACTION_PREFIX, ACTION_COPY_LINK, null, delegate(GVariant, SimpleAction) {
@@ -1854,6 +1869,12 @@ private:
18541869

18551870
mmContext.appendItem(clipItem);
18561871
}
1872+
1873+
//Section for screen actions (clearing output)
1874+
GMenu screenSection = new GMenu();
1875+
screenSection.append(_("Clear"), getActionDetailedName(ACTION_PREFIX, ACTION_CLEAR));
1876+
mmContext.appendSection(null, screenSection);
1877+
18571878
//Check if titlebar is hidden and add extra items
18581879
if (!bTitle.isVisible()) {
18591880
GMenu windowSection = new GMenu();

0 commit comments

Comments
 (0)