Skip to content

Commit 0dde465

Browse files
authored
Restart shell in terminal pane if it exits (#1618)
Fixes #457 There was already code to hide the terminal if it's child exited but it had regressed and was not working. This PR makes the terminal hide again if the shell exits. It also restarts the shell at the last saved location and clears the screen ready for it to be used again. To enable this, the shell location is saved to settings every time it changes through app action instead of just at closing the app. (NOTE: Change of location through the shell cd command is not detected so not saved)
1 parent ed33fe2 commit 0dde465

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/Widgets/Terminal.vala

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ public class Code.Terminal : Gtk.Box {
4444
}
4545

4646
terminal.child_exited.connect (() => {
47-
GLib.Application.get_default ().activate_action (Scratch.MainWindow.ACTION_PREFIX + Scratch.MainWindow.ACTION_TOGGLE_TERMINAL, null);
47+
//Hide the exited terminal
48+
var win_group = get_action_group (Scratch.MainWindow.ACTION_GROUP);
49+
win_group.activate_action (Scratch.MainWindow.ACTION_TOGGLE_TERMINAL, null);
50+
//Get ready to resume at last saved location
51+
spawn_shell (Scratch.saved_state.get_string ("last-opened-path"));
52+
//Clear screen of new shell
53+
terminal.feed_child ("clear -x\n".data);
4854
});
4955

5056
var copy_action = new SimpleAction (ACTION_COPY, null);
@@ -89,16 +95,15 @@ public class Code.Terminal : Gtk.Box {
8995
copy_action.set_enabled (terminal.get_has_selection ());
9096
});
9197

92-
var settings = new Settings (Constants.PROJECT_NAME + ".saved-state");
93-
spawn_shell (settings.get_string ("last-opened-path"));
98+
spawn_shell (Scratch.saved_state.get_string ("last-opened-path"));
9499

95100
var scrolled_window = new Gtk.ScrolledWindow (null, terminal.get_vadjustment ());
96101
scrolled_window.add (terminal);
97102

98103
add (scrolled_window);
99104

100105
destroy.connect (() => {
101-
settings.set_string ("last-opened-path", get_shell_location ());
106+
Scratch.saved_state.set_string ("last-opened-path", get_shell_location ());
102107
});
103108

104109
show_all ();
@@ -125,6 +130,7 @@ public class Code.Terminal : Gtk.Box {
125130
Posix.kill (child_pid, Posix.Signal.TERM);
126131
terminal.reset (true, true);
127132
spawn_shell (dir);
133+
Scratch.saved_state.set_string ("last-opened-path", dir);
128134
}
129135

130136
private string get_shell_location () {

0 commit comments

Comments
 (0)