Skip to content

Commit

Permalink
Clear output action
Browse files Browse the repository at this point in the history
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
  • Loading branch information
algj committed Jul 28, 2024
1 parent 5d16a5f commit 2813398
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions data/gsettings/com.gexperts.Tilix.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,10 @@
<default>'disabled'</default>
<summary>Keyboard shortcut to unselect all text in terminal</summary>
</key>
<key name="terminal-clear" type="s">
<default>'disabled'</default>
<summary>Keyboard shortcut to clear the output buffer, excluding the last line, similar to how 'clear' works in a shell</summary>
</key>
<key name="terminal-zoom-in" type="s">
<default>'&lt;Ctrl&gt;plus'</default>
<summary>Keyboard shortcut to make font larger</summary>
Expand Down
6 changes: 6 additions & 0 deletions data/resources/ui/shortcuts.ui
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,12 @@
<property name="title" translatable="yes" context="shortcut window">Unselect all</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut" id ="terminal-clear">
<property name="visible">1</property>
<property name="title" translatable="yes" context="shortcut window">Clear output</property>
</object>
</child>
</object>
</child>
<child>
Expand Down
1 change: 1 addition & 0 deletions source/gx/tilix/terminal/actions.d
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
21 changes: 21 additions & 0 deletions source/gx/tilix/terminal/terminal.d
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 2813398

Please sign in to comment.