mirror of
https://github.com/starship/starship.git
synced 2026-06-24 02:01:36 +07:00
feat(crystal): Configure when the module is shown (#2310)
* feat(crystal): Configure when the module is shown This makes it possible to configure when the crystal module is shown based on the contents of a directory. This should make it possible to be a lot more granular when configuring the module. * Update docs/config/README.md Co-authored-by: David Knaack <davidkna@users.noreply.github.com> Co-authored-by: David Knaack <davidkna@users.noreply.github.com>
This commit is contained in:
@@ -4,24 +4,21 @@ use crate::configs::crystal::CrystalConfig;
|
||||
use crate::formatter::StringFormatter;
|
||||
|
||||
/// Creates a module with the current Crystal version
|
||||
///
|
||||
/// Will display the Crystal version if any of the following criteria are met:
|
||||
/// - Current directory contains a `.cr` file
|
||||
/// - Current directory contains a `shard.yml` file
|
||||
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
let mut module = context.new_module("crystal");
|
||||
let config: CrystalConfig = CrystalConfig::try_load(module.config);
|
||||
|
||||
let is_crystal_project = context
|
||||
.try_begin_scan()?
|
||||
.set_files(&["shard.yml"])
|
||||
.set_extensions(&["cr"])
|
||||
.set_files(&config.detect_files)
|
||||
.set_extensions(&config.detect_extensions)
|
||||
.set_folders(&config.detect_folders)
|
||||
.is_match();
|
||||
|
||||
if !is_crystal_project {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut module = context.new_module("crystal");
|
||||
let config: CrystalConfig = CrystalConfig::try_load(module.config);
|
||||
|
||||
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
||||
formatter
|
||||
.map_meta(|variable, _| match variable {
|
||||
|
||||
Reference in New Issue
Block a user