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 | |
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')
-rw-r--r-- | src/configs/haskell.rs | 23 | ||||
-rw-r--r-- | src/configs/mod.rs | 1 | ||||
-rw-r--r-- | src/module.rs | 1 | ||||
-rw-r--r-- | src/modules/haskell.rs | 40 | ||||
-rw-r--r-- | src/modules/mod.rs | 2 |
5 files changed, 67 insertions, 0 deletions
diff --git a/src/configs/haskell.rs b/src/configs/haskell.rs new file mode 100644 index 000000000..b7e29e497 --- /dev/null +++ b/src/configs/haskell.rs @@ -0,0 +1,23 @@ +use crate::config::{ModuleConfig, RootModuleConfig, SegmentConfig}; + +use ansi_term::{Color, Style}; +use starship_module_config_derive::ModuleConfig; + +#[derive(Clone, ModuleConfig)] +pub struct HaskellConfig<'a> { + pub symbol: SegmentConfig<'a>, + pub version: SegmentConfig<'a>, + pub style: Style, + pub disabled: bool, +} + +impl<'a> RootModuleConfig<'a> for HaskellConfig<'a> { + fn new() -> Self { + HaskellConfig { + symbol: SegmentConfig::new("λ "), + version: SegmentConfig::default(), + style: Color::Red.bold(), + disabled: false, + } + } +} diff --git a/src/configs/mod.rs b/src/configs/mod.rs index dcf0337f4..02ee00ef7 100644 --- a/src/configs/mod.rs +++ b/src/configs/mod.rs @@ -11,6 +11,7 @@ pub mod git_commit; pub mod git_state; pub mod git_status; pub mod go; +pub mod haskell; pub mod hg_branch; pub mod hostname; pub mod java; diff --git a/src/module.rs b/src/module.rs index 3de985d6c..34f3a6520 100644 --- a/src/module.rs +++ b/src/module.rs @@ -22,6 +22,7 @@ pub const ALL_MODULES: &[&str] = &[ "git_state", "git_status", "golang", + "haskell", "hg_branch", "hostname", "java", 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), |