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 | |
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')
-rw-r--r-- | src/modules/haskell.rs | 40 | ||||
-rw-r--r-- | src/modules/mod.rs | 2 |
2 files changed, 42 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) +} diff --git a/src/modules/mod.rs b/src/modules/mod.rs index 0d206a8d0..9c9f403c0 100644 --- a/src/modules/mod.rs +++ b/src/modules/mod.rs @@ -11,6 +11,7 @@ mod git_commit; mod git_state; mod git_status; mod golang; +mod haskell; mod hg_branch; mod hostname; mod java; @@ -55,6 +56,7 @@ pub fn handle<'a>(module: &str, context: &'a Context) -> Option<Module<'a>> { "git_state" => git_state::module(context), "git_status" => git_status::module(context), "golang" => golang::module(context), + "haskell" => haskell::module(context), "hg_branch" => hg_branch::module(context), "hostname" => hostname::module(context), "java" => java::module(context), |