Time™
This commit is contained in:
parent
22995e9d34
commit
aaf62d0ccd
|
@ -17,7 +17,6 @@ pub fn build(b: *Builder) void {
|
||||||
.name = "hzzp",
|
.name = "hzzp",
|
||||||
.path = "deps/hzzp/src/main.zig",
|
.path = "deps/hzzp/src/main.zig",
|
||||||
});
|
});
|
||||||
|
|
||||||
exe.setBuildMode(mode);
|
exe.setBuildMode(mode);
|
||||||
const run_cmd = exe.run();
|
const run_cmd = exe.run();
|
||||||
|
|
||||||
|
|
|
@ -48,8 +48,8 @@ pub const Bar = struct {
|
||||||
|
|
||||||
fn process(self: *Bar) !void {
|
fn process(self: *Bar) !void {
|
||||||
while (self.running) {
|
while (self.running) {
|
||||||
std.time.sleep(1000 * std.time.ns_per_ms);
|
std.time.sleep(5000 * std.time.ns_per_ms);
|
||||||
return;
|
//return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn keep_running(self: *Bar) bool {
|
pub fn keep_running(self: *Bar) bool {
|
||||||
|
|
|
@ -10,6 +10,8 @@ const DebugAllocator = @import("debug_allocator.zig");
|
||||||
const Info = @import("types/info.zig").Info;
|
const Info = @import("types/info.zig").Info;
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
|
std.debug.print("{}\n", .{@import("builtin").link_libc});
|
||||||
|
|
||||||
const debug: bool = true;
|
const debug: bool = true;
|
||||||
var allocator: *std.mem.Allocator = undefined;
|
var allocator: *std.mem.Allocator = undefined;
|
||||||
var dbgAlloc: *DebugAllocator = undefined;
|
var dbgAlloc: *DebugAllocator = undefined;
|
||||||
|
|
|
@ -2,6 +2,7 @@ const std = @import("std");
|
||||||
const Info = @import("../../types/info.zig").Info;
|
const Info = @import("../../types/info.zig").Info;
|
||||||
const Bar = @import("../../types/bar.zig").Bar;
|
const Bar = @import("../../types/bar.zig").Bar;
|
||||||
const time = @import("time");
|
const time = @import("time");
|
||||||
|
const colour = @import("../../formatting/colour.zig").colour;
|
||||||
|
|
||||||
pub const TimeWidget = struct {
|
pub const TimeWidget = struct {
|
||||||
bar: *Bar,
|
bar: *Bar,
|
||||||
|
@ -17,17 +18,78 @@ pub const TimeWidget = struct {
|
||||||
.markup = "pango",
|
.markup = "pango",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn info(self: *TimeWidget) Info {
|
pub fn info(self: *TimeWidget) Info {
|
||||||
return self.initial_info();
|
return self.initial_info();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start(self: *TimeWidget) anyerror!void {
|
pub fn start(self: *TimeWidget) anyerror!void {
|
||||||
var arena = std.heap.ArenaAllocator.init(self.allocator);
|
while (self.bar.keep_running()) {
|
||||||
defer arena.deinit();
|
var arena = std.heap.ArenaAllocator.init(self.allocator);
|
||||||
var allocator = &arena.allocator;
|
defer arena.deinit();
|
||||||
var local = time.Location.getLocal(allocator);
|
var allocator = &arena.allocator;
|
||||||
var now = time.now(&local);
|
var local = time.Location.getLocal(allocator);
|
||||||
std.debug.print("OwO: {}\n", .{now.date()});
|
var now = time.now(&local);
|
||||||
|
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