mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-12-25 11:20:01 +00:00
fix: don't attempt to display cmd_duration notification if in TTY (#4535)
Disables the display of notifications from cmd_duration on Linux if none of DISPLAY, WAYLAND_DISPLAY, or MIR_SOCKET are set. This prevents starship from attempting to create notifications in tty environments, which was previously causing hangs.
This commit is contained in:
parent
c2c2eecf7e
commit
0427863168
@ -48,13 +48,14 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
}
|
||||
});
|
||||
|
||||
Some(undistract_me(module, &config, elapsed))
|
||||
Some(undistract_me(module, &config, context, elapsed))
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "notify"))]
|
||||
fn undistract_me<'a, 'b>(
|
||||
module: Module<'a>,
|
||||
_config: &'b CmdDurationConfig,
|
||||
_context: &'a Context,
|
||||
_elapsed: u128,
|
||||
) -> Module<'a> {
|
||||
module
|
||||
@ -64,12 +65,24 @@ fn undistract_me<'a, 'b>(
|
||||
fn undistract_me<'a, 'b>(
|
||||
module: Module<'a>,
|
||||
config: &'b CmdDurationConfig,
|
||||
context: &'a Context,
|
||||
elapsed: u128,
|
||||
) -> Module<'a> {
|
||||
use notify_rust::{Notification, Timeout};
|
||||
use nu_ansi_term::{unstyle, AnsiStrings};
|
||||
|
||||
if config.show_notifications && config.min_time_to_notify as u128 <= elapsed {
|
||||
if cfg!(target_os = "linux") {
|
||||
let in_graphical_session = ["DISPLAY", "WAYLAND_DISPLAY", "MIR_SOCKET"]
|
||||
.iter()
|
||||
.find_map(|&var| context.get_env(var).filter(|val| !val.is_empty()))
|
||||
.is_some();
|
||||
|
||||
if !in_graphical_session {
|
||||
return module;
|
||||
};
|
||||
}
|
||||
|
||||
let body = format!(
|
||||
"Command execution {}",
|
||||
unstyle(&AnsiStrings(&module.ansi_strings()))
|
||||
|
Loading…
Reference in New Issue
Block a user