feat: added mise module (#5747)

This commit is contained in:
Andrew Pantuso
2025-04-26 16:15:30 -04:00
committed by GitHub
parent 7e88ba9561
commit d24e78754a
8 changed files with 311 additions and 0 deletions
+83
View File
@@ -974,6 +974,31 @@
} }
] ]
}, },
"mise": {
"default": {
"detect_extensions": [],
"detect_files": [
"mise.toml",
"mise.local.toml",
".mise.toml",
".mise.local.toml"
],
"detect_folders": [
".mise"
],
"disabled": true,
"format": "[$symbol$health]($style) ",
"healthy_symbol": "healthy",
"style": "bold purple",
"symbol": "mise ",
"unhealthy_symbol": "unhealthy"
},
"allOf": [
{
"$ref": "#/definitions/MiseConfig"
}
]
},
"mojo": { "mojo": {
"default": { "default": {
"detect_extensions": ["mojo", "🔥"], "detect_extensions": ["mojo", "🔥"],
@@ -4288,6 +4313,64 @@
}, },
"additionalProperties": false "additionalProperties": false
}, },
"MiseConfig": {
"type": "object",
"properties": {
"format": {
"default": "[$symbol$health]($style) ",
"type": "string"
},
"symbol": {
"default": "mise ",
"type": "string"
},
"style": {
"default": "bold purple",
"type": "string"
},
"disabled": {
"default": true,
"type": "boolean"
},
"detect_extensions": {
"default": [],
"type": "array",
"items": {
"type": "string"
}
},
"detect_files": {
"default": [
"mise.toml",
"mise.local.toml",
".mise.toml",
".mise.local.toml"
],
"type": "array",
"items": {
"type": "string"
}
},
"detect_folders": {
"default": [
".mise"
],
"type": "array",
"items": {
"type": "string"
}
},
"healthy_symbol": {
"default": "healthy",
"type": "string"
},
"unhealthy_symbol": {
"default": "unhealthy",
"type": "string"
}
},
"additionalProperties": false
},
"MojoConfig": { "MojoConfig": {
"type": "object", "type": "object",
"properties": { "properties": {
+35
View File
@@ -342,6 +342,7 @@ $azure\
$nats\ $nats\
$direnv\ $direnv\
$env_var\ $env_var\
$mise\
$crystal\ $crystal\
$custom\ $custom\
$sudo\ $sudo\
@@ -2989,6 +2990,40 @@ truncation_length = 4
truncation_symbol = '' truncation_symbol = ''
``` ```
## Mise
The `mise` module shows the current mise health as reported by running `mise doctor`.
### Options
| Option | Default | Description |
| ------------------ | -------------------------------- | ------------------------------------------------ |
| `symbol` | `'mise '` | The symbol used before displaying _mise_ health. |
| `style` | `'bold purple'` | The style for the module. |
| `format` | `'on [$symbol$health]($style) '` | The format for the module. |
| `healthy_symbol` | `healthy` | The message displayed when _mise_ is healthy. |
| `unhealthy_symbol` | `unhealthy` | The message displayed when _mise_ is unhealthy. |
| `disabled` | `true` | Disables the `mise` module. |
### Variables
| Variable | Example | Description |
| -------- | --------- | ------------------------------------ |
| health | `healthy` | The health of _mise_ |
| 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
### Example
```toml
# ~/.config/starship.toml
[mise]
health = 'ready'
```
## Mojo ## Mojo
The `mojo` module shows the current version of [Mojo programming language](https://www.modular.com/mojo) installed The `mojo` module shows the current version of [Mojo programming language](https://www.modular.com/mojo) installed
+41
View File
@@ -0,0 +1,41 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(
feature = "config-schema",
derive(schemars::JsonSchema),
schemars(deny_unknown_fields)
)]
#[serde(default)]
pub struct MiseConfig<'a> {
pub 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>,
pub healthy_symbol: &'a str,
pub unhealthy_symbol: &'a str,
}
impl Default for MiseConfig<'_> {
fn default() -> Self {
Self {
format: "[$symbol$health]($style) ",
symbol: "mise ",
style: "bold purple",
disabled: true,
detect_extensions: vec![],
detect_files: vec![
"mise.toml",
"mise.local.toml",
".mise.toml",
".mise.local.toml",
],
detect_folders: vec![".mise"],
healthy_symbol: "healthy",
unhealthy_symbol: "unhealthy",
}
}
}
+3
View File
@@ -57,6 +57,7 @@ pub mod localip;
pub mod lua; pub mod lua;
pub mod memory_usage; pub mod memory_usage;
pub mod meson; pub mod meson;
pub mod mise;
pub mod mojo; pub mod mojo;
pub mod nats; pub mod nats;
pub mod netns; pub mod netns;
@@ -226,6 +227,8 @@ pub struct FullConfig<'a> {
#[serde(borrow)] #[serde(borrow)]
meson: meson::MesonConfig<'a>, meson: meson::MesonConfig<'a>,
#[serde(borrow)] #[serde(borrow)]
mise: mise::MiseConfig<'a>,
#[serde(borrow)]
mojo: mojo::MojoConfig<'a>, mojo: mojo::MojoConfig<'a>,
#[serde(borrow)] #[serde(borrow)]
nats: nats::NatsConfig<'a>, nats: nats::NatsConfig<'a>,
+1
View File
@@ -116,6 +116,7 @@ pub const PROMPT_ORDER: &[&str] = &[
"azure", "azure",
"direnv", "direnv",
"env_var", "env_var",
"mise",
"crystal", "crystal",
"custom", "custom",
"sudo", "sudo",
+1
View File
@@ -61,6 +61,7 @@ pub const ALL_MODULES: &[&str] = &[
"lua", "lua",
"memory_usage", "memory_usage",
"meson", "meson",
"mise",
"mojo", "mojo",
"nats", "nats",
"netns", "netns",
+144
View File
@@ -0,0 +1,144 @@
use super::{Context, Module, ModuleConfig};
use crate::configs::mise::MiseConfig;
use crate::formatter::StringFormatter;
/// Creates a module with the current mise config
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let mut module = context.new_module("mise");
let config = MiseConfig::try_load(module.config);
let mise_applies = !config.disabled
&& context
.try_begin_scan()?
.set_extensions(&config.detect_extensions)
.set_files(&config.detect_files)
.set_folders(&config.detect_folders)
.is_match();
if !mise_applies {
return None;
}
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
formatter
.map_style(|variable| match variable {
"style" => Some(Ok(config.style)),
_ => None,
})
.map(|variable| match variable {
"symbol" => Some(Ok(config.symbol)),
"health" => match context.exec_cmd("mise", &["doctor"]) {
Some(_) => Some(Ok(config.healthy_symbol)),
None => Some(Ok(config.unhealthy_symbol)),
},
_ => None,
})
.parse(None, Some(context))
});
module.set_segments(match parsed {
Ok(segments) => segments,
Err(e) => {
log::warn!("{e}");
return None;
}
});
Some(module)
}
#[cfg(test)]
mod tests {
use crate::test::ModuleRenderer;
use crate::utils::CommandOutput;
use nu_ansi_term::Color;
use std::io;
#[test]
fn folder_without_mise_config() {
let renderer = ModuleRenderer::new("mise").config(toml::toml! {
[mise]
disabled = false
});
assert_eq!(None, renderer.collect());
}
#[test]
fn folder_with_mise_config_file_healthy() -> io::Result<()> {
let dir = tempfile::tempdir()?;
let config_path = dir.path().join(".mise.toml");
std::fs::File::create(config_path)?.sync_all()?;
let renderer = ModuleRenderer::new("mise")
.path(dir.path())
.config(toml::toml! {
[mise]
disabled = false
})
.cmd(
"mise doctor",
Some(CommandOutput {
stdout: String::default(),
stderr: String::default(),
}),
);
let expected = Some(format!("{} ", Color::Purple.bold().paint("mise healthy")));
assert_eq!(expected, renderer.collect());
dir.close()
}
#[test]
fn folder_with_mise_config_folder_healthy() -> io::Result<()> {
let dir = tempfile::tempdir()?;
let config_dir = dir.path().join(".mise");
std::fs::create_dir_all(config_dir)?;
let renderer = ModuleRenderer::new("mise")
.path(dir.path())
.config(toml::toml! {
[mise]
disabled = false
})
.cmd(
"mise doctor",
Some(CommandOutput {
stdout: String::default(),
stderr: String::default(),
}),
);
let expected = Some(format!("{} ", Color::Purple.bold().paint("mise healthy")));
assert_eq!(expected, renderer.collect());
dir.close()
}
#[test]
fn folder_with_mise_config_file_unhealthy() -> io::Result<()> {
let dir = tempfile::tempdir()?;
let config_path = dir.path().join(".mise.toml");
std::fs::File::create(config_path)?.sync_all()?;
let renderer = ModuleRenderer::new("mise")
.path(dir.path())
.config(toml::toml! {
[mise]
disabled = false
})
.cmd("mise doctor", None);
let expected = Some(format!("{} ", Color::Purple.bold().paint("mise unhealthy")));
assert_eq!(expected, renderer.collect());
dir.close()
}
}
+3
View File
@@ -54,6 +54,7 @@ mod localip;
mod lua; mod lua;
mod memory_usage; mod memory_usage;
mod meson; mod meson;
mod mise;
mod mojo; mod mojo;
mod nats; mod nats;
mod netns; mod netns;
@@ -169,6 +170,7 @@ pub fn handle<'a>(module: &str, context: &'a Context) -> Option<Module<'a>> {
"lua" => lua::module(context), "lua" => lua::module(context),
"memory_usage" => memory_usage::module(context), "memory_usage" => memory_usage::module(context),
"meson" => meson::module(context), "meson" => meson::module(context),
"mise" => mise::module(context),
"mojo" => mojo::module(context), "mojo" => mojo::module(context),
"nats" => nats::module(context), "nats" => nats::module(context),
"netns" => netns::module(context), "netns" => netns::module(context),
@@ -299,6 +301,7 @@ pub fn description(module: &str) -> &'static str {
"meson" => { "meson" => {
"The current Meson environment, if $MESON_DEVENV and $MESON_PROJECT_NAME are set" "The current Meson environment, if $MESON_DEVENV and $MESON_PROJECT_NAME are set"
} }
"mise" => "The current mise status",
"mojo" => "The currently installed version of Mojo", "mojo" => "The currently installed version of Mojo",
"nats" => "The current NATS context", "nats" => "The current NATS context",
"netns" => "The current network namespace", "netns" => "The current network namespace",