statusbar/src/main.zig

49 lines
1.5 KiB
Zig
Raw Normal View History

2024-03-15 18:30:35 -06:00
const std = @import("std");
const io = std.io;
const heap = std.heap;
const json = std.json;
const battery = @import("modules/battery.zig");
const calendar = @import("modules/calendar.zig");
const display = @import("modules/display.zig");
const uptime = @import("modules/uptime.zig");
2024-03-15 19:42:39 -06:00
const volume = @import("modules/volume.zig");
2024-03-15 20:15:29 -06:00
const memory = @import("modules/memory.zig");
2024-03-16 10:15:04 -06:00
const loadavg = @import("modules/loadavg.zig");
2024-03-15 18:30:35 -06:00
const Module = @import("module.zig");
pub fn main() !void {
var arena = heap.ArenaAllocator.init(heap.page_allocator);
defer arena.deinit();
const stdout_file = std.io.getStdOut().writer();
var bw = std.io.bufferedWriter(stdout_file);
const stdout = bw.writer();
try stdout.print("{{\"version\":1}}\n[\n", .{});
try bw.flush();
var modules = [_]Module{
2024-03-15 19:15:59 -06:00
uptime.init(arena.allocator()).module,
2024-03-16 10:15:04 -06:00
loadavg.init(arena.allocator()).module,
2024-03-15 20:15:29 -06:00
memory.init(arena.allocator()).module,
2024-03-15 19:42:39 -06:00
volume.init(arena.allocator()).module,
2024-03-15 19:15:59 -06:00
display.init(arena.allocator()).module,
battery.init(arena.allocator()).module,
calendar.init(arena.allocator()).module,
2024-03-15 18:30:35 -06:00
};
while (true) {
try stdout.print("[", .{});
for (modules) |module| {
try json.stringify(try module.getJson(), .{ .emit_null_optional_fields = false }, stdout);
try stdout.print(",", .{});
}
try stdout.print("],\n", .{});
try bw.flush();
_ = arena.reset(.retain_capacity);
std.time.sleep(1000_000_000);
}
}