diff --git a/docs/config/README.md b/docs/config/README.md index 37cd0e25..0defe826 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 35a7e685..8d481639 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> { .parse::() .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.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 287944cb..c498f4e0 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(()) +}