From 77184503111e5d2e95a9874ab7ce0d5d2ecdc139 Mon Sep 17 00:00:00 2001 From: Bernardo Meurer Date: Tue, 7 Apr 2020 09:35:18 -0700 Subject: [PATCH] feat(nix_shell): add symbol to nix-shell module (#1058) * feat: add nix-shell icon Fixes #1048 * style: make nix-shell bold blue by default It better matches the whole theme around Nix and snowflakes. --- docs/config/README.md | 16 +++++++++------- src/configs/nix_shell.rs | 4 +++- src/modules/nix_shell.rs | 1 + tests/testsuite/nix_shell.rs | 6 +++--- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/docs/config/README.md b/docs/config/README.md index 75c48afa..7d1cd722 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -977,13 +977,14 @@ The module will be shown when inside a nix-shell environment. ### Options -| Variable | Default | Description | -| ------------ | ------------ | ---------------------------------- | -| `use_name` | `false` | Display the name of the nix-shell. | -| `impure_msg` | `"impure"` | Customize the "impure" msg. | -| `pure_msg` | `"pure"` | Customize the "pure" msg. | -| `style` | `"bold red"` | The style for the module. | -| `disabled` | `false` | Disables the `nix_shell` module. | +| Variable | Default | Description | +| ------------ | ------------- | ------------------------------------------------- | +| `use_name` | `false` | Display the name of the nix-shell. | +| `impure_msg` | `"impure"` | Customize the "impure" msg. | +| `pure_msg` | `"pure"` | Customize the "pure" msg. | +| `symbol` | `"❄️ "` | The symbol used before displaying the shell name. | +| `style` | `"bold blue"` | The style for the module. | +| `disabled` | `false` | Disables the `nix_shell` module. | ### Example @@ -995,6 +996,7 @@ disabled = true use_name = true impure_msg = "impure shell" pure_msg = "pure shell" +symbol = "☃️ " ``` ## NodeJS diff --git a/src/configs/nix_shell.rs b/src/configs/nix_shell.rs index d5316b6a..214277fa 100644 --- a/src/configs/nix_shell.rs +++ b/src/configs/nix_shell.rs @@ -9,6 +9,7 @@ pub struct NixShellConfig<'a> { pub impure_msg: SegmentConfig<'a>, pub pure_msg: SegmentConfig<'a>, pub style: Style, + pub symbol: SegmentConfig<'a>, pub disabled: bool, } @@ -18,7 +19,8 @@ impl<'a> RootModuleConfig<'a> for NixShellConfig<'a> { use_name: false, impure_msg: SegmentConfig::new("impure"), pure_msg: SegmentConfig::new("pure"), - style: Color::Red.bold(), + style: Color::Blue.bold(), + symbol: SegmentConfig::new("❄️ "), disabled: false, } } diff --git a/src/modules/nix_shell.rs b/src/modules/nix_shell.rs index 33fb5bb8..b174645d 100644 --- a/src/modules/nix_shell.rs +++ b/src/modules/nix_shell.rs @@ -27,6 +27,7 @@ pub fn module<'a>(context: &'a Context) -> Option> { let config: NixShellConfig = NixShellConfig::try_load(module.config); module.set_style(config.style); + module.create_segment("symbol", &config.symbol); let shell_type = env::var("IN_NIX_SHELL").ok()?; let shell_type_segment: SegmentConfig = match shell_type.as_ref() { diff --git a/tests/testsuite/nix_shell.rs b/tests/testsuite/nix_shell.rs index b278e3cd..931391a6 100644 --- a/tests/testsuite/nix_shell.rs +++ b/tests/testsuite/nix_shell.rs @@ -28,7 +28,7 @@ fn pure_shell() -> io::Result<()> { .output()?; let actual = String::from_utf8(output.stdout).unwrap(); - let expected = format!("via {} ", Color::Red.bold().paint("pure")); + let expected = format!("via {} ", Color::Blue.bold().paint("❄️ pure")); assert_eq!(expected, actual); Ok(()) } @@ -40,7 +40,7 @@ fn impure_shell() -> io::Result<()> { .output()?; let actual = String::from_utf8(output.stdout).unwrap(); - let expected = format!("via {} ", Color::Red.bold().paint("impure")); + let expected = format!("via {} ", Color::Blue.bold().paint("❄️ impure")); assert_eq!(expected, actual); Ok(()) } @@ -52,7 +52,7 @@ fn lorri_shell() -> io::Result<()> { .output()?; let actual = String::from_utf8(output.stdout).unwrap(); - let expected = format!("via {} ", Color::Red.bold().paint("impure")); + let expected = format!("via {} ", Color::Blue.bold().paint("❄️ impure")); assert_eq!(expected, actual); Ok(()) }