From 32d8f67082d33f30bb34c577857e629f2c9aa3e5 Mon Sep 17 00:00:00 2001 From: Hugo Cardante Date: Wed, 20 Nov 2024 18:23:19 +0000 Subject: [PATCH] Added the option to hide both the task and command lines in the task output --- crates/project/src/terminals.rs | 2 ++ crates/task/src/lib.rs | 4 ++++ crates/task/src/task_template.rs | 8 ++++++++ crates/terminal/src/terminal.rs | 17 ++++++++++++++++- 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/crates/project/src/terminals.rs b/crates/project/src/terminals.rs index 1320a883f3a0e..062acab25a091 100644 --- a/crates/project/src/terminals.rs +++ b/crates/project/src/terminals.rs @@ -174,6 +174,8 @@ impl Project { command_label: spawn_task.command_label, hide: spawn_task.hide, status: TaskStatus::Running, + hide_task: spawn_task.hide_task, + hide_command: spawn_task.hide_command, completion_rx, }); diff --git a/crates/task/src/lib.rs b/crates/task/src/lib.rs index 534b77b743427..4419b17d05ad0 100644 --- a/crates/task/src/lib.rs +++ b/crates/task/src/lib.rs @@ -51,6 +51,10 @@ pub struct SpawnInTerminal { pub hide: HideStrategy, /// Which shell to use when spawning the task. pub shell: Shell, + /// Wether to hide the task line in the task output. + pub hide_task: bool, + /// Weather to hide the command line in the task output. + pub hide_command: bool, } /// A final form of the [`TaskTemplate`], that got resolved with a particualar [`TaskContext`] and now is ready to spawn the actual task. diff --git a/crates/task/src/task_template.rs b/crates/task/src/task_template.rs index b72a0d25f8b65..b455d43945cba 100644 --- a/crates/task/src/task_template.rs +++ b/crates/task/src/task_template.rs @@ -57,6 +57,12 @@ pub struct TaskTemplate { /// Which shell to use when spawning the task. #[serde(default)] pub shell: Shell, + /// Wether to hide the task line in the task output. + #[serde(default)] + pub hide_task: bool, + /// Weather to hide the command line in the task output. + #[serde(default)] + pub hide_command: bool, } /// What to do with the terminal pane and tab, after the command was started. @@ -230,6 +236,8 @@ impl TaskTemplate { reveal: self.reveal, hide: self.hide, shell: self.shell.clone(), + hide_task: !self.hide_task, + hide_command: !self.hide_command, }), }) } diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs index 5a15723cee380..24e1f408c5fb4 100644 --- a/crates/terminal/src/terminal.rs +++ b/crates/terminal/src/terminal.rs @@ -639,6 +639,8 @@ pub struct TaskState { pub status: TaskStatus, pub completion_rx: Receiver<()>, pub hide: HideStrategy, + pub hide_task: bool, + pub hide_command: bool, } /// A status of the current terminal tab's task. @@ -1760,11 +1762,24 @@ impl Terminal { }; let (finished_successfully, task_line, command_line) = task_summary(task, error_code); + // Decide whether to display the task and/or command lines based on user preferences. + let mut lines_to_show = Vec::new(); + if task.hide_task { + lines_to_show.push(task_line.as_str()); + } + if task.hide_command { + lines_to_show.push(command_line.as_str()); + } + // SAFETY: the invocation happens on non `TaskStatus::Running` tasks, once, // after either `AlacTermEvent::Exit` or `AlacTermEvent::ChildExit` events that are spawned // when Zed task finishes and no more output is made. // After the task summary is output once, no more text is appended to the terminal. - unsafe { append_text_to_term(&mut self.term.lock(), &[&task_line, &command_line]) }; + // Only append text if there are lines to show + if !lines_to_show.is_empty() { + unsafe { append_text_to_term(&mut self.term.lock(), &lines_to_show) }; + } + match task.hide { HideStrategy::Never => {} HideStrategy::Always => {