u
This commit is contained in:
parent
4a027944a3
commit
22995e9d34
2
.gitmodules
vendored
2
.gitmodules
vendored
|
@ -3,7 +3,7 @@
|
||||||
url = https://github.com/alexnask/interface.zig
|
url = https://github.com/alexnask/interface.zig
|
||||||
[submodule "deps/time"]
|
[submodule "deps/time"]
|
||||||
path = deps/time
|
path = deps/time
|
||||||
url = https://github.com/gernest/time
|
url = https://github.com/purringChaos/time
|
||||||
[submodule "deps/hzzp"]
|
[submodule "deps/hzzp"]
|
||||||
path = deps/hzzp
|
path = deps/hzzp
|
||||||
url = https://github.com/truemedian/hzzp
|
url = https://github.com/truemedian/hzzp
|
||||||
|
|
|
@ -9,6 +9,10 @@ pub fn build(b: *Builder) void {
|
||||||
.name = "interfaces",
|
.name = "interfaces",
|
||||||
.path = "deps/interfaces/interface.zig",
|
.path = "deps/interfaces/interface.zig",
|
||||||
});
|
});
|
||||||
|
exe.addPackage(.{
|
||||||
|
.name = "time",
|
||||||
|
.path = "deps/time/src/time.zig",
|
||||||
|
});
|
||||||
exe.addPackage(.{
|
exe.addPackage(.{
|
||||||
.name = "hzzp",
|
.name = "hzzp",
|
||||||
.path = "deps/hzzp/src/main.zig",
|
.path = "deps/hzzp/src/main.zig",
|
||||||
|
|
1
deps/time
vendored
Submodule
1
deps/time
vendored
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 04d7cb5a54fbbc0399fd9299b71f461b5bf4ae2c
|
|
@ -47,10 +47,8 @@ pub const Bar = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process(self: *Bar) !void {
|
fn process(self: *Bar) !void {
|
||||||
var i: i32 = 0;
|
|
||||||
while (self.running) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,8 +80,6 @@ pub const Bar = struct {
|
||||||
for (self.infos.items) |infoItem, index| {
|
for (self.infos.items) |infoItem, index| {
|
||||||
if (std.mem.eql(u8, infoItem.name, info.name)) {
|
if (std.mem.eql(u8, infoItem.name, info.name)) {
|
||||||
if (std.mem.eql(u8, infoItem.full_text, info.full_text)) {
|
if (std.mem.eql(u8, infoItem.full_text, info.full_text)) {
|
||||||
std.debug.warn("dupe!: {}\n", .{info.name});
|
|
||||||
|
|
||||||
// OK so info is a dupe, we don't care about dupes so we don't do anything.
|
// OK so info is a dupe, we don't care about dupes so we don't do anything.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
78
src/main.zig
78
src/main.zig
|
@ -4,78 +4,40 @@ const Widget = @import("types/widget.zig").Widget;
|
||||||
const barImpl = @import("bar/bar.zig");
|
const barImpl = @import("bar/bar.zig");
|
||||||
const textWidget = @import("widgets/text/text.zig");
|
const textWidget = @import("widgets/text/text.zig");
|
||||||
const weatherWidget = @import("widgets/weather/weather.zig");
|
const weatherWidget = @import("widgets/weather/weather.zig");
|
||||||
const DebugAllocator = @import("debug_allocator.zig");
|
const timeWidget = @import("widgets/time/time.zig");
|
||||||
const colour = @import("formatting/colour.zig").colour;
|
|
||||||
|
|
||||||
|
const DebugAllocator = @import("debug_allocator.zig");
|
||||||
const Info = @import("types/info.zig").Info;
|
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 {
|
pub fn main() !void {
|
||||||
const dbgAlloc = &DebugAllocator.init(std.heap.page_allocator, 8192 * 512);
|
const debug: bool = true;
|
||||||
defer {
|
var allocator: *std.mem.Allocator = undefined;
|
||||||
std.debug.print("Finished cleanup, last allocation info.\n", .{});
|
var dbgAlloc: *DebugAllocator = undefined;
|
||||||
std.debug.print("\n{}\n", .{dbgAlloc.info});
|
if (debug) {
|
||||||
dbgAlloc.printRemainingStackTraces();
|
dbgAlloc = &DebugAllocator.init(std.heap.page_allocator, 8192 * 8192);
|
||||||
dbgAlloc.deinit();
|
allocator = &dbgAlloc.allocator;
|
||||||
|
} else {
|
||||||
|
allocator = std.heap.page_allocator;
|
||||||
}
|
}
|
||||||
var allocator = &dbgAlloc.allocator;
|
|
||||||
//var allocator = std.heap.page_allocator;
|
|
||||||
|
|
||||||
var bar = barImpl.InitBar(allocator);
|
var bar = barImpl.InitBar(allocator);
|
||||||
var br = Bar.init(&bar);
|
var br = Bar.init(&bar);
|
||||||
|
|
||||||
const widgets = [_]*Widget{
|
const widgets = [_]*Widget{
|
||||||
&Widget.init(&textWidget.New("owo", "potato")),
|
&Widget.init(&textWidget.New("owo", "potato")),
|
||||||
&Widget.init(&textWidget.New("uwu", "potato")),
|
&Widget.init(&textWidget.New("uwu", "tomato")),
|
||||||
&Widget.init(&NewSpam(&br, "h")),
|
|
||||||
&Widget.init(&weatherWidget.New(allocator, &br, "London")),
|
&Widget.init(&weatherWidget.New(allocator, &br, "London")),
|
||||||
|
&Widget.init(&timeWidget.New(allocator, &br)),
|
||||||
|
|
||||||
|
//&Widget.init(&weatherWidget.New(allocator, &br, "Oxford")),
|
||||||
//&Widget.init(&weatherWidget.New(allocator, &br, "Newcastle")),
|
//&Widget.init(&weatherWidget.New(allocator, &br, "Newcastle")),
|
||||||
};
|
};
|
||||||
bar.widgets = widgets[0..];
|
bar.widgets = widgets[0..];
|
||||||
try br.start();
|
try br.start();
|
||||||
|
if (debug) {
|
||||||
|
std.debug.print("Finished cleanup, last allocation info.\n", .{});
|
||||||
|
std.debug.print("\n{}\n", .{dbgAlloc.info});
|
||||||
|
dbgAlloc.printRemainingStackTraces();
|
||||||
|
dbgAlloc.deinit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
39
src/widgets/time/time.zig
Normal file
39
src/widgets/time/time.zig
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
const std = @import("std");
|
||||||
|
const Info = @import("../../types/info.zig").Info;
|
||||||
|
const Bar = @import("../../types/bar.zig").Bar;
|
||||||
|
const time = @import("time");
|
||||||
|
|
||||||
|
pub const TimeWidget = struct {
|
||||||
|
bar: *Bar,
|
||||||
|
allocator: *std.mem.Allocator,
|
||||||
|
|
||||||
|
pub fn name(self: *TimeWidget) []const u8 {
|
||||||
|
return "time";
|
||||||
|
}
|
||||||
|
pub fn initial_info(self: *TimeWidget) Info {
|
||||||
|
return Info{
|
||||||
|
.name = "time",
|
||||||
|
.full_text = "TheTime™",
|
||||||
|
.markup = "pango",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
pub fn info(self: *TimeWidget) Info {
|
||||||
|
return self.initial_info();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn start(self: *TimeWidget) anyerror!void {
|
||||||
|
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()});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
pub inline fn New(allocator: *std.mem.Allocator, bar: *Bar) TimeWidget {
|
||||||
|
return TimeWidget{
|
||||||
|
.allocator = allocator,
|
||||||
|
.bar = bar,
|
||||||
|
};
|
||||||
|
}
|
|
@ -10,6 +10,8 @@ const DebugAllocator = @import("../../debug_allocator.zig");
|
||||||
const WeatherData = struct {
|
const WeatherData = struct {
|
||||||
temp: u16,
|
temp: u16,
|
||||||
main: []const u8,
|
main: []const u8,
|
||||||
|
code: i16,
|
||||||
|
message: []const u8,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const WeatherWidget = struct {
|
pub const WeatherWidget = struct {
|
||||||
|
@ -48,10 +50,15 @@ pub const WeatherWidget = struct {
|
||||||
|
|
||||||
var isNextTemp: bool = false;
|
var isNextTemp: bool = false;
|
||||||
var isNextMain: bool = false;
|
var isNextMain: bool = false;
|
||||||
|
var isNextCode: bool = false;
|
||||||
|
var isNextMessage: bool = false;
|
||||||
|
|
||||||
var foundMain: bool = false;
|
var foundMain: bool = false;
|
||||||
|
|
||||||
var temp: u16 = undefined;
|
var temp: u16 = 0;
|
||||||
var main: []const u8 = undefined;
|
var code: i16 = 0;
|
||||||
|
var main: []const u8 = "";
|
||||||
|
var message: []const u8 = "";
|
||||||
|
|
||||||
while (try client.readEvent()) |event| {
|
while (try client.readEvent()) |event| {
|
||||||
switch (event) {
|
switch (event) {
|
||||||
|
@ -69,17 +76,37 @@ pub const WeatherWidget = struct {
|
||||||
isNextMain = true;
|
isNextMain = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (std.mem.eql(u8, str, "cod")) {
|
||||||
|
isNextCode = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (std.mem.eql(u8, str, "message")) {
|
||||||
|
isNextMessage = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (isNextMain) {
|
if (isNextMain) {
|
||||||
main = str;
|
main = str;
|
||||||
isNextMain = false;
|
isNextMain = false;
|
||||||
foundMain = true;
|
foundMain = true;
|
||||||
}
|
}
|
||||||
|
if (isNextMessage) {
|
||||||
|
message = str;
|
||||||
|
}
|
||||||
|
if (isNextCode) {
|
||||||
|
// why the fuck would you make code both a string and a int are you wanting me to question my sanity???
|
||||||
|
isNextCode = false;
|
||||||
|
code = try std.fmt.parseInt(i16, str, 10);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
.Number => |num| {
|
.Number => |num| {
|
||||||
if (isNextTemp) {
|
if (isNextTemp) {
|
||||||
isNextTemp = false;
|
isNextTemp = false;
|
||||||
temp = @floatToInt(u16, std.math.round(try std.fmt.parseFloat(f32, num.slice(tokens.slice, tokens.i - 1))));
|
temp = @floatToInt(u16, std.math.round(try std.fmt.parseFloat(f32, num.slice(tokens.slice, tokens.i - 1))));
|
||||||
}
|
}
|
||||||
|
if (isNextCode) {
|
||||||
|
isNextCode = false;
|
||||||
|
code = try std.fmt.parseInt(i16, num.slice(tokens.slice, tokens.i - 1), 10);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
|
@ -88,18 +115,17 @@ pub const WeatherWidget = struct {
|
||||||
.status, .header, .head_complete, .closed, .end, .invalid => continue,
|
.status, .header, .head_complete, .closed, .end, .invalid => continue,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return WeatherData{ .temp = temp, .main = main };
|
return WeatherData{ .temp = temp, .main = main, .code = code, .message = message };
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_info(self: *WeatherWidget) anyerror!void {
|
fn update_info(self: *WeatherWidget) anyerror!void {
|
||||||
std.debug.print("uwu!!\n", .{});
|
|
||||||
|
|
||||||
var inf: WeatherData = undefined;
|
var inf: WeatherData = undefined;
|
||||||
var arena = std.heap.ArenaAllocator.init(self.allocator);
|
var arena = std.heap.ArenaAllocator.init(self.allocator);
|
||||||
defer arena.deinit();
|
defer arena.deinit();
|
||||||
var arenacator = &arena.allocator;
|
var arenacator = &arena.allocator;
|
||||||
if (self.get_weather_info(arenacator)) |i| {
|
if (self.get_weather_info(arenacator)) |i| {
|
||||||
inf = i;
|
inf = i;
|
||||||
|
//std.debug.print("{}", .{i});
|
||||||
} else |err| switch (err) {
|
} else |err| switch (err) {
|
||||||
error.TemporaryNameServerFailure => {
|
error.TemporaryNameServerFailure => {
|
||||||
try self.bar.add(Info{
|
try self.bar.add(Info{
|
||||||
|
@ -120,6 +146,15 @@ pub const WeatherWidget = struct {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (inf.code != 200) {
|
||||||
|
try self.bar.add(Info{
|
||||||
|
.name = self.name,
|
||||||
|
.full_text = try std.fmt.allocPrint(arenacator, "Weather API Failed: {}", .{inf.message}),
|
||||||
|
.markup = "pango",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var temp = inf.temp;
|
var temp = inf.temp;
|
||||||
var main = inf.main;
|
var main = inf.main;
|
||||||
|
|
||||||
|
@ -148,6 +183,7 @@ pub const WeatherWidget = struct {
|
||||||
pub fn start(self: *WeatherWidget) anyerror!void {
|
pub fn start(self: *WeatherWidget) anyerror!void {
|
||||||
while (self.bar.keep_running()) {
|
while (self.bar.keep_running()) {
|
||||||
try self.update_info();
|
try self.update_info();
|
||||||
|
std.time.sleep(1000 * std.time.ns_per_ms);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue