diff --git a/src/app.zig b/src/app.zig index 28781eb..3afd186 100644 --- a/src/app.zig +++ b/src/app.zig @@ -74,6 +74,7 @@ pub const Action = union(enum) { pub const Event = union(enum) { image_ready, + notification, key_press: Key, winsize: vaxis.Winsize, }; diff --git a/src/event_handlers.zig b/src/event_handlers.zig index fd58e1b..e91c13d 100644 --- a/src/event_handlers.zig +++ b/src/event_handlers.zig @@ -133,6 +133,7 @@ pub fn handleNormalEvent( } }, .image_ready => {}, + .notification => {}, .winsize => |ws| try app.vx.resize(app.alloc, app.tty.writer(), ws), } } @@ -283,6 +284,7 @@ pub fn handleInputEvent(app: *App, event: App.Event) !void { } }, .image_ready => {}, + .notification => {}, .winsize => |ws| try app.vx.resize(app.alloc, app.tty.writer(), ws), } } @@ -298,6 +300,7 @@ pub fn handleHelpMenuEvent(app: *App, event: App.Event) !void { } }, .image_ready => {}, + .notification => {}, .winsize => |ws| try app.vx.resize(app.alloc, app.tty.writer(), ws), } } diff --git a/src/notification.zig b/src/notification.zig index 4099a54..bd3054a 100644 --- a/src/notification.zig +++ b/src/notification.zig @@ -1,4 +1,7 @@ const std = @import("std"); +const vaxis = @import("vaxis"); +const Event = @import("app.zig").Event; + const FileLogger = @import("file_logger.zig"); const Self = @This(); @@ -18,12 +21,17 @@ style: Style = Style.info, fbs: std.io.FixedBufferStream([]u8) = std.io.fixedBufferStream(&buf), /// How long until the notification disappears in seconds. timer: i64 = 0, +loop: ?*vaxis.Loop(Event) = null, pub fn write(self: *Self, text: []const u8, style: Style) !void { self.fbs.reset(); _ = try self.fbs.write(text); self.timer = std.time.timestamp(); self.style = style; + + if (self.loop) |loop| { + loop.postEvent(.notification); + } } pub fn reset(self: *Self) void {