vaxis: implement osc9 and osc777 notifications

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
This commit is contained in:
Tim Culverhouse 2024-01-24 13:15:04 -06:00
parent 3d6f42a66e
commit 33d43dc6d1
5 changed files with 26 additions and 2 deletions

View file

@ -24,8 +24,8 @@ Contributions are welcome.
| Styled Underlines | ✅ | ✅ | ✅ | | Styled Underlines | ✅ | ✅ | ✅ |
| Mouse Shapes (OSC 22) | ✅ | planned | ❌ | | Mouse Shapes (OSC 22) | ✅ | planned | ❌ |
| System Clipboard (OSC 52) | ✅ | planned | ❌ | | System Clipboard (OSC 52) | ✅ | planned | ❌ |
| System Notifications (OSC 9) | ✅ | planned | ❌ | | System Notifications (OSC 9) | ✅ | | ❌ |
| System Notifications (OSC 777) | ✅ | planned | ❌ | | System Notifications (OSC 777) | ✅ | | ❌ |
| Synchronized Output (DEC 2026) | ✅ | ✅ | ✅ | | Synchronized Output (DEC 2026) | ✅ | ✅ | ✅ |
| Unicode Core (DEC 2027) | ✅ | ✅ | ❌ | | Unicode Core (DEC 2027) | ✅ | ✅ | ❌ |
| Color Mode Updates (DEC 2031) | ✅ | planned | ❌ | | Color Mode Updates (DEC 2031) | ✅ | planned | ❌ |

View file

@ -71,6 +71,8 @@ pub fn main() !void {
break :outer; break :outer;
} else if (key.matches('l', .{ .ctrl = true })) { } else if (key.matches('l', .{ .ctrl = true })) {
vx.queueRefresh(); vx.queueRefresh();
} else if (key.matches('n', .{ .ctrl = true })) {
try vx.notify("vaxis", "hello from vaxis");
} else { } else {
try text_input.update(.{ .key_press = key }); try text_input.update(.{ .key_press = key });
} }

View file

@ -22,6 +22,8 @@ pub const Style = struct {
bg: Color = .default, bg: Color = .default,
ul: Color = .default, ul: Color = .default,
ul_style: Underline = .off, ul_style: Underline = .off,
// TODO: url should maybe go outside of style. We'll need to allocate these
// in the internal screen
url: ?[]const u8 = null, url: ?[]const u8 = null,
url_params: ?[]const u8 = null, url_params: ?[]const u8 = null,

View file

@ -76,3 +76,5 @@ pub const strikethrough_reset = "\x1b[29m";
// OSC sequences // OSC sequences
pub const osc8 = "\x1b]8;{s};{s}\x1b\\"; pub const osc8 = "\x1b]8;{s};{s}\x1b\\";
pub const osc8_clear = "\x1b]8;;\x1b\\"; pub const osc8_clear = "\x1b]8;;\x1b\\";
pub const osc9_notify = "\x1b]9;{s}\x1b\\";
pub const osc777_notify = "\x1b]777;notify;{s};{s}\x1b\\";

View file

@ -472,6 +472,24 @@ pub fn Vaxis(comptime T: type) type {
); );
try self.tty.?.flush(); try self.tty.?.flush();
} }
/// send a system notification
pub fn notify(self: *Self, title: ?[]const u8, body: []const u8) !void {
if (self.tty == null) return;
if (title) |t| {
try std.fmt.format(
self.tty.?.buffered_writer.writer(),
ctlseqs.osc777_notify,
.{ t, body },
);
} else {
try std.fmt.format(
self.tty.?.buffered_writer.writer(),
ctlseqs.osc9_notify,
.{body},
);
}
}
}; };
} }