summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Hotston <Hotston.tom@Gmail.com>2019-09-30 06:26:32 +0100
committerMatan Kushner <hello@matchai.me>2019-09-30 14:26:32 +0900
commit7588137b09f7706cc404a986113b277d99fde859 (patch)
tree668ec37c88ef3b4782d12d3205c85fb64f5a0fcd
parent61604a4a8e7f407290ef4cf5205be6f4e2fd4dcf (diff)
feat: Added ability for setting command duration prefix (#414)
-rw-r--r--docs/config/README.md12
-rw-r--r--src/modules/cmd_duration.rs10
-rw-r--r--tests/testsuite/cmd_duration.rs32
3 files changed, 48 insertions, 6 deletions
diff --git a/docs/config/README.md b/docs/config/README.md
index 37cd0e252..0defe8268 100644
--- a/docs/config/README.md
+++ b/docs/config/README.md
@@ -257,11 +257,12 @@ running `eval $(starship init $0)`, and then proceed as normal.
### Options
-| Variable | Default | Description |
-| ---------- | --------------- | ----------------------------------- |
-| `min_time` | `2` | Shortest duration to show time for. |
-| `style` | `"bold yellow"` | The style for the module. |
-| `disabled` | `false` | Disables the `cmd_duration` module. |
+| Variable | Default | Description |
+| ---------- | --------------- | ------------------------------------------- |
+| `min_time` | `2` | Shortest duration to show time for. |
+| `prefix` | `took ` | Prefix to display immediately cmd_duration. |
+| `style` | `"bold yellow"` | The style for the module. |
+| `disabled` | `false` | Disables the `cmd_duration` module. |
### Example
@@ -270,6 +271,7 @@ running `eval $(starship init $0)`, and then proceed as normal.
[cmd_duration]
min_time = 4
+prefix = "underwent "
```
## Directory
diff --git a/src/modules/cmd_duration.rs b/src/modules/cmd_duration.rs
index 35a7e6858..8d4816392 100644
--- a/src/modules/cmd_duration.rs
+++ b/src/modules/cmd_duration.rs
@@ -16,6 +16,11 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
.parse::<u64>()
.ok()?;
+ let prefix = module
+ .config_value_str("prefix")
+ .unwrap_or("took ")
+ .to_owned();
+
let signed_config_min = module.config_value_i64("min_time").unwrap_or(2);
/* TODO: Once error handling is implemented, warn the user if their config
@@ -38,7 +43,10 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
};
module.set_style(module_color);
- module.new_segment("cmd_duration", &format!("took {}", render_time(elapsed)));
+ module.new_segment(
+ "cmd_duration",
+ &format!("{}{}", prefix, render_time(elapsed)),
+ );
module.get_prefix().set_value("");
Some(module)
diff --git a/tests/testsuite/cmd_duration.rs b/tests/testsuite/cmd_duration.rs
index 287944cbd..c498f4e0d 100644
--- a/tests/testsuite/cmd_duration.rs
+++ b/tests/testsuite/cmd_duration.rs
@@ -58,3 +58,35 @@ fn config_5s_duration_10s() -> io::Result<()> {
assert_eq!(expected, actual);
Ok(())
}
+
+#[test]
+fn config_1s_duration_prefix_underwent() -> io::Result<()> {
+ let output = common::render_module("cmd_duration")
+ .use_config(toml::toml! {
+ [cmd_duration]
+ prefix = "underwent "
+ })
+ .arg("--cmd-duration=1")
+ .output()?;
+ let actual = String::from_utf8(output.stdout).unwrap();
+
+ let expected = "";
+ assert_eq!(expected, actual);
+ Ok(())
+}
+
+#[test]
+fn config_5s_duration_prefix_underwent() -> io::Result<()> {
+ let output = common::render_module("cmd_duration")
+ .use_config(toml::toml! {
+ [cmd_duration]
+ prefix = "underwent "
+ })
+ .arg("--cmd-duration=5")
+ .output()?;
+ let actual = String::from_utf8(output.stdout).unwrap();
+
+ let expected = format!("{} ", Color::Yellow.bold().paint("underwent 5s"));
+ assert_eq!(expected, actual);
+ Ok(())
+}