mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-24 21:57:41 +00:00
feat(swift): Configure when the module is shown (#2349)
This makes it possible to configure when the swift module is shown based on the contents of a directory.
This commit is contained in:
parent
a499f30157
commit
509767adc0
@ -2412,7 +2412,7 @@ disabled = false
|
||||
|
||||
## Swift
|
||||
|
||||
The `swift` module shows the currently installed version of Swift.
|
||||
By default the `swift` module shows the currently installed version of Swift.
|
||||
The module will be shown if any of the following conditions are met:
|
||||
|
||||
- The current directory contains a `Package.swift` file
|
||||
@ -2420,12 +2420,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 Swift |
|
||||
| `style` | `"bold 202"` | The style for the module. |
|
||||
| `disabled` | `false` | Disables the `swift` module. |
|
||||
| Option | Default | Description |
|
||||
| ------------------- | ------------------------------------ | ------------------------------------------------ |
|
||||
| `format` | `"via [$symbol($version )]($style)"` | The format for the module. |
|
||||
| `symbol` | `"🐦 "` | A format string representing the symbol of Swift |
|
||||
| `detect_extensions` | `["swift"]` | Which extensions should trigger this moudle. |
|
||||
| `detect_files` | `["Package.swift"]` | Which filenames should trigger this module. |
|
||||
| `detect_folders` | `[]` | Which folders should trigger this module. |
|
||||
| `style` | `"bold 202"` | The style for the module. |
|
||||
| `disabled` | `false` | Disables the `swift` module. |
|
||||
|
||||
### Variables
|
||||
|
||||
|
@ -8,6 +8,9 @@ pub struct SwiftConfig<'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 SwiftConfig<'a> {
|
||||
@ -17,6 +20,9 @@ impl<'a> RootModuleConfig<'a> for SwiftConfig<'a> {
|
||||
symbol: "🐦 ",
|
||||
style: "bold 202",
|
||||
disabled: false,
|
||||
detect_extensions: vec!["swift"],
|
||||
detect_files: vec!["Package.swift"],
|
||||
detect_folders: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,23 +4,21 @@ use crate::configs::swift::SwiftConfig;
|
||||
use crate::formatter::StringFormatter;
|
||||
|
||||
/// Creates a module with the current Swift version
|
||||
///
|
||||
/// Will display the Swift version if any of the following criteria are met:
|
||||
/// - The current directory contains a `Package.swift` file
|
||||
/// - The current directory contains a file with extension `.swift`
|
||||
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
let mut module = context.new_module("swift");
|
||||
let config: SwiftConfig = SwiftConfig::try_load(module.config);
|
||||
|
||||
let is_swift_project = context
|
||||
.try_begin_scan()?
|
||||
.set_extensions(&["swift"])
|
||||
.set_files(&config.detect_files)
|
||||
.set_folders(&config.detect_folders)
|
||||
.set_extensions(&config.detect_extensions)
|
||||
.is_match();
|
||||
|
||||
if !is_swift_project {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut module = context.new_module("swift");
|
||||
let config: SwiftConfig = SwiftConfig::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