summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas O'Donnell <andytom@users.noreply.github.com>2021-02-21 19:56:55 +0100
committerGitHub <noreply@github.com>2021-02-21 19:56:55 +0100
commitc0a209f27ccaf96d08aedc011dca05435fa2c900 (patch)
treef4d56b7668c399a7a7a804cfacecae128aa8a964
parent1a6c625521510fee059bec168e73a49aef834c8c (diff)
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.
-rw-r--r--docs/config/README.md17
-rw-r--r--src/configs/julia.rs6
-rw-r--r--src/modules/julia.rs15
3 files changed, 22 insertions, 16 deletions
diff --git a/docs/config/README.md b/docs/config/README.md
index 6d54249c2..8b4682943 100644
--- a/docs/config/README.md
+++ b/docs/config/README.md
@@ -1435,7 +1435,7 @@ threshold = 4
## Julia
The `julia` module shows the currently installed version of Julia.
-The module will be shown if any of the following conditions are met:
+By default the module will be shown if any of the following conditions are met:
- The current directory contains a `Project.toml` file
- The current directory contains a `Manifest.toml` file
@@ -1443,12 +1443,15 @@ The module will be shown if any of the following conditions are met:
### Options
-| Option | Default | Description |
-| ---------- | ---------------------------------- | ------------------------------------------------- |
-| `format` | `"via [$symbol($version )]($style)"` | The format for the module. |
-| `symbol` | `"ஃ "` | A format string representing the symbol of Julia. |
-| `style` | `"bold purple"` | The style for the module. |
-| `disabled` | `false` | Disables the `julia` module. |
+| Option | Default | Description |
+| ------------------- | ------------------------------------ | ------------------------------------------------- |
+| `format` | `"via [$symbol($version )]($style)"` | The format for the module. |
+| `detect_extensions` | `["jl"]` | Which extensions should trigger this module. |
+| `detect_files` | `["Project.toml", "Manifest.toml"]` | Which filenames should trigger this module. |
+| `detect_folders` | `[]` | Which folders should trigger this modules. |
+| `symbol` | `"ஃ "` | A format string representing the symbol of Julia. |
+| `style` | `"bold purple"` | The style for the module. |
+| `disabled` | `false` | Disables the `julia` module. |
### Variables
diff --git a/src/configs/julia.rs b/src/configs/julia.rs
index 6d99ad5e8..502317ef2 100644
--- a/src/configs/julia.rs
+++ b/src/configs/julia.rs
@@ -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![],
}
}
}
diff --git a/src/modules/julia.rs b/src/modules/julia.rs
index db729d338..0ae892add 100644
--- a/src/modules/julia.rs
+++ b/src/modules/julia.rs
@@ -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 {