statusbar/src/main.zig

51 lines
1.6 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");
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 _display = display.init(arena.allocator());
var _battery = battery.init(arena.allocator());
var _calendar = calendar.init(arena.allocator());
var modules = [_]Module{
_display.module,
_battery.module,
_calendar.module,
};
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("[", .{});
// try json.stringify(battery_json, .{ .emit_null_optional_fields = false }, stdout);
// try stdout.print(",", .{});
// try json.stringify(calendar_json, .{ .emit_null_optional_fields = false }, stdout);
// try stdout.print(",", .{});
// try stdout.print("{{\"full_text\":\"test\"}}", .{});
try stdout.print("],\n", .{});
try bw.flush();
_ = arena.reset(.retain_capacity);
std.time.sleep(1000_000_000);
}
}