Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Clear and Reset actions with hotkeys #778

Merged
merged 7 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,18 @@ namespace Terminal {
);
copy_last_output_menuitem.set_attribute_value ("accel", new Variant ("s", TerminalWidget.ACCELS_COPY_OUTPUT[0]));

var clear_screen_menuitem = new MenuItem (
_("Clear Screen"),
TerminalWidget.ACTION_CLEAR_SCREEN
);
clear_screen_menuitem.set_attribute_value ("accel", new Variant ("s", TerminalWidget.ACCELS_CLEAR_SCREEN[0]));

var reset_menuitem = new MenuItem (
_("Reset"),
TerminalWidget.ACTION_RESET
);
reset_menuitem.set_attribute_value ("accel", new Variant ("s", TerminalWidget.ACCELS_RESET[0]));

var paste_menuitem = new MenuItem (
_("Paste"),
TerminalWidget.ACTION_PASTE
Expand All @@ -200,6 +212,10 @@ namespace Terminal {
terminal_action_section.append_item (paste_menuitem);
terminal_action_section.append_item (select_all_menuitem);

var terminal_clear_reset_section = new Menu ();
terminal_clear_reset_section.append_item (clear_screen_menuitem);
terminal_clear_reset_section.append_item (reset_menuitem);

var search_section = new Menu ();
search_section.append_item (search_menuitem);

Expand All @@ -208,6 +224,7 @@ namespace Terminal {
context_menu_model.append_item (open_in_browser_menuitem);
context_menu_model.append_section (null, terminal_action_section);
context_menu_model.append_section (null, search_section);
context_menu_model.append_section (null, terminal_clear_reset_section);

setup_ui ();

Expand Down
39 changes: 39 additions & 0 deletions src/Widgets/TerminalWidget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ namespace Terminal {

public const string ACTION_COPY = "term.copy";
public const string ACTION_COPY_OUTPUT = "term.copy-output";
public const string ACTION_CLEAR_SCREEN = "term.clear-screen";
public const string ACTION_RESET = "term.reset";
public const string ACTION_PASTE = "term.paste";
public const string ACTION_RELOAD = "term.reload";
public const string ACTION_SCROLL_TO_COMMAND = "term.scroll-to-command";
Expand All @@ -69,8 +71,11 @@ namespace Terminal {
public const string ACTION_ZOOM_IN = "term.zoom::in";
public const string ACTION_ZOOM_OUT = "term.zoom::out";


public const string[] ACCELS_COPY = { "<Control><Shift>C", null };
public const string[] ACCELS_COPY_OUTPUT = { "<Alt>C", null };
public const string[] ACCELS_CLEAR_SCREEN = { "<Control>L", null };
public const string[] ACCELS_RESET = { "<Control>K", null };
public const string[] ACCELS_PASTE = { "<Control><Shift>V", null };
public const string[] ACCELS_RELOAD = { "<Control><Shift>R", "<Ctrl>F5", null };
public const string[] ACCELS_SCROLL_TO_COMMAND = { "<Alt>Up", null };
Expand Down Expand Up @@ -135,6 +140,8 @@ namespace Terminal {

private GLib.SimpleAction copy_action;
private GLib.SimpleAction copy_output_action;
private GLib.SimpleAction clear_screen_action;
private GLib.SimpleAction reset_action;
private GLib.SimpleAction paste_action;
private GLib.SimpleAction scroll_to_command_action;

Expand Down Expand Up @@ -268,6 +275,16 @@ namespace Terminal {
copy_output_action.activate.connect (copy_output);
action_group.add_action (copy_output_action);

clear_screen_action = new GLib.SimpleAction ("clear-screen", null);
clear_screen_action.set_enabled (true);
clear_screen_action.activate.connect (action_clear_screen);
action_group.add_action (clear_screen_action);

reset_action = new GLib.SimpleAction ("reset", null);
reset_action.set_enabled (true);
reset_action.activate.connect (action_reset);
action_group.add_action (reset_action);

paste_action = new GLib.SimpleAction ("paste", null);
paste_action.activate.connect (() => paste_clipboard.emit ());
action_group.add_action (paste_action);
Expand Down Expand Up @@ -430,6 +447,16 @@ namespace Terminal {
}
}

if (CONTROL_MASK in modifiers && match_keycode (Gdk.Key.k, keycode)) {
action_reset ();
return true;
}

if (CONTROL_MASK in modifiers && match_keycode (Gdk.Key.l, keycode)) {
action_clear_screen ();
return true;
}

if (MOD1_MASK in modifiers && keyval == Gdk.Key.Up) {
return !scroll_to_command_action.enabled;
}
Expand Down Expand Up @@ -478,6 +505,18 @@ namespace Terminal {
clipboard.set_text (output, output.length);
}

private void action_clear_screen () {
debug ("Clear screen only");
// Should we clear scrollback too?
run_program ("clear -x", null);
}

private void action_reset () {
debug ("Reset");
// This also clears the screen and the scrollback
run_program ("reset", null);
}

protected override void paste_clipboard () {
clipboard.request_text ((clipboard, text) => {
if (text == null) {
Expand Down