Add task docs and default keybindings (#8123)

Also group task source modules together

Release Notes:

- N/A

---------

Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com>
This commit is contained in:
Kirill Bulatov 2024-02-21 16:43:56 +02:00 committed by GitHub
parent b9151b9506
commit 0c939e5dfc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 84 additions and 64 deletions

View file

@ -12,9 +12,53 @@ use schemars::{gen::SchemaSettings, JsonSchema};
use serde::{Deserialize, Serialize};
use util::ResultExt;
use crate::{Source, StaticTask, Task};
use crate::{Source, SpawnInTerminal, Task, TaskId};
use futures::channel::mpsc::UnboundedReceiver;
/// A single config file entry with the deserialized task definition.
#[derive(Clone, Debug, PartialEq)]
struct StaticTask {
id: TaskId,
definition: Definition,
}
impl StaticTask {
pub(super) fn new(id: usize, task_definition: Definition) -> Self {
Self {
id: TaskId(format!("static_{}_{}", task_definition.label, id)),
definition: task_definition,
}
}
}
impl Task for StaticTask {
fn exec(&self, cwd: Option<PathBuf>) -> Option<SpawnInTerminal> {
Some(SpawnInTerminal {
id: self.id.clone(),
cwd,
use_new_terminal: self.definition.use_new_terminal,
allow_concurrent_runs: self.definition.allow_concurrent_runs,
label: self.definition.label.clone(),
command: self.definition.command.clone(),
args: self.definition.args.clone(),
env: self.definition.env.clone(),
separate_shell: false,
})
}
fn name(&self) -> &str {
&self.definition.label
}
fn id(&self) -> &TaskId {
&self.id
}
fn cwd(&self) -> Option<&Path> {
self.definition.cwd.as_deref()
}
}
/// The source of tasks defined in a tasks config file.
pub struct StaticSource {
tasks: Vec<StaticTask>,