| 1 | package ansi |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "strings" |
| 6 | ) |
| 7 | |
| 8 | // Notify sends a desktop notification using iTerm's OSC 9. |
| 9 | // |
| 10 | // OSC 9 ; Mc ST |
| 11 | // OSC 9 ; Mc BEL |
| 12 | // |
| 13 | // Where Mc is the notification body. |
| 14 | // |
| 15 | // See: https://iterm2.com/documentation-escape-codes.html |
| 16 | func Notify(s string) string { |
| 17 | return "\x1b]9;" + s + "\x07" |
| 18 | } |
| 19 | |
| 20 | // DesktopNotification sends a desktop notification based on the extensible OSC |
| 21 | // 99 escape code. |
| 22 | // |
| 23 | // OSC 99 ; <metadata> ; <payload> ST |
| 24 | // OSC 99 ; <metadata> ; <payload> BEL |
| 25 | // |
| 26 | // Where <metadata> is a colon-separated list of key-value pairs, and |
| 27 | // <payload> is the notification body. |
| 28 | // |
| 29 | // See: https://sw.kovidgoyal.net/kitty/desktop-notifications/ |
| 30 | func DesktopNotification(payload string, metadata ...string) string { |
| 31 | return fmt.Sprintf("\x1b]99;%s;%s\x07", strings.Join(metadata, ":"), payload) |
| 32 | } |