1
0
Fork 0
This commit is contained in:
namedkitten 2020-07-09 19:22:01 +01:00
parent 20d3dc4dfc
commit 4a027944a3
2 changed files with 67 additions and 11 deletions

View file

@ -15,11 +15,16 @@ pub const Bar = struct {
for (self.widgets) |w| {
std.debug.warn("Adding Initial Info: {}\n", .{w.name()});
try self.infos.append(try self.dupe_info(w.initial_info()));
}
try self.print_infos(true);
for (self.widgets) |w| {
std.debug.warn("Starting widget: {}\n", .{w.name()});
var thread = try std.Thread.spawn(w, Widget.start);
}
var thread = try std.Thread.spawn(self, Bar.process);
thread.wait();
self.running = false;
std.time.sleep(1000 * std.time.ns_per_ms);
for (self.infos.items) |info| {
try self.free_info(info);
}
@ -45,7 +50,8 @@ pub const Bar = struct {
var i: i32 = 0;
while (self.running) {
//try self.print_infos(true);
std.time.sleep(1000 * std.time.ns_per_ms);
std.time.sleep(10000 * std.time.ns_per_ms);
return;
}
}
pub fn keep_running(self: *Bar) bool {

View file

@ -7,24 +7,74 @@ const weatherWidget = @import("widgets/weather/weather.zig");
const DebugAllocator = @import("debug_allocator.zig");
const colour = @import("formatting/colour.zig").colour;
const Info = @import("types/info.zig").Info;
pub const SpamWidget = struct {
name: []const u8,
bar: *Bar,
pub fn name(self: *SpamWidget) []const u8 {
return self.name;
}
pub fn initial_info(self: *SpamWidget) Info {
return Info{
.name = self.name,
.full_text = "uwu",
.markup = "pango",
};
}
pub fn info(self: *SpamWidget) Info {
return self.initial_info();
}
pub fn start(self: *SpamWidget) anyerror!void {
var h: bool = true;
while (self.bar.keep_running()) {
h = !h;
if (h) {
try self.bar.add(Info{
.name = self.name,
.full_text = "uwu",
.markup = "pango",
});
} else {
try self.bar.add(Info{
.name = self.name,
.full_text = "owo",
.markup = "pango",
});
}
}
}
};
pub inline fn NewSpam(bar: *Bar, name: []const u8) SpamWidget {
return SpamWidget{
.name = name,
.bar = bar,
};
}
pub fn main() !void {
//const dbgAlloc = &DebugAllocator.init(std.heap.page_allocator, 8192 * 512);
//defer {
// std.debug.print("Finished cleanup, last allocation info.\n", .{});
// std.debug.print("\n{}\n", .{dbgAlloc.info});
// dbgAlloc.printRemainingStackTraces();
// dbgAlloc.deinit();
//}
//var allocator = &dbgAlloc.allocator;
var allocator = std.heap.page_allocator;
const dbgAlloc = &DebugAllocator.init(std.heap.page_allocator, 8192 * 512);
defer {
std.debug.print("Finished cleanup, last allocation info.\n", .{});
std.debug.print("\n{}\n", .{dbgAlloc.info});
dbgAlloc.printRemainingStackTraces();
dbgAlloc.deinit();
}
var allocator = &dbgAlloc.allocator;
//var allocator = std.heap.page_allocator;
var bar = barImpl.InitBar(allocator);
var br = Bar.init(&bar);
const widgets = [_]*Widget{
&Widget.init(&textWidget.New("owo", "potato")),
&Widget.init(&textWidget.New("uwu", "potato")),
&Widget.init(&NewSpam(&br, "h")),
&Widget.init(&weatherWidget.New(allocator, &br, "London")),
&Widget.init(&weatherWidget.New(allocator, &br, "Newcastle")),
//&Widget.init(&weatherWidget.New(allocator, &br, "Newcastle")),
};
bar.widgets = widgets[0..];
try br.start();