mirror of
https://github.com/starship/starship.git
synced 2024-11-22 00:04:05 +01:00
Check for out-of-bounds timeout and correct it
This commit is contained in:
parent
3f6e9daf7d
commit
52109ab5f7
@ -79,12 +79,24 @@ fn undistract_me<'a, 'b>(
|
||||
unstyle(&ANSIStrings(&module.ansi_strings()))
|
||||
);
|
||||
|
||||
let timeout: u32 = match u32::try_from(config.notification_timeout) {
|
||||
Ok(v) => v,
|
||||
Err(_) => {
|
||||
let v: u32 = CmdDurationConfig::default().notification_timeout as u32;
|
||||
log::trace!(
|
||||
"Configured notification timeout not within bounds. Defaulting to {} ms",
|
||||
v
|
||||
);
|
||||
v
|
||||
}
|
||||
};
|
||||
|
||||
let mut notification = Notification::new();
|
||||
notification
|
||||
.summary("Command finished")
|
||||
.body(&body)
|
||||
.icon("utilities-terminal")
|
||||
.timeout(Timeout::Milliseconds(config.notification_timeout as u32));
|
||||
.timeout(Timeout::Milliseconds(timeout));
|
||||
|
||||
if let Err(err) = notification.show() {
|
||||
log::trace!("Cannot show notification: {}", err);
|
||||
@ -96,6 +108,7 @@ fn undistract_me<'a, 'b>(
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::configs::cmd_duration::CmdDurationConfig;
|
||||
use crate::test::ModuleRenderer;
|
||||
use ansi_term::Color;
|
||||
|
||||
@ -174,4 +187,14 @@ mod tests {
|
||||
let expected = Some(format!("underwent {} ", Color::Yellow.bold().paint("5s")));
|
||||
assert_eq!(expected, actual);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn config_notification_timeout_within_bounds() {
|
||||
assert!(
|
||||
match u32::try_from(CmdDurationConfig::default().notification_timeout) {
|
||||
Ok(_) => true,
|
||||
Err(_) => false,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user