Unknown state [2025-08-04]
This commit is contained in:
29
statusline/Time.zig
Normal file
29
statusline/Time.zig
Normal file
@@ -0,0 +1,29 @@
|
||||
const std = @import("std");
|
||||
const Self = @This();
|
||||
|
||||
const time = @cImport({
|
||||
@cInclude("time.h");
|
||||
});
|
||||
|
||||
buf: []u8,
|
||||
|
||||
pub fn init(self: *Self, alloc: std.mem.Allocator) !void {
|
||||
self.buf = try alloc.alloc(u8, 64);
|
||||
errdefer alloc.free(self.buf);
|
||||
}
|
||||
|
||||
pub fn update(self: *Self) ![]const u8 {
|
||||
const tt: time.time_t = time.time(null);
|
||||
const tp = time.localtime(&tt);
|
||||
const n = time.strftime(
|
||||
self.buf.ptr,
|
||||
self.buf.len,
|
||||
"%c",
|
||||
tp,
|
||||
);
|
||||
return self.buf[0..n];
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Self, alloc: std.mem.Allocator) void {
|
||||
alloc.free(self.buf);
|
||||
}
|
Reference in New Issue
Block a user