mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-04 20:37:56 +00:00
feat(kotlin): Configure when the module is shown (#2359)
This makes it possible to configure when the kotlin module is shown based on the contents of a directory.
This commit is contained in:
parent
fe6f9eeb4d
commit
1a6c625521
@ -1472,19 +1472,22 @@ symbol = "∴ "
|
||||
## Kotlin
|
||||
|
||||
The `kotlin` module shows the currently installed version of Kotlin.
|
||||
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 `.kt` or a `.kts` file
|
||||
|
||||
### Options
|
||||
|
||||
| Option | Default | Description |
|
||||
| --------------- | ------------------------------------ | ----------------------------------------------------------------------------- |
|
||||
| `format` | `"via [$symbol($version )]($style)"` | The format for the module. |
|
||||
| `symbol` | `"🅺 "` | A format string representing the symbol of Kotlin. |
|
||||
| `style` | `"bold blue"` | The style for the module. |
|
||||
| `kotlin_binary` | `"kotlin"` | Configures the kotlin binary that Starship executes when getting the version. |
|
||||
| `disabled` | `false` | Disables the `kotlin` module. |
|
||||
| Option | Default | Description |
|
||||
| ------------------- | ------------------------------------ | ----------------------------------------------------------------------------- |
|
||||
| `format` | `"via [$symbol($version )]($style)"` | The format for the module. |
|
||||
| `detect_extensions` | `["kt", "kts"]` | Which extensions should trigger this module. |
|
||||
| `detect_files` | `[]` | Which filenames should trigger this module. |
|
||||
| `detect_folders` | `[]` | Which folders should trigger this modules. |
|
||||
| `symbol` | `"🅺 "` | A format string representing the symbol of Kotlin. |
|
||||
| `style` | `"bold blue"` | The style for the module. |
|
||||
| `kotlin_binary` | `"kotlin"` | Configures the kotlin binary that Starship executes when getting the version. |
|
||||
| `disabled` | `false` | Disables the `kotlin` module. |
|
||||
|
||||
### Variables
|
||||
|
||||
|
@ -9,6 +9,9 @@ pub struct KotlinConfig<'a> {
|
||||
pub style: &'a str,
|
||||
pub kotlin_binary: &'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 KotlinConfig<'a> {
|
||||
@ -19,6 +22,9 @@ impl<'a> RootModuleConfig<'a> for KotlinConfig<'a> {
|
||||
style: "bold blue",
|
||||
kotlin_binary: "kotlin",
|
||||
disabled: false,
|
||||
detect_extensions: vec!["kt", "kts"],
|
||||
detect_files: vec![],
|
||||
detect_folders: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,21 +7,21 @@ use regex::Regex;
|
||||
const KOTLIN_VERSION_PATTERN: &str = "(?P<version>[\\d\\.]+[\\d\\.]+[\\d\\.]+)";
|
||||
|
||||
/// Creates a module with the current Kotlin version
|
||||
///
|
||||
/// Will display the Kotlin version if any of the following criteria are met:
|
||||
/// - Current directory contains a file with a `.kt` or `.kts` extension
|
||||
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
let mut module = context.new_module("kotlin");
|
||||
let config = KotlinConfig::try_load(module.config);
|
||||
|
||||
let is_kotlin_project = context
|
||||
.try_begin_scan()?
|
||||
.set_extensions(&["kt", "kts"])
|
||||
.set_files(&config.detect_files)
|
||||
.set_extensions(&config.detect_extensions)
|
||||
.set_folders(&config.detect_folders)
|
||||
.is_match();
|
||||
|
||||
if !is_kotlin_project {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut module = context.new_module("kotlin");
|
||||
let config = KotlinConfig::try_load(module.config);
|
||||
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
||||
formatter
|
||||
.map_meta(|var, _| match var {
|
||||
|
Loading…
Reference in New Issue
Block a user