mirror of
https://github.com/starship/starship.git
synced 2024-11-26 10:14:57 +01:00
feat: add Zig module (#1231)
This commit is contained in:
parent
9e8f35d746
commit
c008f4041b
@ -122,6 +122,7 @@ prompt_order = [
|
|||||||
"ruby",
|
"ruby",
|
||||||
"rust",
|
"rust",
|
||||||
"terraform",
|
"terraform",
|
||||||
|
"zig",
|
||||||
"nix_shell",
|
"nix_shell",
|
||||||
"conda",
|
"conda",
|
||||||
"memory_usage",
|
"memory_usage",
|
||||||
@ -1363,6 +1364,31 @@ The module will be shown if any of the following conditions are met:
|
|||||||
disabled = true
|
disabled = true
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Zig
|
||||||
|
|
||||||
|
The `zig` module shows the currently installed version of Zig.
|
||||||
|
The module will be shown if any of the following conditions are met:
|
||||||
|
|
||||||
|
- The current directory contains a `.zig` file
|
||||||
|
|
||||||
|
### Options
|
||||||
|
|
||||||
|
| Variable | Default | Description |
|
||||||
|
| ---------- | ------------ | ------------------------------------------------------ |
|
||||||
|
| `symbol` | `"↯ "` | The symbol used before displaying the version of Zig. |
|
||||||
|
| `style` | `"bold yellow"` | The style for the module. |
|
||||||
|
| `disabled` | `false` | Disables the `zig` module. |
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```toml
|
||||||
|
# ~/.config/starship.toml
|
||||||
|
|
||||||
|
[zig]
|
||||||
|
symbol = "⚡️ "
|
||||||
|
```
|
||||||
|
|
||||||
## Custom commands
|
## Custom commands
|
||||||
|
|
||||||
The `custom` modules show the output of some arbitrary commands.
|
The `custom` modules show the output of some arbitrary commands.
|
||||||
|
@ -38,5 +38,6 @@ mod starship_root;
|
|||||||
pub mod terraform;
|
pub mod terraform;
|
||||||
pub mod time;
|
pub mod time;
|
||||||
pub mod username;
|
pub mod username;
|
||||||
|
pub mod zig;
|
||||||
|
|
||||||
pub use starship_root::*;
|
pub use starship_root::*;
|
||||||
|
@ -46,6 +46,7 @@ impl<'a> RootModuleConfig<'a> for StarshipRootConfig<'a> {
|
|||||||
"ruby",
|
"ruby",
|
||||||
"rust",
|
"rust",
|
||||||
"terraform",
|
"terraform",
|
||||||
|
"zig",
|
||||||
// ↑ Toolchain version modules ↑
|
// ↑ Toolchain version modules ↑
|
||||||
"nix_shell",
|
"nix_shell",
|
||||||
"conda",
|
"conda",
|
||||||
|
23
src/configs/zig.rs
Normal file
23
src/configs/zig.rs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
use crate::config::{ModuleConfig, RootModuleConfig, SegmentConfig};
|
||||||
|
|
||||||
|
use ansi_term::{Color, Style};
|
||||||
|
use starship_module_config_derive::ModuleConfig;
|
||||||
|
|
||||||
|
#[derive(Clone, ModuleConfig)]
|
||||||
|
pub struct ZigConfig<'a> {
|
||||||
|
pub symbol: SegmentConfig<'a>,
|
||||||
|
pub version: SegmentConfig<'a>,
|
||||||
|
pub style: Style,
|
||||||
|
pub disabled: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> RootModuleConfig<'a> for ZigConfig<'a> {
|
||||||
|
fn new() -> Self {
|
||||||
|
ZigConfig {
|
||||||
|
symbol: SegmentConfig::new("↯ "),
|
||||||
|
version: SegmentConfig::default(),
|
||||||
|
style: Color::Yellow.bold(),
|
||||||
|
disabled: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -50,6 +50,7 @@ pub const ALL_MODULES: &[&str] = &[
|
|||||||
"singularity",
|
"singularity",
|
||||||
"time",
|
"time",
|
||||||
"username",
|
"username",
|
||||||
|
"zig",
|
||||||
];
|
];
|
||||||
|
|
||||||
/// A module is a collection of segments showing data for a single integration
|
/// A module is a collection of segments showing data for a single integration
|
||||||
|
@ -39,6 +39,7 @@ mod terraform;
|
|||||||
mod time;
|
mod time;
|
||||||
mod username;
|
mod username;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
mod zig;
|
||||||
|
|
||||||
#[cfg(feature = "battery")]
|
#[cfg(feature = "battery")]
|
||||||
mod battery;
|
mod battery;
|
||||||
@ -91,6 +92,7 @@ pub fn handle<'a>(module: &str, context: &'a Context) -> Option<Module<'a>> {
|
|||||||
"time" => time::module(context),
|
"time" => time::module(context),
|
||||||
"crystal" => crystal::module(context),
|
"crystal" => crystal::module(context),
|
||||||
"username" => username::module(context),
|
"username" => username::module(context),
|
||||||
|
"zig" => zig::module(context),
|
||||||
_ => {
|
_ => {
|
||||||
eprintln!("Error: Unknown module {}. Use starship module --list to list out all supported modules.", module);
|
eprintln!("Error: Unknown module {}. Use starship module --list to list out all supported modules.", module);
|
||||||
None
|
None
|
||||||
@ -138,6 +140,7 @@ pub fn description(module: &str) -> &'static str {
|
|||||||
"terraform" => "The currently selected terraform workspace and version",
|
"terraform" => "The currently selected terraform workspace and version",
|
||||||
"time" => "The current local time",
|
"time" => "The current local time",
|
||||||
"username" => "The active user's username",
|
"username" => "The active user's username",
|
||||||
|
"zig" => "The currently installed version of Zig",
|
||||||
_ => "<no description>",
|
_ => "<no description>",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
63
src/modules/zig.rs
Normal file
63
src/modules/zig.rs
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
use super::{Context, Module, RootModuleConfig};
|
||||||
|
|
||||||
|
use crate::configs::zig::ZigConfig;
|
||||||
|
use crate::utils;
|
||||||
|
|
||||||
|
/// Creates a module with the current Zig version
|
||||||
|
///
|
||||||
|
/// Will display the Zig version if any of the following criteria are met:
|
||||||
|
/// - The current directory contains a file with extension `.zig`
|
||||||
|
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||||
|
let is_zig_project = context
|
||||||
|
.try_begin_scan()?
|
||||||
|
.set_extensions(&["zig"])
|
||||||
|
.is_match();
|
||||||
|
|
||||||
|
if !is_zig_project {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let zig_version_output = utils::exec_cmd("zig", &["version"])?
|
||||||
|
.stdout
|
||||||
|
.trim()
|
||||||
|
.to_string();
|
||||||
|
let zig_version = format!("v{}", zig_version_output);
|
||||||
|
|
||||||
|
let mut module = context.new_module("zig");
|
||||||
|
let config = ZigConfig::try_load(module.config);
|
||||||
|
|
||||||
|
module.set_style(config.style);
|
||||||
|
|
||||||
|
module.create_segment("symbol", &config.symbol);
|
||||||
|
module.create_segment("version", &config.version.with_value(&zig_version));
|
||||||
|
|
||||||
|
Some(module)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::modules::utils::test::render_module;
|
||||||
|
use ansi_term::Color;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn folder_without_zig() -> io::Result<()> {
|
||||||
|
let dir = tempfile::tempdir()?;
|
||||||
|
File::create(dir.path().join("zig.txt"))?.sync_all()?;
|
||||||
|
let actual = render_module("zig", dir.path(), None);
|
||||||
|
let expected = None;
|
||||||
|
assert_eq!(expected, actual);
|
||||||
|
dir.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn folder_with_zig_file() -> io::Result<()> {
|
||||||
|
let dir = tempfile::tempdir()?;
|
||||||
|
File::create(dir.path().join("main.zig"))?.sync_all()?;
|
||||||
|
let actual = render_module("zig", dir.path(), None);
|
||||||
|
let expected = Some(format!("via {} ", Color::Yellow.bold().paint("↯ v0.6.0")));
|
||||||
|
assert_eq!(expected, actual);
|
||||||
|
dir.close()
|
||||||
|
}
|
||||||
|
}
|
@ -92,6 +92,10 @@ Elixir 1.10 (compiled with Erlang/OTP 22)",
|
|||||||
),
|
),
|
||||||
stderr: String::default(),
|
stderr: String::default(),
|
||||||
}),
|
}),
|
||||||
|
"zig version" => Some(CommandOutput {
|
||||||
|
stdout: String::from("0.6.0"),
|
||||||
|
stderr: String::default(),
|
||||||
|
}),
|
||||||
s if s.starts_with("erl") => Some(CommandOutput {
|
s if s.starts_with("erl") => Some(CommandOutput {
|
||||||
stdout: String::from("22.1.3"),
|
stdout: String::from("22.1.3"),
|
||||||
stderr: String::default(),
|
stderr: String::default(),
|
||||||
|
Loading…
Reference in New Issue
Block a user