From 109cd096e1f01dd9fa60257f0906904726491ceb Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Sat, 9 May 2026 14:22:46 +0100 Subject: [PATCH] Use feed_child to run program --- src/Widgets/TerminalView.vala | 16 +++++++------- src/Widgets/TerminalWidget.vala | 38 +++++++-------------------------- 2 files changed, 16 insertions(+), 38 deletions(-) diff --git a/src/Widgets/TerminalView.vala b/src/Widgets/TerminalView.vala index 2750375bac..d1547df9d6 100644 --- a/src/Widgets/TerminalView.vala +++ b/src/Widgets/TerminalView.vala @@ -186,15 +186,15 @@ public class Terminal.TerminalView : Granite.Bin { selected_page = tab; - if (program.length == 0) { - /* Set up the virtual terminal */ - if (location == "") { - terminal_widget.active_shell (); - } else { - terminal_widget.active_shell (location); - } + /* Set up the virtual terminal */ + if (location == "") { + terminal_widget.active_shell (); } else { - terminal_widget.run_program (program, location); + terminal_widget.active_shell (location); + } + + if (program.length > 0) { + terminal_widget.run_program (program); } main_window.save_opened_terminals (true, true); diff --git a/src/Widgets/TerminalWidget.vala b/src/Widgets/TerminalWidget.vala index 39fe03afe1..3c9f73cedc 100644 --- a/src/Widgets/TerminalWidget.vala +++ b/src/Widgets/TerminalWidget.vala @@ -896,37 +896,15 @@ namespace Terminal { ); } - public void run_program (string _program_string, string? working_directory) { - string[]? program_with_args = null; - this.program_string = _program_string; - try { - Shell.parse_argv (program_string, out program_with_args); - } catch (Error e) { - warning (e.message); - feed ((e.message + "\r\n\r\n").data); - active_shell (working_directory); - return; - } + // Only used when command launched from command lines + // We do not send SIGINT or reset the shell as we know the shell has only + // just been created and we may need to run e.g. `conda` which sets the environment + public void run_program (string program) { + Idle.add (() => { + feed_child ((program + "\n").data); + return Source.REMOVE; + }); - this.spawn_async ( - Vte.PtyFlags.DEFAULT, - working_directory, - program_with_args, - null, - SpawnFlags.SEARCH_PATH, - null, - -1, - null, - (terminal, pid, error) => { - if (error == null) { - this.child_pid = pid; - } else { - warning (error.message); - feed ((error.message + "\r\n\r\n").data); - active_shell (working_directory); - } - } - ); } private bool try_get_foreground_pid (out int pid) {