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