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
|
@ -7,12 +7,13 @@ mod vscode_format;
|
|||
|
||||
use collections::{hash_map, HashMap, HashSet};
|
||||
use gpui::SharedString;
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
use std::{borrow::Cow, path::Path};
|
||||
|
||||
pub use task_template::{RevealStrategy, TaskTemplate, TaskTemplates};
|
||||
pub use task_template::{HideStrategy, RevealStrategy, TaskTemplate, TaskTemplates};
|
||||
pub use vscode_format::VsCodeTaskFile;
|
||||
|
||||
/// Task identifier, unique within the application.
|
||||
|
@ -78,6 +79,10 @@ pub struct SpawnInTerminal {
|
|||
pub allow_concurrent_runs: bool,
|
||||
/// What to do with the terminal pane and tab, after the command was started.
|
||||
pub reveal: RevealStrategy,
|
||||
/// What to do with the terminal pane and tab, after the command had finished.
|
||||
pub hide: HideStrategy,
|
||||
/// Which shell to use when spawning the task.
|
||||
pub shell: Shell,
|
||||
}
|
||||
|
||||
/// A final form of the [`TaskTemplate`], that got resolved with a particualar [`TaskContext`] and now is ready to spawn the actual task.
|
||||
|
@ -271,3 +276,21 @@ pub struct TaskContext {
|
|||
/// This is a new type representing a 'tag' on a 'runnable symbol', typically a test of main() function, found via treesitter.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RunnableTag(pub SharedString);
|
||||
|
||||
/// Shell configuration to open the terminal with.
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum Shell {
|
||||
/// Use the system's default terminal configuration in /etc/passwd
|
||||
#[default]
|
||||
System,
|
||||
/// Use a specific program with no arguments.
|
||||
Program(String),
|
||||
/// Use a specific program with arguments.
|
||||
WithArguments {
|
||||
/// The program to run.
|
||||
program: String,
|
||||
/// The arguments to pass to the program.
|
||||
args: Vec<String>,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ use sha2::{Digest, Sha256};
|
|||
use util::{truncate_and_remove_front, ResultExt};
|
||||
|
||||
use crate::{
|
||||
ResolvedTask, SpawnInTerminal, TaskContext, TaskId, TerminalWorkDir, VariableName,
|
||||
ResolvedTask, Shell, SpawnInTerminal, TaskContext, TaskId, TerminalWorkDir, VariableName,
|
||||
ZED_VARIABLE_NAME_PREFIX,
|
||||
};
|
||||
|
||||
|
@ -45,10 +45,18 @@ pub struct TaskTemplate {
|
|||
/// * `never` — avoid changing current terminal pane focus, but still add/reuse the task's tab there
|
||||
#[serde(default)]
|
||||
pub reveal: RevealStrategy,
|
||||
|
||||
/// What to do with the terminal pane and tab, after the command had finished:
|
||||
/// * `never` — do nothing when the command finishes (default)
|
||||
/// * `always` — always hide the terminal tab, hide the pane also if it was the last tab in it
|
||||
/// * `on_success` — hide the terminal tab on task success only, otherwise behaves similar to `always`.
|
||||
#[serde(default)]
|
||||
pub hide: HideStrategy,
|
||||
/// Represents the tags which this template attaches to. Adding this removes this task from other UI.
|
||||
#[serde(default)]
|
||||
pub tags: Vec<String>,
|
||||
/// Which shell to use when spawning the task.
|
||||
#[serde(default)]
|
||||
pub shell: Shell,
|
||||
}
|
||||
|
||||
/// What to do with the terminal pane and tab, after the command was started.
|
||||
|
@ -62,6 +70,19 @@ pub enum RevealStrategy {
|
|||
Never,
|
||||
}
|
||||
|
||||
/// What to do with the terminal pane and tab, after the command has finished.
|
||||
#[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum HideStrategy {
|
||||
/// Do nothing when the command finishes.
|
||||
#[default]
|
||||
Never,
|
||||
/// Always hide the terminal tab, hide the pane also if it was the last tab in it.
|
||||
Always,
|
||||
/// Hide the terminal tab on task success only, otherwise behaves similar to `Always`.
|
||||
OnSuccess,
|
||||
}
|
||||
|
||||
/// A group of Tasks defined in a JSON file.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct TaskTemplates(pub Vec<TaskTemplate>);
|
||||
|
@ -194,6 +215,8 @@ impl TaskTemplate {
|
|||
use_new_terminal: self.use_new_terminal,
|
||||
allow_concurrent_runs: self.allow_concurrent_runs,
|
||||
reveal: self.reveal,
|
||||
hide: self.hide,
|
||||
shell: self.shell.clone(),
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue