T40: sessions post system notifications through gpui's: each terminal posts its own in the order its output asks, when its row turns to waiting, done or error, when a command ends, and when a program asks through OSC 9, 777 or 99, only while its window is inactive or it is hidden, one every 3 seconds, titled with the session's name; a press goes to the window whose session posted it and shows it; OSC 99 hears untracked closes, alive lists what lives, in order before a later DA1, a close and w take one back where gpui can, a closed session's too, and the query says what holds where
CI / platforms (windows-latest) (push) Successful in 1m51s
CI / platforms (ubuntu-24.04) (push) Successful in 2m2s
CI / macos (push) Successful in 12m36s

This commit is contained in:
ZacharyZhang-NY committed 2026-10-17 15:36:28 -04:00
1 parent 53b8978dff
commit 31de5e44ef
18 files changed
+512 -122

No files matched your search

+21 -23
View File
@@ -2,15 +2,6 @@ use base64::Engine;
use super::status::BASE64;
/// When a notification may show: OSC 99's `o`.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum Occasion {
#[default]
Always,
Unfocused,
Invisible,
}
/// A notification a program asks for: OSC 9, 777 or 99.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Notice {
@@ -18,7 +9,6 @@ pub struct Notice {
pub id: Option<String>,
pub title: String,
pub body: String,
pub occasion: Occasion,
/// A press shows the window and session (`a=focus`, the default), and tells the program (`a=report`).
pub focus: bool,
pub report: bool,
@@ -121,7 +111,6 @@ fn plain(title: String, body: String) -> Notice {
id: None,
title,
body,
occasion: Occasion::Always,
focus: true,
report: false,
close: false,
@@ -141,14 +130,30 @@ fn safe(bytes: &[u8], what: &str) -> Option<String> {
Some(text)
}
/// The answer to OSC 99's query, naming `id`: what this terminal reads of notifications.
/// gpui closes no notification on Linux, nor replaces one, so close and expiry hold elsewhere alone.
pub(super) const CLOSES: bool = !cfg!(target_os = "linux");
/// The answer to OSC 99's query, naming `id`: a press focuses and reports, a notification posts while unseen, its payloads, and close and expiry where gpui closes one.
pub fn answer(id: &str) -> String {
format!("\x1b]99;i={id}:p=?;p=title,body,?,alive:o=always\x1b\\")
let (close, expire) = if CLOSES { ("close,", ":w=1") } else { ("", "") };
format!(
"\x1b]99;i={id}:p=?;a=focus,report:o=invisible:p=title,body,{close}?,alive{expire}\x1b\\"
)
}
/// The answer to OSC 99's `p=alive`, naming `id`: none, as no notification shows yet.
pub fn alive(id: &str) -> String {
format!("\x1b]99;i={id}:p=alive;\x1b\\")
/// The answer to OSC 99's `p=alive`, naming `id`: the ids of notifications still alive.
pub fn alive(id: &str, alive: &[&str]) -> String {
format!("\x1b]99;i={id}:p=alive;{}\x1b\\", alive.join(","))
}
/// What `c=1` hears of notification `id`: its close goes untracked, as gpui hears of none.
pub fn untracked(id: &str) -> String {
format!("\x1b]99;i={id}:p=close;untracked\x1b\\")
}
/// What `a=report` hears when notification `id` is pressed.
pub fn activated(id: &str) -> String {
format!("\x1b]99;i={id};\x1b\\")
}
/// An OSC 99 payload's most bytes: plain, and base64; and its metadata's.
@@ -335,13 +340,6 @@ impl Kitty {
return Err(format!("a notification over {GATHERED} bytes"));
}
let notice = &mut gathering.notice;
if let Some(occasion) = get(b'o') {
notice.occasion = match occasion {
b"unfocused" => Occasion::Unfocused,
b"invisible" => Occasion::Invisible,
_ => Occasion::Always,
};
}
if let Some(actions) = get(b'a') {
for action in actions.split(|&byte| byte == b',') {
let (on, name) = match action.strip_prefix(b"-") {