Skip to content

Commit

Permalink
Added the option to hide both the task and command lines in the task …
Browse files Browse the repository at this point in the history
…output
  • Loading branch information
omennia committed Nov 20, 2024
1 parent 1475a70 commit 32d8f67
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
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,
hide_task: spawn_task.hide_task,
hide_command: spawn_task.hide_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,
/// 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.
Expand Down
8 changes: 8 additions & 0 deletions crates/task/src/task_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
}),
})
}
Expand Down
17 changes: 16 additions & 1 deletion 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 hide_task: bool,
pub hide_command: bool,
}

/// A status of the current terminal tab's task.
Expand Down Expand Up @@ -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 => {
Expand Down

0 comments on commit 32d8f67

Please sign in to comment.