Skip to content

Commit

Permalink
Add the option to hide both the task and command lines in the task ou…
Browse files Browse the repository at this point in the history
…tput (zed-industries#20920)

The goal is to be able to hide these lines from a task output:

```sh
⏵ Task `...` finished successfully
⏵ Command: ...
```

---------

Co-authored-by: Peter Tripp <peter@zed.dev>
  • Loading branch information
2 people authored and Anthony-Eid committed Nov 22, 2024
1 parent 5da39b3 commit 78b4ba4
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 6 deletions.
2 changes: 2 additions & 0 deletions crates/project/src/terminals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ impl Project {
command_label: spawn_task.command_label,
hide: spawn_task.hide,
status: TaskStatus::Running,
show_summary: spawn_task.show_summary,
show_command: spawn_task.show_command,
completion_rx,
});

Expand Down
4 changes: 4 additions & 0 deletions crates/task/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ pub struct SpawnInTerminal {
pub hide: HideStrategy,
/// Which shell to use when spawning the task.
pub shell: Shell,
/// Whether to show the task summary line in the task output (sucess/failure).
pub show_summary: bool,
/// Whether to show the command line in the task output.
pub show_command: bool,
}

/// A final form of the [`TaskTemplate`], that got resolved with a particualar [`TaskContext`] and now is ready to spawn the actual task.
Expand Down
9 changes: 9 additions & 0 deletions crates/task/src/task_template.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::path::PathBuf;
use util::serde::default_true;

use anyhow::{bail, Context};
use collections::{HashMap, HashSet};
Expand Down Expand Up @@ -57,6 +58,12 @@ pub struct TaskTemplate {
/// Which shell to use when spawning the task.
#[serde(default)]
pub shell: Shell,
/// Whether to show the task line in the task output.
#[serde(default = "default_true")]
pub show_summary: bool,
/// Whether to show the command line in the task output.
#[serde(default = "default_true")]
pub show_command: bool,
}

/// What to do with the terminal pane and tab, after the command was started.
Expand Down Expand Up @@ -230,6 +237,8 @@ impl TaskTemplate {
reveal: self.reveal,
hide: self.hide,
shell: self.shell.clone(),
show_summary: self.show_summary,
show_command: self.show_command,
}),
})
}
Expand Down
23 changes: 18 additions & 5 deletions crates/terminal/src/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,8 @@ pub struct TaskState {
pub status: TaskStatus,
pub completion_rx: Receiver<()>,
pub hide: HideStrategy,
pub show_summary: bool,
pub show_command: bool,
}

/// A status of the current terminal tab's task.
Expand Down Expand Up @@ -1760,11 +1762,22 @@ impl Terminal {
};

let (finished_successfully, task_line, command_line) = task_summary(task, error_code);
// 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]) };
let mut lines_to_show = Vec::new();
if task.show_summary {
lines_to_show.push(task_line.as_str());
}
if task.show_command {
lines_to_show.push(command_line.as_str());
}

if !lines_to_show.is_empty() {
// 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(), &lines_to_show) };
}

match task.hide {
HideStrategy::Never => {}
HideStrategy::Always => {
Expand Down
6 changes: 5 additions & 1 deletion docs/src/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ Zed supports ways to spawn (and rerun) commands using its integrated terminal to
// "args": ["--login"]
// }
// }
"shell": "system"
"shell": "system",
// Whether to show the task line in the output of the spawned task, defaults to `true`.
"show_summary": true,
// Whether to show the command line in the output of the spawned task, defaults to `true`.
"show_output": true
}
]
```
Expand Down

0 comments on commit 78b4ba4

Please sign in to comment.