Time™
This commit is contained in:
parent
22995e9d34
commit
aaf62d0ccd
|
@ -17,7 +17,6 @@ pub fn build(b: *Builder) void {
|
|||
.name = "hzzp",
|
||||
.path = "deps/hzzp/src/main.zig",
|
||||
});
|
||||
|
||||
exe.setBuildMode(mode);
|
||||
const run_cmd = exe.run();
|
||||
|
||||
|
|
|
@ -48,8 +48,8 @@ pub const Bar = struct {
|
|||
|
||||
fn process(self: *Bar) !void {
|
||||
while (self.running) {
|
||||
std.time.sleep(1000 * std.time.ns_per_ms);
|
||||
return;
|
||||
std.time.sleep(5000 * std.time.ns_per_ms);
|
||||
//return;
|
||||
}
|
||||
}
|
||||
pub fn keep_running(self: *Bar) bool {
|
||||
|
|
|
@ -10,6 +10,8 @@ const DebugAllocator = @import("debug_allocator.zig");
|
|||
const Info = @import("types/info.zig").Info;
|
||||
|
||||
pub fn main() !void {
|
||||
std.debug.print("{}\n", .{@import("builtin").link_libc});
|
||||
|
||||
const debug: bool = true;
|
||||
var allocator: *std.mem.Allocator = undefined;
|
||||
var dbgAlloc: *DebugAllocator = undefined;
|
||||
|
|
|
@ -2,6 +2,7 @@ const std = @import("std");
|
|||
const Info = @import("../../types/info.zig").Info;
|
||||
const Bar = @import("../../types/bar.zig").Bar;
|
||||
const time = @import("time");
|
||||
const colour = @import("../../formatting/colour.zig").colour;
|
||||
|
||||
pub const TimeWidget = struct {
|
||||
bar: *Bar,
|
||||
|
@ -17,17 +18,78 @@ pub const TimeWidget = struct {
|
|||
.markup = "pango",
|
||||
};
|
||||
}
|
||||
|
||||
pub fn info(self: *TimeWidget) Info {
|
||||
return self.initial_info();
|
||||
}
|
||||
|
||||
pub fn start(self: *TimeWidget) anyerror!void {
|
||||
while (self.bar.keep_running()) {
|
||||
var arena = std.heap.ArenaAllocator.init(self.allocator);
|
||||
defer arena.deinit();
|
||||
var allocator = &arena.allocator;
|
||||
var local = time.Location.getLocal(allocator);
|
||||
var now = time.now(&local);
|
||||
std.debug.print("OwO: {}\n", .{now.date()});
|
||||
var date = now.date();
|
||||
var clock = now.clock();
|
||||
|
||||
var hour: isize = clock.hour;
|
||||
var end: []const u8 = "";
|
||||
if (hour >= 12) {
|
||||
if (hour >= 13) {
|
||||
hour = hour - 12;
|
||||
}
|
||||
end = "pm";
|
||||
} else {
|
||||
end = "am";
|
||||
}
|
||||
|
||||
var timeStr = try std.fmt.allocPrint(allocator, "{}{}{}{}{}{}", .{
|
||||
colour(allocator, "red", try std.fmt.allocPrint(allocator, "{d:0<2}", .{@intCast(u7, hour)})),
|
||||
colour(allocator, "accentlight", ":"),
|
||||
colour(allocator, "orange", try std.fmt.allocPrint(allocator, "{d:0<2}", .{@intCast(u7, clock.min)})),
|
||||
colour(allocator, "accentmedium", ":"),
|
||||
colour(allocator, "yellow", try std.fmt.allocPrint(allocator, "{d:0<2}", .{@intCast(u7, clock.sec)})),
|
||||
colour(allocator, "accentdark", end),
|
||||
});
|
||||
|
||||
var suffix: []const u8 = "th";
|
||||
if (@mod(date.day, 10) == 1) {
|
||||
if (@mod(date.day, 100) != 11) {
|
||||
suffix = "st";
|
||||
}
|
||||
} else if (@mod(date.day, 10) == 2) {
|
||||
if (@mod(date.day, 100) != 12) {
|
||||
suffix = "nd";
|
||||
}
|
||||
} else if (@mod(date.day, 10) == 3) {
|
||||
if (@mod(date.day, 100) != 13) {
|
||||
suffix = "rd";
|
||||
}
|
||||
}
|
||||
|
||||
var h = try std.fmt.allocPrint(allocator, "{} {} {}{} {} {} {} {} {} {}", .{
|
||||
colour(allocator, "green", now.weekday().string()),
|
||||
colour(allocator, "purple", "the"),
|
||||
colour(allocator, "yellow", try std.fmt.allocPrint(allocator, "{}", .{date.day})),
|
||||
colour(allocator, "accentmedium", suffix),
|
||||
colour(allocator, "purple", "of"),
|
||||
colour(allocator, "red", date.month.string()),
|
||||
colour(allocator, "purple", "in"),
|
||||
colour(allocator, "accentlight", try std.fmt.allocPrint(allocator, "{}", .{date.year})),
|
||||
colour(allocator, "purple", "at"),
|
||||
timeStr,
|
||||
});
|
||||
|
||||
try self.bar.add(Info{
|
||||
.name = "time",
|
||||
.full_text = h,
|
||||
.markup = "pango",
|
||||
});
|
||||
|
||||
std.debug.print("h\n", .{});
|
||||
std.time.sleep(200 * std.time.ns_per_ms);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue