mirror of
https://github.com/starship/starship.git
synced 2026-06-23 02:05:51 +07:00
feat(julia): Configure when the module is shown (#2358)
This makes it possible to configure when the julia module is shown based on the contents of a directory.
This commit is contained in:
@@ -8,6 +8,9 @@ pub struct JuliaConfig<'a> {
|
||||
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> RootModuleConfig<'a> for JuliaConfig<'a> {
|
||||
@@ -17,6 +20,9 @@ impl<'a> RootModuleConfig<'a> for JuliaConfig<'a> {
|
||||
symbol: "ஃ ",
|
||||
style: "bold purple",
|
||||
disabled: false,
|
||||
detect_extensions: vec!["jl"],
|
||||
detect_files: vec!["Project.toml", "Manifest.toml"],
|
||||
detect_folders: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,24 +4,21 @@ use crate::configs::julia::JuliaConfig;
|
||||
use crate::formatter::StringFormatter;
|
||||
|
||||
/// Creates a module with the current Julia version
|
||||
///
|
||||
/// Will display the Julia version if any of the following criteria are met:
|
||||
/// - Current directory contains a `Project.toml` file
|
||||
/// - Current directory contains a `Manifest.toml` file
|
||||
/// - Current directory contains a file with the `.jl` extension
|
||||
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
let mut module = context.new_module("julia");
|
||||
let config = JuliaConfig::try_load(module.config);
|
||||
|
||||
let is_julia_project = context
|
||||
.try_begin_scan()?
|
||||
.set_files(&["Project.toml", "Manifest.toml"])
|
||||
.set_extensions(&["jl"])
|
||||
.set_files(&config.detect_files)
|
||||
.set_extensions(&config.detect_extensions)
|
||||
.set_folders(&config.detect_folders)
|
||||
.is_match();
|
||||
|
||||
if !is_julia_project {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut module = context.new_module("julia");
|
||||
let config = JuliaConfig::try_load(module.config);
|
||||
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
||||
formatter
|
||||
.map_meta(|var, _| match var {
|
||||
|
||||
Reference in New Issue
Block a user