mirror of
https://github.com/wez/wezterm.git
synced 2024-12-24 13:52:55 +03:00
Plumb OSC 777 to toast notifications
``` echo -e "\033]777;notify;This is the notification title;This is the notification text\a" ``` Now pops up a notification in a similar manner to OSC 9, except that this form allows setting both the title and the body separately. refs: https://github.com/wez/wezterm/issues/489
This commit is contained in:
parent
84a45f28e5
commit
f0c163e212
@ -3192,6 +3192,27 @@ impl<'a> Performer<'a> {
|
||||
log::info!("Application sends SystemNotification: {}", message);
|
||||
}
|
||||
}
|
||||
OperatingSystemCommand::RxvtExtension(params) => {
|
||||
if let Some("notify") = params.get(0).map(String::as_str) {
|
||||
let title = params.get(1);
|
||||
let body = params.get(2);
|
||||
let (title, body) = match (title.cloned(), body.cloned()) {
|
||||
(Some(title), None) => (None, title),
|
||||
(Some(title), Some(body)) => (Some(title), body),
|
||||
_ => {
|
||||
log::error!("malformed rxvt notify escape: {:?}", params);
|
||||
return;
|
||||
}
|
||||
};
|
||||
if let Some(handler) = self.notification_handler.as_mut() {
|
||||
handler.show_notification(ToastNotification {
|
||||
title,
|
||||
body,
|
||||
focus: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
OperatingSystemCommand::CurrentWorkingDirectory(url) => {
|
||||
self.current_dir = Url::parse(&url).ok();
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ pub enum OperatingSystemCommand {
|
||||
ResetDynamicColor(DynamicColorNumber),
|
||||
CurrentWorkingDirectory(String),
|
||||
ResetColors(Vec<u8>),
|
||||
RxvtExtension(Vec<String>),
|
||||
|
||||
Unspecified(Vec<Vec<u8>>),
|
||||
}
|
||||
@ -300,6 +301,13 @@ impl OperatingSystemCommand {
|
||||
ITermProprietary => {
|
||||
self::ITermProprietary::parse(osc).map(OperatingSystemCommand::ITermProprietary)
|
||||
}
|
||||
RxvtProprietary => {
|
||||
let mut vec = vec![];
|
||||
for slice in osc.iter().skip(1) {
|
||||
vec.push(String::from_utf8_lossy(slice).to_string());
|
||||
}
|
||||
Ok(OperatingSystemCommand::RxvtExtension(vec))
|
||||
}
|
||||
FinalTermSemanticPrompt => self::FinalTermSemanticPrompt::parse(osc)
|
||||
.map(OperatingSystemCommand::FinalTermSemanticPrompt),
|
||||
ChangeColorNumber => Self::parse_change_color_number(osc),
|
||||
@ -473,6 +481,7 @@ impl Display for OperatingSystemCommand {
|
||||
SetIconNameSun(title) => single_string!(SetIconNameSun, title),
|
||||
SetHyperlink(Some(link)) => link.fmt(f)?,
|
||||
SetHyperlink(None) => write!(f, "8;;")?,
|
||||
RxvtExtension(params) => write!(f, "777;{}", params.join(";"))?,
|
||||
Unspecified(v) => {
|
||||
for (idx, item) in v.iter().enumerate() {
|
||||
if idx > 0 {
|
||||
@ -1466,6 +1475,21 @@ mod test {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rxvt() {
|
||||
assert_eq!(
|
||||
parse(
|
||||
&["777", "notify", "alert user", "the tea is ready"],
|
||||
"\x1b]777;notify;alert user;the tea is ready\x1b\\"
|
||||
),
|
||||
OperatingSystemCommand::RxvtExtension(vec![
|
||||
"notify".into(),
|
||||
"alert user".into(),
|
||||
"the tea is ready".into()
|
||||
]),
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn iterm() {
|
||||
assert_eq!(
|
||||
|
Loading…
Reference in New Issue
Block a user