地圖 (Jido) is a lightweight Unix TUI file explorer designed for speed and simplicity.
at v1.3.0 996 B view raw
1const std = @import("std"); 2const FileLogger = @import("file_logger.zig"); 3 4const Self = @This(); 5 6/// Seconds. 7pub const notification_timeout = 3; 8 9const Style = enum { 10 err, 11 info, 12 warn, 13}; 14 15var buf: [1024]u8 = undefined; 16 17style: Style = Style.info, 18fbs: std.io.FixedBufferStream([]u8) = std.io.fixedBufferStream(&buf), 19/// How long until the notification disappears in seconds. 20timer: i64 = 0, 21 22pub fn write(self: *Self, text: []const u8, style: Style) !void { 23 self.fbs.reset(); 24 _ = try self.fbs.write(text); 25 self.timer = std.time.timestamp(); 26 self.style = style; 27} 28 29pub fn reset(self: *Self) void { 30 self.fbs.reset(); 31 self.style = Style.info; 32} 33 34pub fn slice(self: *Self) []const u8 { 35 return self.fbs.getWritten(); 36} 37 38pub fn clearIfEnded(self: *Self) bool { 39 if (std.time.timestamp() - self.timer > notification_timeout) { 40 self.reset(); 41 return true; 42 } 43 44 return false; 45} 46 47pub fn len(self: Self) usize { 48 return self.fbs.pos; 49}