1
0
Fork 0

Updated to zig v0.8.0.

This commit is contained in:
purringChaos 2021-03-31 14:43:35 +01:00
parent 36b3429c2c
commit 8bb45d6553
14 changed files with 60 additions and 73 deletions

View file

@ -6,7 +6,7 @@ const assert = std.debug.assert;
const expect = std.testing.expect; const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual; const expectEqual = std.testing.expectEqual;
pub const SelfType = @Type(.Opaque); pub const SelfType = opaque{};
fn makeSelfPtr(ptr: anytype) *SelfType { fn makeSelfPtr(ptr: anytype) *SelfType {
if (comptime !trait.isSingleItemPtr(@TypeOf(ptr))) { if (comptime !trait.isSingleItemPtr(@TypeOf(ptr))) {

View file

@ -27,7 +27,7 @@ pub const Bar = struct {
widgets: []const *Widget, widgets: []const *Widget,
running: bool, running: bool,
infos: std.ArrayList(Info), infos: std.ArrayList(Info),
items_mutex: std.Mutex, items_mutex: std.Thread.Mutex,
out_file: std.fs.File, out_file: std.fs.File,
pub fn start(self: *Bar) !void { pub fn start(self: *Bar) !void {
self.running = true; self.running = true;
@ -48,9 +48,9 @@ pub const Bar = struct {
log.debug("Spawning threads.\n", .{}); log.debug("Spawning threads.\n", .{});
for (self.widgets) |w| { for (self.widgets) |w| {
log.debug("Spawning thread=\"{}\"\n", .{w.name()}); log.debug("Spawning thread=\"{}\"\n", .{w.name()});
var thread = try std.Thread.spawn(w, Widget.start); var thread = try std.Thread.spawn(Widget.start, w);
} }
_ = try std.Thread.spawn(self, Bar.process); _ = try std.Thread.spawn(Bar.process, self);
log.info("Waiting for kill signal.\n", .{}); log.info("Waiting for kill signal.\n", .{});
while (true) { while (true) {
@ -75,8 +75,7 @@ pub const Bar = struct {
try self.out_file.writer().writeAll("\u{001b}[?1000;1006;1015l"); try self.out_file.writer().writeAll("\u{001b}[?1000;1006;1015l");
} }
} }
fn print_i3bar_infos(self: *Bar) callconv(.Inline) !void {
inline fn print_i3bar_infos(self: *Bar) !void {
// Serialize all bar items and put on stdout. // Serialize all bar items and put on stdout.
try self.out_file.writer().writeAll("["); try self.out_file.writer().writeAll("[");
for (self.infos.items) |info, i| { for (self.infos.items) |info, i| {
@ -88,8 +87,7 @@ pub const Bar = struct {
} }
try self.out_file.writer().writeAll("],\n"); try self.out_file.writer().writeAll("],\n");
} }
fn print_terminal_infos(self: *Bar) callconv(.Inline) !void {
inline fn print_terminal_infos(self: *Bar) !void {
// For terminal we just need to directly print. // For terminal we just need to directly print.
for (self.infos.items) |info, i| { for (self.infos.items) |info, i| {
try self.out_file.writer().writeAll(info.full_text); try self.out_file.writer().writeAll(info.full_text);
@ -121,8 +119,7 @@ pub const Bar = struct {
} }
} }
} }
fn terminal_input_process(self: *Bar) callconv(.Inline) !void {
inline fn terminal_input_process(self: *Bar) !void {
// TODO: make work on other OSes other than xterm compatable terminals. // TODO: make work on other OSes other than xterm compatable terminals.
// Write to stdout that we want to recieve all terminal click events. // Write to stdout that we want to recieve all terminal click events.
@ -133,7 +130,7 @@ pub const Bar = struct {
termios.iflag &= ~@as( termios.iflag &= ~@as(
os.tcflag_t, os.tcflag_t,
os.IGNBRK | os.BRKINT | os.PARMRK | os.ISTRIP | os.IGNBRK | os.BRKINT | os.PARMRK | os.ISTRIP |
os.INLCR | os.IGNCR | os.ICRNL | os.IXON, os.INLCR | os.IGNCR | os.ICRNL | os.IXON,
); );
// Disable echo so that you don't see mouse events in terminal. // Disable echo so that you don't see mouse events in terminal.
termios.lflag |= ~@as(os.tcflag_t, (os.ECHO | os.ICANON)); termios.lflag |= ~@as(os.tcflag_t, (os.ECHO | os.ICANON));
@ -145,7 +142,7 @@ pub const Bar = struct {
while (self.running) { while (self.running) {
var line_buffer: [128]u8 = undefined; var line_buffer: [128]u8 = undefined;
// 0x1b is the ESC key which is used for sending and recieving events to xterm terminals. // 0x1b is the ESC key which is used for sending and recieving events to xterm terminals.
const line_opt = try std.io.getStdIn().inStream().readUntilDelimiterOrEof(&line_buffer, 0x1b); const line_opt = try std.io.getStdIn().reader().readUntilDelimiterOrEof(&line_buffer, 0x1b);
if (line_opt) |l| { if (line_opt) |l| {
// I honestly have no idea what this does but I assume that it checks // I honestly have no idea what this does but I assume that it checks
// that this is the right event? // that this is the right event?
@ -200,11 +197,10 @@ pub const Bar = struct {
} }
} }
} }
fn i3bar_input_process(self: *Bar) callconv(.Inline) !void {
inline fn i3bar_input_process(self: *Bar) !void {
var line_buffer: [512]u8 = undefined; var line_buffer: [512]u8 = undefined;
while (self.running) { while (self.running) {
const line_opt = try std.io.getStdIn().inStream().readUntilDelimiterOrEof(&line_buffer, '\n'); const line_opt = try std.io.getStdIn().reader().readUntilDelimiterOrEof(&line_buffer, '\n');
if (line_opt) |l| { if (line_opt) |l| {
var line = l; var line = l;
if (std.mem.eql(u8, line, "[")) continue; if (std.mem.eql(u8, line, "[")) continue;
@ -217,6 +213,7 @@ pub const Bar = struct {
// Anyway this just strips off the prefix of ',' so I can parse the json. // Anyway this just strips off the prefix of ',' so I can parse the json.
if (line[0] == ',') line = line[1..line.len]; if (line[0] == ',') line = line[1..line.len];
const parseOptions = std.json.ParseOptions{ .allocator = self.allocator }; const parseOptions = std.json.ParseOptions{ .allocator = self.allocator };
@setEvalBranchQuota(9999999);
const data = try std.json.parse(MouseEvent, &std.json.TokenStream.init(line), parseOptions); const data = try std.json.parse(MouseEvent, &std.json.TokenStream.init(line), parseOptions);
defer std.json.parseFree(MouseEvent, data, parseOptions); defer std.json.parseFree(MouseEvent, data, parseOptions);
@ -306,7 +303,7 @@ pub fn initBar(allocator: *std.mem.Allocator) Bar {
.widgets = undefined, .widgets = undefined,
.running = false, .running = false,
.infos = std.ArrayList(Info).init(allocator), .infos = std.ArrayList(Info).init(allocator),
.items_mutex = std.Mutex{}, .items_mutex = std.Thread.Mutex{},
.out_file = std.io.getStdOut(), .out_file = std.io.getStdOut(),
}; };
} }

View file

@ -85,14 +85,14 @@ allocation_strack_addresses: std.AutoHashMap(usize, [stack_addresses_size]usize)
// Interface implementation // Interface implementation
allocator: std.mem.Allocator, allocator: std.mem.Allocator,
mutex: std.Mutex, mutex: std.Thread.Mutex,
pub fn init(base_allocator: *std.mem.Allocator, max_bytes: usize) DebugAllocator { pub fn init(base_allocator: *std.mem.Allocator, max_bytes: usize) DebugAllocator {
return .{ return .{
.base_allocator = base_allocator, .base_allocator = base_allocator,
.info = .{}, .info = .{},
.max_bytes = max_bytes, .max_bytes = max_bytes,
.mutex = std.Mutex.init(), .mutex = std.Thread.Mutex.init(),
.allocation_strack_addresses = std.AutoHashMap(usize, [stack_addresses_size]usize).init(base_allocator), .allocation_strack_addresses = std.AutoHashMap(usize, [stack_addresses_size]usize).init(base_allocator),
.allocator = .{ .allocator = .{
.allocFn = alloc, .allocFn = alloc,

View file

@ -27,8 +27,7 @@ const TerminalOrangeColour = "\u{001b}[31;1m";
const TerminalYellowColour = "\u{001b}[33m"; const TerminalYellowColour = "\u{001b}[33m";
const TerminalGreenColour = "\u{001b}[32m"; const TerminalGreenColour = "\u{001b}[32m";
const TerminalPurpleColour = "\u{001b}[35m"; const TerminalPurpleColour = "\u{001b}[35m";
fn getColourFromColour(clr: []const u8) callconv(.Inline) []const u8 {
inline fn getColourFromColour(clr: []const u8) []const u8 {
if (clr[0] == '#' or clr[0] == '\u{001b}') { if (clr[0] == '#' or clr[0] == '\u{001b}') {
return clr; return clr;
} else if (eql(u8, clr, "text")) { } else if (eql(u8, clr, "text")) {
@ -74,8 +73,8 @@ pub fn colour(alloc: *std.mem.Allocator, clr: []const u8, str: []const u8) ![]co
if (disable_colour) return str; if (disable_colour) return str;
const proper_colour = getColourFromColour(clr); const proper_colour = getColourFromColour(clr);
if (terminal_version) { if (terminal_version) {
return try std.fmt.allocPrint(alloc, "{}{}" ++ TerminalResetColour, .{ proper_colour, str }); return try std.fmt.allocPrint(alloc, "{s}{s}" ++ TerminalResetColour, .{ proper_colour, str });
} else { } else {
return try std.fmt.allocPrint(alloc, "<span color=\"{}\">{}</span>", .{ proper_colour, str }); return try std.fmt.allocPrint(alloc, "<span color=\"{s}\">{s}</span>", .{ proper_colour, str });
} }
} }

View file

@ -71,7 +71,7 @@ pub fn main() !void {
&Widget.init(&cpuWidget.New(&br)), // 4.08KiB &Widget.init(&cpuWidget.New(&br)), // 4.08KiB
&Widget.init(&memoryWidget.New(&br)), // 4.08KiB &Widget.init(&memoryWidget.New(&br)), // 4.08KiB
&Widget.init(&weatherWidget.New(allocator, &br, @import("build_options").weather_location)), // 16.16KiB &Widget.init(&weatherWidget.New(allocator, &br, @import("build_options").weather_location)), // 16.16KiB
&Widget.init(&batteryWidget.New(allocator, &br)), // 12.11KiB //&Widget.init(&batteryWidget.New(allocator, &br)), // 12.11KiB
&Widget.init(&timeWidget.New(allocator, &br)), // 32.46KiB &Widget.init(&timeWidget.New(allocator, &br)), // 32.46KiB
}; };
bar.widgets = widgets[0..]; bar.widgets = widgets[0..];

View file

@ -11,7 +11,7 @@ pub const Bar = struct {
}, interface.Storage.NonOwning); }, interface.Storage.NonOwning);
iface: IFace, iface: IFace,
pub fn init(impl_ptr: anytype) Bar { pub fn init(impl_ptr: anytype) Bar {
return .{ .iface = try IFace.init(impl_ptr) }; return .{ .iface = try IFace.init(impl_ptr) };
} }
pub fn keep_running(self: *Bar) bool { pub fn keep_running(self: *Bar) bool {
return self.iface.call("keep_running", .{}); return self.iface.call("keep_running", .{});

View file

@ -14,7 +14,7 @@ pub const Widget = struct {
}, interface.Storage.NonOwning); }, interface.Storage.NonOwning);
iface: IFace, iface: IFace,
pub fn init(impl_ptr: anytype) Widget { pub fn init(impl_ptr: anytype) Widget {
return .{ .iface = try IFace.init(impl_ptr) }; return .{ .iface = try IFace.init(impl_ptr) };
} }
pub fn name(self: *Widget) []const u8 { pub fn name(self: *Widget) []const u8 {
return self.iface.call("name", .{}); return self.iface.call("name", .{});

View file

@ -62,29 +62,29 @@ pub const BatteryWidget = struct {
var iterate = dir.iterate(); var iterate = dir.iterate();
defer dir.close(); defer dir.close();
while (try iterate.next()) |ent| { while (try iterate.next()) |ent| {
var ps_dir = try std.fmt.allocPrint(provided_allocator, "/sys/class/power_supply/{}", .{ent.name}); var ps_dir = try std.fmt.allocPrint(provided_allocator, "/sys/class/power_supply/{s}", .{ent.name});
var supply_dir = try fs.cwd().openDir(ps_dir, .{ .iterate = true }); var supply_dir = try fs.cwd().openDir(ps_dir, .{ .iterate = true });
var supply_iterate = supply_dir.iterate(); var supply_iterate = supply_dir.iterate();
defer supply_dir.close(); defer supply_dir.close();
while (try supply_iterate.next()) |entry| { while (try supply_iterate.next()) |entry| {
if (std.mem.eql(u8, entry.name, "status")) { if (std.mem.eql(u8, entry.name, "status")) {
pp.status_path = try std.fmt.allocPrint(provided_allocator, "{}/{}", .{ ps_dir, entry.name }); pp.status_path = try std.fmt.allocPrint(provided_allocator, "{s}/{s}", .{ ps_dir, entry.name });
continue; continue;
} }
if (std.mem.eql(u8, entry.name, "power_now")) { if (std.mem.eql(u8, entry.name, "power_now")) {
pp.power_now_path = try std.fmt.allocPrint(provided_allocator, "{}/{}", .{ ps_dir, entry.name }); pp.power_now_path = try std.fmt.allocPrint(provided_allocator, "{s}/{s}", .{ ps_dir, entry.name });
continue; continue;
} }
if (std.mem.eql(u8, entry.name, "capacity")) { if (std.mem.eql(u8, entry.name, "capacity")) {
pp.capacity_path = try std.fmt.allocPrint(provided_allocator, "{}/{}", .{ ps_dir, entry.name }); pp.capacity_path = try std.fmt.allocPrint(provided_allocator, "{s}/{s}", .{ ps_dir, entry.name });
continue; continue;
} }
if (std.mem.eql(u8, entry.name, "current_now")) { if (std.mem.eql(u8, entry.name, "current_now")) {
pp.current_now_path = try std.fmt.allocPrint(provided_allocator, "{}/{}", .{ ps_dir, entry.name }); pp.current_now_path = try std.fmt.allocPrint(provided_allocator, "{s}/{s}", .{ ps_dir, entry.name });
continue; continue;
} }
if (std.mem.eql(u8, entry.name, "voltage_now")) { if (std.mem.eql(u8, entry.name, "voltage_now")) {
pp.voltage_now_path = try std.fmt.allocPrint(provided_allocator, "{}/{}", .{ ps_dir, entry.name }); pp.voltage_now_path = try std.fmt.allocPrint(provided_allocator, "{s}/{s}", .{ ps_dir, entry.name });
continue; continue;
} }
} }
@ -147,7 +147,7 @@ pub const BatteryWidget = struct {
var watts_info: []const u8 = ""; var watts_info: []const u8 = "";
if (can_get_watts) { if (can_get_watts) {
const watts_str = try std.fmt.allocPrint(self.allocator, " {}{d:.2}W", .{ sign, watts }); const watts_str = try std.fmt.allocPrint(self.allocator, " {s}{d:.2}W", .{ sign, watts });
watts_info = try colour(self.allocator, "purple", watts_str); watts_info = try colour(self.allocator, "purple", watts_str);
self.allocator.free(watts_str); self.allocator.free(watts_str);
} }
@ -162,7 +162,7 @@ pub const BatteryWidget = struct {
self.allocator.free(capInfo); self.allocator.free(capInfo);
defer self.allocator.free(colourCapInfo); defer self.allocator.free(colourCapInfo);
var bat_info = try std.fmt.allocPrint(self.allocator, "{} {} {}{}{}", .{ var bat_info = try std.fmt.allocPrint(self.allocator, "{s} {s} {s}{s}{s}", .{
comptimeColour("accentlight", "bat"), comptimeColour("accentlight", "bat"),
descriptor, descriptor,
colourCapInfo, colourCapInfo,
@ -180,8 +180,7 @@ pub const BatteryWidget = struct {
} }
} }
}; };
pub fn New(allocator: *std.mem.Allocator, bar: *Bar) callconv(.Inline) BatteryWidget {
pub inline fn New(allocator: *std.mem.Allocator, bar: *Bar) BatteryWidget {
return BatteryWidget{ return BatteryWidget{
.allocator = allocator, .allocator = allocator,
.bar = bar, .bar = bar,

View file

@ -32,7 +32,7 @@ fn fetchCPU() ![2]f64 {
var data: [2]f64 = [2]f64{ 0.0, 0.0 }; var data: [2]f64 = [2]f64{ 0.0, 0.0 };
var line_buffer: [128]u8 = undefined; var line_buffer: [128]u8 = undefined;
const line_opt = try stat_file.inStream().readUntilDelimiterOrEof(&line_buffer, '\n'); const line_opt = try stat_file.reader().readUntilDelimiterOrEof(&line_buffer, '\n');
if (line_opt) |line| { if (line_opt) |line| {
var it = std.mem.tokenize(line, " "); var it = std.mem.tokenize(line, " ");
const stat_type = it.next().?; const stat_type = it.next().?;
@ -98,7 +98,7 @@ pub const CPUWidget = struct {
var allocator = &fba.allocator; var allocator = &fba.allocator;
try self.bar.add(Info{ try self.bar.add(Info{
.name = "cpu", .name = "cpu",
.full_text = try std.fmt.allocPrint(allocator, "{} {}", .{ .full_text = try std.fmt.allocPrint(allocator, "{s} {s}", .{
comptimeColour("accentlight", "cpu"), comptimeColour("accentlight", "cpu"),
formatCPUPercent(allocator, percentage), formatCPUPercent(allocator, percentage),
}), }),
@ -120,8 +120,7 @@ pub const CPUWidget = struct {
} }
} }
}; };
pub fn New(bar: *Bar) callconv(.Inline) CPUWidget {
pub inline fn New(bar: *Bar) CPUWidget {
return CPUWidget{ return CPUWidget{
.bar = bar, .bar = bar,
}; };

View file

@ -66,7 +66,7 @@ fn fetchTotalMemory() !MemInfo {
while (true) { while (true) {
var line_buffer: [128]u8 = undefined; var line_buffer: [128]u8 = undefined;
const line_opt = try meminfo_file.inStream().readUntilDelimiterOrEof(&line_buffer, '\n'); const line_opt = try meminfo_file.reader().readUntilDelimiterOrEof(&line_buffer, '\n');
if (line_opt) |line| { if (line_opt) |line| {
var it = std.mem.tokenize(line, " "); var it = std.mem.tokenize(line, " ");
const line_header = it.next().?; const line_header = it.next().?;
@ -152,47 +152,47 @@ pub const MemoryWidget = struct {
// And this is why I love the looping counter. // And this is why I love the looping counter.
if (self.lc.get() == 0) { if (self.lc.get() == 0) {
text = try std.fmt.allocPrint(allocator, "{} {}", .{ text = try std.fmt.allocPrint(allocator, "{s} {s}", .{
comptimeColour("accentlight", "mem"), comptimeColour("accentlight", "mem"),
formatMemoryPercent(allocator, memInfo.memPercent), formatMemoryPercent(allocator, memInfo.memPercent),
}); });
} else if (self.lc.get() == 1) { } else if (self.lc.get() == 1) {
text = try std.fmt.allocPrint(allocator, "{} {}", .{ text = try std.fmt.allocPrint(allocator, "{s} {s}", .{
comptimeColour("accentlight", "swap"), comptimeColour("accentlight", "swap"),
formatMemoryPercent(allocator, memInfo.swapPercent), formatMemoryPercent(allocator, memInfo.swapPercent),
}); });
} else if (self.lc.get() == 2) { } else if (self.lc.get() == 2) {
text = try std.fmt.allocPrint(allocator, "{} {d:0>2} MB", .{ text = try std.fmt.allocPrint(allocator, "{s} {d:0>2} MB", .{
comptimeColour("accentlight", "mem free"), comptimeColour("accentlight", "mem free"),
kibibytesToMegabytes(memInfo.memFree), kibibytesToMegabytes(memInfo.memFree),
}); });
} else if (self.lc.get() == 3) { } else if (self.lc.get() == 3) {
text = try std.fmt.allocPrint(allocator, "{} {d:0>2} MB", .{ text = try std.fmt.allocPrint(allocator, "{s} {d:0>2} MB", .{
comptimeColour("accentlight", "swap free"), comptimeColour("accentlight", "swap free"),
kibibytesToMegabytes(memInfo.swapFree), kibibytesToMegabytes(memInfo.swapFree),
}); });
} else if (self.lc.get() == 4) { } else if (self.lc.get() == 4) {
text = try std.fmt.allocPrint(allocator, "{} {d:0>2} MB", .{ text = try std.fmt.allocPrint(allocator, "{s} {d:0>2} MB", .{
comptimeColour("accentlight", "mem used"), comptimeColour("accentlight", "mem used"),
kibibytesToMegabytes(memInfo.memUsed), kibibytesToMegabytes(memInfo.memUsed),
}); });
} else if (self.lc.get() == 5) { } else if (self.lc.get() == 5) {
text = try std.fmt.allocPrint(allocator, "{} {d:0>2} MB", .{ text = try std.fmt.allocPrint(allocator, "{s} {d:0>2} MB", .{
comptimeColour("accentlight", "swap used"), comptimeColour("accentlight", "swap used"),
kibibytesToMegabytes(memInfo.swapUsed), kibibytesToMegabytes(memInfo.swapUsed),
}); });
} else if (self.lc.get() == 6) { } else if (self.lc.get() == 6) {
text = try std.fmt.allocPrint(allocator, "{} {d:0>2} MB", .{ text = try std.fmt.allocPrint(allocator, "{s} {d:0>2} MB", .{
comptimeColour("accentlight", "mem cache"), comptimeColour("accentlight", "mem cache"),
kibibytesToMegabytes(memInfo.cached), kibibytesToMegabytes(memInfo.cached),
}); });
} else if (self.lc.get() == 7) { } else if (self.lc.get() == 7) {
text = try std.fmt.allocPrint(allocator, "{} {d:0>2} MB", .{ text = try std.fmt.allocPrint(allocator, "{s} {d:0>2} MB", .{
comptimeColour("accentlight", "swap cache"), comptimeColour("accentlight", "swap cache"),
kibibytesToMegabytes(memInfo.swapCached), kibibytesToMegabytes(memInfo.swapCached),
}); });
} else if (self.lc.get() == 8) { } else if (self.lc.get() == 8) {
text = try std.fmt.allocPrint(allocator, "{} {d:0>2} MB", .{ text = try std.fmt.allocPrint(allocator, "{s} {d:0>2} MB", .{
comptimeColour("accentlight", "mem buf"), comptimeColour("accentlight", "mem buf"),
kibibytesToMegabytes(memInfo.buffers), kibibytesToMegabytes(memInfo.buffers),
}); });
@ -207,7 +207,7 @@ pub const MemoryWidget = struct {
}); });
if (kibibytesToMegabytes(memInfo.cached) > 1000) { if (kibibytesToMegabytes(memInfo.cached) > 1000) {
self.clear_cache() catch |err| { self.clear_cache() catch |err| {
std.log.err("Can't clear cache {}.\n", .{err}); std.log.err("Can't clear cache {any}.\n", .{err});
}; };
} }
} }
@ -228,8 +228,7 @@ pub const MemoryWidget = struct {
} }
} }
}; };
pub fn New(bar: *Bar) callconv(.Inline) MemoryWidget {
pub inline fn New(bar: *Bar) MemoryWidget {
return MemoryWidget{ return MemoryWidget{
.bar = bar, .bar = bar,
.lc = LoopingCounter(8).init(), .lc = LoopingCounter(8).init(),

View file

@ -49,12 +49,10 @@ pub const NetworkInfo = struct {
network_status: NetworkStatus = .Connected, network_status: NetworkStatus = .Connected,
network_info: []const u8, network_info: []const u8,
}; };
fn freeString(allocator: *std.mem.Allocator, string: []const u8) callconv(.Inline) void {
inline fn freeString(allocator: *std.mem.Allocator, string: []const u8) void {
allocator.free(string); allocator.free(string);
} }
fn dupeString(allocator: *std.mem.Allocator, string: []const u8) callconv(.Inline) ![]const u8 {
inline fn dupeString(allocator: *std.mem.Allocator, string: []const u8) ![]const u8 {
return try allocator.dupe(u8, string); return try allocator.dupe(u8, string);
} }
@ -64,7 +62,7 @@ pub const NetworkWidget = struct {
network_infos: std.ArrayList(NetworkInfo), network_infos: std.ArrayList(NetworkInfo),
num_interfaces: u8 = 0, num_interfaces: u8 = 0,
current_interface: u8 = 0, current_interface: u8 = 0,
update_mutex: std.Mutex = std.Mutex{}, update_mutex: std.Thread.Mutex = std.Mutex{},
pub fn name(self: *NetworkWidget) []const u8 { pub fn name(self: *NetworkWidget) []const u8 {
return "network"; return "network";
@ -167,8 +165,7 @@ pub const NetworkWidget = struct {
} }
} }
}; };
pub fn New(allocator: *std.mem.Allocator, bar: *Bar) callconv(.Inline) NetworkWidget {
pub inline fn New(allocator: *std.mem.Allocator, bar: *Bar) NetworkWidget {
return NetworkWidget{ return NetworkWidget{
.allocator = allocator, .allocator = allocator,
.bar = bar, .bar = bar,

View file

@ -20,8 +20,7 @@ pub const TextWidget = struct {
pub fn start(self: *TextWidget) anyerror!void {} pub fn start(self: *TextWidget) anyerror!void {}
}; };
pub fn New(name: []const u8, text: []const u8) callconv(.Inline) TextWidget {
pub inline fn New(name: []const u8, text: []const u8) TextWidget {
return TextWidget{ return TextWidget{
.name = name, .name = name,
.text = text, .text = text,

View file

@ -45,7 +45,7 @@ pub const TimeWidget = struct {
end = "am"; end = "am";
} }
var timeStr = try std.fmt.allocPrint(allocator, "{}{}{}{}{}{}", .{ var timeStr = try std.fmt.allocPrint(allocator, "{s}{s}{s}{s}{s}{s}", .{
colour(allocator, "red", try std.fmt.allocPrint(allocator, "{d:0>2}", .{@intCast(u7, hour)})), colour(allocator, "red", try std.fmt.allocPrint(allocator, "{d:0>2}", .{@intCast(u7, hour)})),
comptimeColour("accentlight", ":"), comptimeColour("accentlight", ":"),
colour(allocator, "orange", try std.fmt.allocPrint(allocator, "{d:0>2}", .{@intCast(u7, clock.min)})), colour(allocator, "orange", try std.fmt.allocPrint(allocator, "{d:0>2}", .{@intCast(u7, clock.min)})),
@ -69,15 +69,15 @@ pub const TimeWidget = struct {
} }
} }
var h = try std.fmt.allocPrint(allocator, "{} {} {}{} {} {} {} {} {} {}", .{ var h = try std.fmt.allocPrint(allocator, "{s} {s} {s}{s} {s} {s} {s} {s} {s} {s}", .{
colour(allocator, "green", now.weekday().string()), colour(allocator, "green", now.weekday().string()),
comptimeColour("purple", "the"), comptimeColour("purple", "the"),
colour(allocator, "yellow", try std.fmt.allocPrint(allocator, "{}", .{date.day})), colour(allocator, "yellow", try std.fmt.allocPrint(allocator, "{d}", .{date.day})),
colour(allocator, "accentmedium", suffix), colour(allocator, "accentmedium", suffix),
comptimeColour("purple", "of"), comptimeColour("purple", "of"),
colour(allocator, "red", date.month.string()), colour(allocator, "red", date.month.string()),
comptimeColour("purple", "in"), comptimeColour("purple", "in"),
colour(allocator, "accentlight", try std.fmt.allocPrint(allocator, "{}", .{date.year})), colour(allocator, "accentlight", try std.fmt.allocPrint(allocator, "{d}", .{date.year})),
comptimeColour("purple", "at"), comptimeColour("purple", "at"),
timeStr, timeStr,
}); });
@ -92,8 +92,7 @@ pub const TimeWidget = struct {
} }
} }
}; };
pub fn New(allocator: *std.mem.Allocator, bar: *Bar) callconv(.Inline) TimeWidget {
pub inline fn New(allocator: *std.mem.Allocator, bar: *Bar) TimeWidget {
return TimeWidget{ return TimeWidget{
.allocator = allocator, .allocator = allocator,
.bar = bar, .bar = bar,

View file

@ -155,7 +155,7 @@ pub const WeatherWidget = struct {
return; return;
}, },
else => |e| { else => |e| {
std.debug.print("\n\n\n\n\nError!: {}\n\n\n\n\n", .{@errorName(e)}); std.debug.print("\n\n\n\n\nError!: {s}\n\n\n\n\n", .{@errorName(e)});
return; return;
}, },
} }
@ -163,7 +163,7 @@ pub const WeatherWidget = struct {
if (inf.code != 200) { if (inf.code != 200) {
try self.bar.add(Info{ try self.bar.add(Info{
.name = self.name, .name = self.name,
.full_text = try std.fmt.allocPrint(arenacator, "Weather API Failed: {}", .{inf.message}), .full_text = try std.fmt.allocPrint(arenacator, "Weather API Failed: {s}", .{inf.message}),
.markup = "pango", .markup = "pango",
}); });
return; return;
@ -189,9 +189,9 @@ pub const WeatherWidget = struct {
var i = Info{ var i = Info{
.name = self.name, .name = self.name,
.full_text = try std.fmt.allocPrint(arenacator, "{} {}{}{} {}", .{ .full_text = try std.fmt.allocPrint(arenacator, "{s} {s}{s}{s} {s}", .{
comptimeColour("accentlight", "weather"), comptimeColour("accentlight", "weather"),
colour(arenacator, tempColour, try std.fmt.allocPrint(arenacator, "{}", .{temp})), colour(arenacator, tempColour, try std.fmt.allocPrint(arenacator, "{d}", .{temp})),
comptimeColour("accentlight", "°"), comptimeColour("accentlight", "°"),
comptimeColour("accentdark", "C"), comptimeColour("accentdark", "C"),
colour(arenacator, "green", main), colour(arenacator, "green", main),
@ -208,8 +208,7 @@ pub const WeatherWidget = struct {
} }
} }
}; };
pub fn New(allocator: *std.mem.Allocator, bar: *Bar, comptime location: []const u8) callconv(.Inline) WeatherWidget {
pub inline fn New(allocator: *std.mem.Allocator, bar: *Bar, comptime location: []const u8) WeatherWidget {
return WeatherWidget{ return WeatherWidget{
.allocator = allocator, .allocator = allocator,
.bar = bar, .bar = bar,