fhskjdfg
This commit is contained in:
parent
9cd3a3ceeb
commit
34afae5d84
|
@ -49,7 +49,7 @@ pub const Bar = struct {
|
||||||
fn process(self: *Bar) !void {
|
fn process(self: *Bar) !void {
|
||||||
while (self.running) {
|
while (self.running) {
|
||||||
std.time.sleep(5000 * std.time.ns_per_ms);
|
std.time.sleep(5000 * std.time.ns_per_ms);
|
||||||
//return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn keep_running(self: *Bar) bool {
|
pub fn keep_running(self: *Bar) bool {
|
||||||
|
|
10
src/main.zig
10
src/main.zig
|
@ -11,7 +11,7 @@ const DebugAllocator = @import("debug_allocator.zig");
|
||||||
const Info = @import("types/info.zig").Info;
|
const Info = @import("types/info.zig").Info;
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
const debug: bool = false;
|
const debug: bool = true;
|
||||||
var allocator: *std.mem.Allocator = undefined;
|
var allocator: *std.mem.Allocator = undefined;
|
||||||
var dbgAlloc: *DebugAllocator = undefined;
|
var dbgAlloc: *DebugAllocator = undefined;
|
||||||
if (debug) {
|
if (debug) {
|
||||||
|
@ -25,11 +25,11 @@ pub fn main() !void {
|
||||||
var br = Bar.init(&bar);
|
var br = Bar.init(&bar);
|
||||||
|
|
||||||
const widgets = [_]*Widget{
|
const widgets = [_]*Widget{
|
||||||
&Widget.init(&textWidget.New("owo", "potato")), // 4KiB
|
//&Widget.init(&textWidget.New("owo", "potato")), // 4KiB
|
||||||
&Widget.init(&textWidget.New("uwu", "tomato")), // 4KiB
|
//&Widget.init(&textWidget.New("uwu", "tomato")), // 4KiB
|
||||||
&Widget.init(&weatherWidget.New(allocator, &br, "London")), // 16KiB
|
//&Widget.init(&weatherWidget.New(allocator, &br, "London")), // 16KiB
|
||||||
&Widget.init(&batteryWidget.New(allocator, &br)), // 756.15KiB
|
&Widget.init(&batteryWidget.New(allocator, &br)), // 756.15KiB
|
||||||
&Widget.init(&timeWidget.New(allocator, &br)), // 32.46KiB
|
//&Widget.init(&timeWidget.New(allocator, &br)), // 32.46KiBx
|
||||||
};
|
};
|
||||||
bar.widgets = widgets[0..];
|
bar.widgets = widgets[0..];
|
||||||
try br.start();
|
try br.start();
|
||||||
|
|
|
@ -6,9 +6,13 @@ const cwd = fs.cwd;
|
||||||
const colour = @import("../../formatting/colour.zig").colour;
|
const colour = @import("../../formatting/colour.zig").colour;
|
||||||
|
|
||||||
pub fn compare_from_walker(allocator: *std.mem.Allocator, path: []const u8, start_path: []const u8, required_filename: []const u8) !bool {
|
pub fn compare_from_walker(allocator: *std.mem.Allocator, path: []const u8, start_path: []const u8, required_filename: []const u8) !bool {
|
||||||
var full_path = try std.fmt.allocPrint(allocator, "{}/{}", .{ start_path, required_filename });
|
if (path.len == start_path.len + 1 + required_filename.len) {
|
||||||
defer allocator.free(full_path);
|
var full_path = try std.fmt.allocPrint(allocator, "{}/{}", .{ start_path, required_filename });
|
||||||
return std.mem.eql(u8, path, full_path);
|
defer allocator.free(full_path);
|
||||||
|
return std.mem.eql(u8, path, full_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const PowerPaths = struct {
|
pub const PowerPaths = struct {
|
||||||
|
@ -58,15 +62,51 @@ pub const BatteryWidget = struct {
|
||||||
var allocator = &arena.allocator;
|
var allocator = &arena.allocator;
|
||||||
var power_supply_walker = try fs.walkPath(allocator, "/sys/class/power_supply");
|
var power_supply_walker = try fs.walkPath(allocator, "/sys/class/power_supply");
|
||||||
defer power_supply_walker.deinit();
|
defer power_supply_walker.deinit();
|
||||||
var power_supply_dirs = std.ArrayList([]const u8).init(self.allocator);
|
|
||||||
defer power_supply_dirs.deinit();
|
|
||||||
|
|
||||||
var pp = PowerPaths{};
|
var pp = PowerPaths{};
|
||||||
|
|
||||||
while (try power_supply_walker.next()) |entry| {
|
while (try power_supply_walker.next()) |supply_entry| {
|
||||||
switch (entry.kind) {
|
switch (supply_entry.kind) {
|
||||||
.SymLink => {
|
.SymLink => {
|
||||||
try power_supply_dirs.append(entry.path);
|
var filepath = supply_entry.path;
|
||||||
|
var power_supply_file_walker = try fs.walkPath(allocator, filepath);
|
||||||
|
defer power_supply_file_walker.deinit();
|
||||||
|
|
||||||
|
while (try power_supply_file_walker.next()) |entry| {
|
||||||
|
switch (entry.kind) {
|
||||||
|
.File => {
|
||||||
|
if (try compare_from_walker(allocator, entry.path, filepath, "status")) {
|
||||||
|
pp.status_path = try std.fmt.allocPrint(provided_allocator, "{}", .{entry.path});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (try compare_from_walker(allocator, entry.path, filepath, "power_now")) {
|
||||||
|
pp.power_now_path = try std.fmt.allocPrint(provided_allocator, "{}", .{entry.path});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (try compare_from_walker(allocator, entry.path, filepath, "capacity")) {
|
||||||
|
pp.capacity_path = try std.fmt.allocPrint(provided_allocator, "{}", .{entry.path});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (try compare_from_walker(allocator, entry.path, filepath, "current_now")) {
|
||||||
|
pp.current_now_path = try std.fmt.allocPrint(provided_allocator, "{}", .{entry.path});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (try compare_from_walker(allocator, entry.path, filepath, "voltage_now")) {
|
||||||
|
pp.voltage_now_path = try std.fmt.allocPrint(provided_allocator, "{}", .{entry.path});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
.SymLink,
|
||||||
|
.BlockDevice,
|
||||||
|
.CharacterDevice,
|
||||||
|
.Directory,
|
||||||
|
.NamedPipe,
|
||||||
|
.UnixDomainSocket,
|
||||||
|
.Whiteout,
|
||||||
|
.Unknown,
|
||||||
|
=> continue,
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
.File,
|
.File,
|
||||||
.BlockDevice,
|
.BlockDevice,
|
||||||
|
@ -79,45 +119,7 @@ pub const BatteryWidget = struct {
|
||||||
=> continue,
|
=> continue,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (power_supply_dirs.items) |filepath| {
|
|
||||||
var power_supply_file_walker = try fs.walkPath(allocator, filepath);
|
|
||||||
defer power_supply_file_walker.deinit();
|
|
||||||
while (try power_supply_file_walker.next()) |entry| {
|
|
||||||
switch (entry.kind) {
|
|
||||||
.File => {
|
|
||||||
if (try compare_from_walker(allocator, entry.path, filepath, "status")) {
|
|
||||||
pp.status_path = try std.fmt.allocPrint(provided_allocator, "{}", .{entry.path});
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (try compare_from_walker(allocator, entry.path, filepath, "power_now")) {
|
|
||||||
pp.power_now_path = try std.fmt.allocPrint(provided_allocator, "{}", .{entry.path});
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (try compare_from_walker(allocator, entry.path, filepath, "capacity")) {
|
|
||||||
pp.capacity_path = try std.fmt.allocPrint(provided_allocator, "{}", .{entry.path});
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (try compare_from_walker(allocator, entry.path, filepath, "current_now")) {
|
|
||||||
pp.current_now_path = try std.fmt.allocPrint(provided_allocator, "{}", .{entry.path});
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (try compare_from_walker(allocator, entry.path, filepath, "voltage_now")) {
|
|
||||||
pp.voltage_now_path = try std.fmt.allocPrint(provided_allocator, "{}", .{entry.path});
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
.SymLink,
|
|
||||||
.BlockDevice,
|
|
||||||
.CharacterDevice,
|
|
||||||
.Directory,
|
|
||||||
.NamedPipe,
|
|
||||||
.UnixDomainSocket,
|
|
||||||
.Whiteout,
|
|
||||||
.Unknown,
|
|
||||||
=> continue,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return pp;
|
return pp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,6 +128,7 @@ pub const BatteryWidget = struct {
|
||||||
defer pparena.deinit();
|
defer pparena.deinit();
|
||||||
var ppallocator = &pparena.allocator;
|
var ppallocator = &pparena.allocator;
|
||||||
const pp = try self.get_power_paths(ppallocator);
|
const pp = try self.get_power_paths(ppallocator);
|
||||||
|
if (true) return;
|
||||||
while (self.bar.keep_running()) {
|
while (self.bar.keep_running()) {
|
||||||
var arena = std.heap.ArenaAllocator.init(self.allocator);
|
var arena = std.heap.ArenaAllocator.init(self.allocator);
|
||||||
defer arena.deinit();
|
defer arena.deinit();
|
||||||
|
@ -202,7 +205,7 @@ pub const BatteryWidget = struct {
|
||||||
|
|
||||||
pub inline fn New(allocator: *std.mem.Allocator, bar: *Bar) BatteryWidget {
|
pub inline fn New(allocator: *std.mem.Allocator, bar: *Bar) BatteryWidget {
|
||||||
return BatteryWidget{
|
return BatteryWidget{
|
||||||
.allocator = allocator,
|
.allocator = &std.heap.loggingAllocator(allocator, std.io.getStdErr().writer()).allocator,
|
||||||
.bar = bar,
|
.bar = bar,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue