diff options
| author | Stanton Burchett <sburchett@medallia.com> | 2026-07-30 14:51:22 -0600 |
|---|---|---|
| committer | Stanton Burchett <sburchett@medallia.com> | 2026-07-30 14:51:22 -0600 |
| commit | 46e3650242cfe38941eb747e601484bd19c137bd (patch) | |
| tree | 16a1df66b7fead0e8ee1838e4b02179f5d2360b5 /src/osc-notify-middleware.ts | |
| parent | 64b564b52ba7d22ba8129821ab4b30542d971ff5 (diff) | |
Add OSC 777 support and clean up the notification title
Support OSC 777 ; notify ; title ; body (the rxvt/urxvt notification form) so a program can set an explicit title and body, with the semicolon-safe body rejoined via slice(2).join(";"). Clean the OSC 9 title: prefer a user-set custom tab name, and reduce filesystem-path titles to their last segment so shell tabs no longer show a long, truncated cwd.
Diffstat (limited to 'src/osc-notify-middleware.ts')
| -rw-r--r-- | src/osc-notify-middleware.ts | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/osc-notify-middleware.ts b/src/osc-notify-middleware.ts index ad2946c..dcfcc1a 100644 --- a/src/osc-notify-middleware.ts +++ b/src/osc-notify-middleware.ts @@ -4,6 +4,16 @@ import { Observable, Subject } from "rxjs"; const oscPrefix = Buffer.from("\x1b]"); const oscSuffix = Buffer.from("\x07"); +function cleanTitle(raw: string): string { + const t = (raw ?? "").trim(); + if (!t) return "Terminal"; + if (t.includes("/") || t.includes("\\")) { + const segs = t.split(/[/\\]/).filter(s => s.length > 0); + return segs.length ? segs[segs.length - 1] : t; + } + return t; +} + export default class OscNotifyMiddleware extends SessionMiddleware { getTitle: () => string; onClick: () => void; @@ -39,11 +49,11 @@ export default class OscNotifyMiddleware extends SessionMiddleware { const oscCode = parseInt(oscCodeString); if (oscCode === 9) { - const notification = new Notification(this.getTitle() || "Terminal", { - body: oscParams[0] - }); - notification.onclick = () => this.onClick(); - this.notifications.push(notification); + this.showNotification(cleanTitle(this.getTitle()), oscParams[0] ?? ""); + } else if (oscCode === 777 && oscParams[0] === "notify") { + const title = oscParams[1] || cleanTitle(this.getTitle()); + const body = oscParams.slice(2).join(";"); + this.showNotification(title, body); } else { continue; } @@ -52,6 +62,12 @@ export default class OscNotifyMiddleware extends SessionMiddleware { super.feedFromSession(data); } + private showNotification(title: string, body: string): void { + const notification = new Notification(title || "Terminal", { body }); + notification.onclick = () => this.onClick(); + this.notifications.push(notification); + } + close(): void { this.notifications.forEach((notification) => notification.close()); this.notifications = []; |
