Extend task templates with shell
and hide
fields to use custom shells and custom close behavior (#15031)
This commit is contained in:
parent
4a43084cb7
commit
b2b9d4ccb6
15 changed files with 302 additions and 148 deletions
|
@ -39,8 +39,8 @@ use pty_info::PtyProcessInfo;
|
|||
use serde::{Deserialize, Serialize};
|
||||
use settings::Settings;
|
||||
use smol::channel::{Receiver, Sender};
|
||||
use task::TaskId;
|
||||
use terminal_settings::{AlternateScroll, Shell, TerminalBlink, TerminalSettings};
|
||||
use task::{HideStrategy, Shell, TaskId};
|
||||
use terminal_settings::{AlternateScroll, TerminalBlink, TerminalSettings};
|
||||
use theme::{ActiveTheme, Theme};
|
||||
use util::truncate_and_trailoff;
|
||||
|
||||
|
@ -612,6 +612,7 @@ pub struct TaskState {
|
|||
pub command_label: String,
|
||||
pub status: TaskStatus,
|
||||
pub completion_rx: Receiver<()>,
|
||||
pub hide: HideStrategy,
|
||||
}
|
||||
|
||||
/// A status of the current terminal tab's task.
|
||||
|
@ -1567,32 +1568,43 @@ impl Terminal {
|
|||
}
|
||||
};
|
||||
|
||||
let (task_line, command_line) = task_summary(task, error_code);
|
||||
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]) };
|
||||
match task.hide {
|
||||
HideStrategy::Never => {}
|
||||
HideStrategy::Always => {
|
||||
cx.emit(Event::CloseTerminal);
|
||||
}
|
||||
HideStrategy::OnSuccess => {
|
||||
if finished_successfully {
|
||||
cx.emit(Event::CloseTerminal);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const TASK_DELIMITER: &str = "⏵ ";
|
||||
fn task_summary(task: &TaskState, error_code: Option<i32>) -> (String, String) {
|
||||
fn task_summary(task: &TaskState, error_code: Option<i32>) -> (bool, String, String) {
|
||||
let escaped_full_label = task.full_label.replace("\r\n", "\r").replace('\n', "\r");
|
||||
let task_line = match error_code {
|
||||
let (success, task_line) = match error_code {
|
||||
Some(0) => {
|
||||
format!("{TASK_DELIMITER}Task `{escaped_full_label}` finished successfully")
|
||||
(true, format!("{TASK_DELIMITER}Task `{escaped_full_label}` finished successfully"))
|
||||
}
|
||||
Some(error_code) => {
|
||||
format!("{TASK_DELIMITER}Task `{escaped_full_label}` finished with non-zero error code: {error_code}")
|
||||
(false, format!("{TASK_DELIMITER}Task `{escaped_full_label}` finished with non-zero error code: {error_code}"))
|
||||
}
|
||||
None => {
|
||||
format!("{TASK_DELIMITER}Task `{escaped_full_label}` finished")
|
||||
(false, format!("{TASK_DELIMITER}Task `{escaped_full_label}` finished"))
|
||||
}
|
||||
};
|
||||
let escaped_command_label = task.command_label.replace("\r\n", "\r").replace('\n', "\r");
|
||||
let command_line = format!("{TASK_DELIMITER}Command: '{escaped_command_label}'");
|
||||
(task_line, command_line)
|
||||
(success, task_line, command_line)
|
||||
}
|
||||
|
||||
/// Appends a stringified task summary to the terminal, after its output.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue