diff --git a/docs/config/README.md b/docs/config/README.md index 8dc1f6cb..3bf0ec9c 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -597,15 +597,16 @@ running `eval $(starship init $0)`, and then proceed as normal. ### Options -| Option | Default | Description | -| -------------------- | ----------------------------- | ---------------------------------------------------------- | -| `min_time` | `2_000` | Shortest duration to show time for (in milliseconds). | -| `show_milliseconds` | `false` | Show milliseconds in addition to seconds for the duration. | -| `format` | `"took [$duration]($style) "` | The format for the module. | -| `style` | `"bold yellow"` | The style for the module. | -| `disabled` | `false` | Disables the `cmd_duration` module. | -| `show_notifications` | `false` | Show desktop notifications when command completes. | -| `min_time_to_notify` | `45_000` | Shortest duration for notification (in milliseconds). | +| Option | Default | Description | +| ---------------------- | ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `min_time` | `2_000` | Shortest duration to show time for (in milliseconds). | +| `show_milliseconds` | `false` | Show milliseconds in addition to seconds for the duration. | +| `format` | `"took [$duration]($style) "` | The format for the module. | +| `style` | `"bold yellow"` | The style for the module. | +| `disabled` | `false` | Disables the `cmd_duration` module. | +| `show_notifications` | `false` | Show desktop notifications when command completes. | +| `min_time_to_notify` | `45_000` | Shortest duration for notification (in milliseconds). | +| `notification_timeout` | | Duration to show notification for (in milliseconds). If unset, notification timeout will be determined by daemon. Not all notification daemons honor this option. | ::: tip diff --git a/src/config.rs b/src/config.rs index aa86e5ba..83bccb7e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -109,6 +109,23 @@ impl<'a> ModuleConfig<'a> for f64 { } } +impl<'a> ModuleConfig<'a> for u32 { + fn from_config(config: &Value) -> Option { + match config { + Value::Integer(value) => { + // Converting i64 to u32 + if *value > 0 && *value <= u32::MAX.into() { + Some(*value as Self) + } else { + None + } + } + Value::String(value) => value.parse::().ok(), + _ => None, + } + } +} + impl<'a> ModuleConfig<'a> for usize { fn from_config(config: &Value) -> Option { match config { diff --git a/src/configs/cmd_duration.rs b/src/configs/cmd_duration.rs index be5d2f73..44c0c699 100644 --- a/src/configs/cmd_duration.rs +++ b/src/configs/cmd_duration.rs @@ -12,6 +12,9 @@ pub struct CmdDurationConfig<'a> { pub disabled: bool, pub show_notifications: bool, pub min_time_to_notify: i64, + + #[serde(skip_serializing_if = "Option::is_none")] + pub notification_timeout: Option, } impl<'a> Default for CmdDurationConfig<'a> { @@ -24,6 +27,7 @@ impl<'a> Default for CmdDurationConfig<'a> { disabled: false, show_notifications: false, min_time_to_notify: 45_000, + notification_timeout: None, } } } diff --git a/src/modules/cmd_duration.rs b/src/modules/cmd_duration.rs index f15d349d..133db31e 100644 --- a/src/modules/cmd_duration.rs +++ b/src/modules/cmd_duration.rs @@ -79,12 +79,17 @@ fn undistract_me<'a, 'b>( unstyle(&ANSIStrings(&module.ansi_strings())) ); + let timeout = match config.notification_timeout { + Some(v) => Timeout::Milliseconds(v), + None => Timeout::Default, + }; + let mut notification = Notification::new(); notification .summary("Command finished") .body(&body) .icon("utilities-terminal") - .timeout(Timeout::Milliseconds(750)); + .timeout(timeout); if let Err(err) = notification.show() { log::trace!("Cannot show notification: {}", err);