diff options
author | Andrew Prokhorenkov <andrew.prokhorenkov@gmail.com> | 2020-01-25 00:48:39 -0600 |
---|---|---|
committer | Kevin Song <chipbuster@users.noreply.github.com> | 2020-01-25 00:48:39 -0600 |
commit | 6f2c9fb397fcfb22829c043a23372afe1f877499 (patch) | |
tree | 48b64728a098dcd95f2e694b0a62dd66467fc47b /src/modules/haskell.rs | |
parent | f4c095de92a09b7143766c4759ab0e60ff0befbb (diff) |
feat: add Haskell Stack support (#546)
Add a Haskell Stack module when a stack.yaml file is detected
Diffstat (limited to 'src/modules/haskell.rs')
-rw-r--r-- | src/modules/haskell.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/modules/haskell.rs b/src/modules/haskell.rs new file mode 100644 index 000000000..ce0918cca --- /dev/null +++ b/src/modules/haskell.rs @@ -0,0 +1,40 @@ +use super::{Context, Module, RootModuleConfig, SegmentConfig}; + +use crate::configs::haskell::HaskellConfig; +use crate::utils; + +/// Creates a module with the current Haskell Stack version +/// +/// Will display the Haskell version if any of the following criteria are met: +/// - Current directory contains a `stack.yaml` file +pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { + let is_haskell_project = context + .try_begin_scan()? + .set_files(&["stack.yaml"]) + .is_match(); + + if !is_haskell_project { + return None; + } + + let haskell_version = utils::exec_cmd( + "stack", + &["ghc", "--", "--numeric-version", "--no-install-ghc"], + )? + .stdout; + let formatted_version = format_haskell_version(&haskell_version)?; + + let mut module = context.new_module("haskell"); + let config: HaskellConfig = HaskellConfig::try_load(module.config); + module.set_style(config.style); + + module.create_segment("symbol", &config.symbol); + module.create_segment("version", &SegmentConfig::new(&formatted_version)); + + Some(module) +} + +fn format_haskell_version(haskell_version: &str) -> Option<String> { + let formatted_version = format!("v{}", haskell_version.trim()); + Some(formatted_version) +} |