mirror of
https://github.com/starship/starship.git
synced 2024-11-22 16:23:17 +01:00
feat: Added ability for setting command duration prefix (#414)
This commit is contained in:
parent
61604a4a8e
commit
7588137b09
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user