1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-12-05 03:13:14 +00:00

feat(quarto): Add Quarto module (#5820)

Add Quarto module

* Adapted from the Typst module
This commit is contained in:
Virgile Andreani 2024-03-20 17:50:12 -04:00 committed by GitHub
parent d879317d51
commit 0e49f04a6b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 253 additions and 0 deletions

View File

@ -1365,6 +1365,27 @@
} }
] ]
}, },
"quarto": {
"default": {
"detect_extensions": [
"qmd"
],
"detect_files": [
"_quarto.yml"
],
"detect_folders": [],
"disabled": false,
"format": "via [$symbol($version )]($style)",
"style": "bold #75AADB",
"symbol": "⨁ ",
"version_format": "v${raw}"
},
"allOf": [
{
"$ref": "#/definitions/QuartoConfig"
}
]
},
"raku": { "raku": {
"default": { "default": {
"detect_extensions": [ "detect_extensions": [
@ -5046,6 +5067,57 @@
} }
] ]
}, },
"QuartoConfig": {
"type": "object",
"properties": {
"format": {
"default": "via [$symbol($version )]($style)",
"type": "string"
},
"version_format": {
"default": "v${raw}",
"type": "string"
},
"symbol": {
"default": "⨁ ",
"type": "string"
},
"style": {
"default": "bold #75AADB",
"type": "string"
},
"disabled": {
"default": false,
"type": "boolean"
},
"detect_extensions": {
"default": [
"qmd"
],
"type": "array",
"items": {
"type": "string"
}
},
"detect_files": {
"default": [
"_quarto.yml"
],
"type": "array",
"items": {
"type": "string"
}
},
"detect_folders": {
"default": [],
"type": "array",
"items": {
"type": "string"
}
}
},
"additionalProperties": false
},
"RakuConfig": { "RakuConfig": {
"type": "object", "type": "object",
"properties": { "properties": {

View File

@ -314,6 +314,7 @@ $php\
$pulumi\ $pulumi\
$purescript\ $purescript\
$python\ $python\
$quarto\
$raku\ $raku\
$rlang\ $rlang\
$red\ $red\
@ -3590,6 +3591,38 @@ python_binary = 'python3'
detect_extensions = [] detect_extensions = []
``` ```
## Quarto
The `quarto` module shows the current installed version of Quarto used in a project.
By default, the module will be shown if any of the following conditions are met:
- The current directory contains a `_quarto.yml` file
- The current directory contains any `*.qmd` file
### Options
| Option | Default | Description |
| ------------------- | ------------------------------------ | ------------------------------------------------------------------------- |
| `format` | `'via [$symbol($version )]($style)'` | The format for the module. |
| `version_format` | `'v${raw}'` | The version format. Available vars are `raw`, `major`, `minor`, & `patch` |
| `symbol` | `'⨁ '` | A format string representing the symbol of Quarto |
| `style` | `'bold #75AADB'` | The style for the module. |
| `detect_extensions` | `['.qmd']` | Which extensions should trigger this module. |
| `detect_files` | `['_quarto.yml']` | Which filenames should trigger this module. |
| `detect_folders` | `[]` | Which folders should trigger this module. |
| `disabled` | `false` | Disables the `quarto` module. |
### Variables
| Variable | Example | Description |
| -------- | --------- | ------------------------------------ |
| version | `1.4.549` | The version of `quarto` |
| symbol | | Mirrors the value of option `symbol` |
| style\* | | Mirrors the value of option `style` |
*: This variable can only be used as a part of a style string
## R ## R
The `rlang` module shows the currently installed version of [R](https://www.r-project.org/). The module will be shown if The `rlang` module shows the currently installed version of [R](https://www.r-project.org/). The module will be shown if

View File

@ -87,6 +87,9 @@ format = '(via [$symbol($version )]($style))'
[python] [python]
format = '(via [${symbol}${pyenv_prefix}(${version} )(\($virtualenv\) )]($style))' format = '(via [${symbol}${pyenv_prefix}(${version} )(\($virtualenv\) )]($style))'
[quarto]
format = '(via [$symbol($version )]($style))'
[raku] [raku]
format = '(via [$symbol($version-$vm_version )]($style))' format = '(via [$symbol($version-$vm_version )]($style))'

View File

@ -91,6 +91,9 @@ format = 'via [$symbol]($style)'
[python] [python]
format = 'via [$symbol]($style)' format = 'via [$symbol]($style)'
[quarto]
format = 'via [$symbol]($style)'
[raku] [raku]
format = 'via [$symbol]($style)' format = 'via [$symbol]($style)'

View File

@ -182,6 +182,9 @@ symbol = "purs "
[python] [python]
symbol = "py " symbol = "py "
[quarto]
symbol = "quarto "
[raku] [raku]
symbol = "raku " symbol = "raku "

View File

@ -68,6 +68,7 @@ pub mod pijul_channel;
pub mod pulumi; pub mod pulumi;
pub mod purescript; pub mod purescript;
pub mod python; pub mod python;
pub mod quarto;
pub mod raku; pub mod raku;
pub mod red; pub mod red;
pub mod rlang; pub mod rlang;
@ -241,6 +242,8 @@ pub struct FullConfig<'a> {
#[serde(borrow)] #[serde(borrow)]
python: python::PythonConfig<'a>, python: python::PythonConfig<'a>,
#[serde(borrow)] #[serde(borrow)]
quarto: quarto::QuartoConfig<'a>,
#[serde(borrow)]
raku: raku::RakuConfig<'a>, raku: raku::RakuConfig<'a>,
#[serde(borrow)] #[serde(borrow)]
red: red::RedConfig<'a>, red: red::RedConfig<'a>,

34
src/configs/quarto.rs Normal file
View File

@ -0,0 +1,34 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(
feature = "config-schema",
derive(schemars::JsonSchema),
schemars(deny_unknown_fields)
)]
#[serde(default)]
pub struct QuartoConfig<'a> {
pub format: &'a str,
pub version_format: &'a str,
pub symbol: &'a str,
pub style: &'a str,
pub disabled: bool,
pub detect_extensions: Vec<&'a str>,
pub detect_files: Vec<&'a str>,
pub detect_folders: Vec<&'a str>,
}
impl<'a> Default for QuartoConfig<'a> {
fn default() -> Self {
QuartoConfig {
format: "via [$symbol($version )]($style)",
version_format: "v${raw}",
symbol: "",
style: "bold #75AADB",
disabled: false,
detect_extensions: vec!["qmd"],
detect_files: vec!["_quarto.yml"],
detect_folders: vec![],
}
}
}

View File

@ -82,6 +82,7 @@ pub const PROMPT_ORDER: &[&str] = &[
"pulumi", "pulumi",
"purescript", "purescript",
"python", "python",
"quarto",
"raku", "raku",
"rlang", "rlang",
"red", "red",

View File

@ -75,6 +75,7 @@ pub const ALL_MODULES: &[&str] = &[
"pulumi", "pulumi",
"purescript", "purescript",
"python", "python",
"quarto",
"raku", "raku",
"red", "red",
"rlang", "rlang",

View File

@ -65,6 +65,7 @@ mod pijul_channel;
mod pulumi; mod pulumi;
mod purescript; mod purescript;
mod python; mod python;
mod quarto;
mod raku; mod raku;
mod red; mod red;
mod rlang; mod rlang;
@ -172,6 +173,7 @@ pub fn handle<'a>(module: &str, context: &'a Context) -> Option<Module<'a>> {
"pulumi" => pulumi::module(context), "pulumi" => pulumi::module(context),
"purescript" => purescript::module(context), "purescript" => purescript::module(context),
"python" => python::module(context), "python" => python::module(context),
"quarto" => quarto::module(context),
"raku" => raku::module(context), "raku" => raku::module(context),
"rlang" => rlang::module(context), "rlang" => rlang::module(context),
"red" => red::module(context), "red" => red::module(context),
@ -292,6 +294,7 @@ pub fn description(module: &str) -> &'static str {
"pulumi" => "The current username, stack, and installed version of Pulumi", "pulumi" => "The current username, stack, and installed version of Pulumi",
"purescript" => "The currently installed version of PureScript", "purescript" => "The currently installed version of PureScript",
"python" => "The currently installed version of Python", "python" => "The currently installed version of Python",
"quarto" => "The current installed version of quarto",
"raku" => "The currently installed version of Raku", "raku" => "The currently installed version of Raku",
"red" => "The currently installed version of Red", "red" => "The currently installed version of Red",
"rlang" => "The currently installed version of R", "rlang" => "The currently installed version of R",

93
src/modules/quarto.rs Normal file
View File

@ -0,0 +1,93 @@
use super::{Context, Module, ModuleConfig};
use crate::configs::quarto::QuartoConfig;
use crate::formatter::{StringFormatter, VersionFormatter};
/// Creates a module with the current Quarto version
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let mut module = context.new_module("quarto");
let config = QuartoConfig::try_load(module.config);
let is_quarto_project = context
.try_begin_scan()?
.set_files(&config.detect_files)
.set_extensions(&config.detect_extensions)
.set_folders(&config.detect_folders)
.is_match();
if !is_quarto_project {
return None;
}
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
formatter
.map_meta(|var, _| match var {
"symbol" => Some(config.symbol),
_ => None,
})
.map_style(|variable| match variable {
"style" => Some(Ok(config.style)),
_ => None,
})
.map(|variable| match variable {
"version" => {
let version = context
.exec_cmd("quarto", &["--version"])?
.stdout
.trim_end()
.to_owned();
VersionFormatter::format_module_version(
module.get_name(),
&version,
config.version_format,
)
.map(Ok)
}
_ => None,
})
.parse(None, Some(context))
});
module.set_segments(match parsed {
Ok(segments) => segments,
Err(error) => {
log::warn!("Error in module `quarto`:\n{}", error);
return None;
}
});
Some(module)
}
#[cfg(test)]
mod tests {
use crate::test::ModuleRenderer;
use nu_ansi_term::Color;
use std::fs::File;
use std::io;
#[test]
fn read_quarto_not_present() -> io::Result<()> {
let dir = tempfile::tempdir()?;
let actual = ModuleRenderer::new("quarto").path(dir.path()).collect();
let expected = None;
assert_eq!(expected, actual);
dir.close()
}
#[test]
fn read_quarto_present() -> io::Result<()> {
let dir = tempfile::tempdir()?;
File::create(dir.path().join("test.qmd"))?.sync_all()?;
let actual = ModuleRenderer::new("quarto").path(dir.path()).collect();
let expected = Some(format!(
"via {}",
Color::Rgb(117, 170, 219).bold().paint("⨁ v1.4.549 ")
));
assert_eq!(expected, actual);
dir.close()
}
}

View File

@ -393,6 +393,10 @@ WebAssembly: unavailable
stdout: String::from("Python 3.8.0\n"), stdout: String::from("Python 3.8.0\n"),
stderr: String::default(), stderr: String::default(),
}), }),
"quarto --version" => Some(CommandOutput {
stdout: String::from("1.4.549\n"),
stderr: String::default(),
}),
"R --version" => Some(CommandOutput { "R --version" => Some(CommandOutput {
stdout: String::default(), stdout: String::default(),
stderr: String::from( stderr: String::from(