stevee

My wayland statusbar
git clone git://gtms.dev/stevee
Log | Files | Refs | Submodules | README | LICENSE

commit f2b74950b7431f6024814ff54cbc0949e29e9a5d
parent 485b6cb9f94ffd7c7a057b3a7fc0bbb9460b2932
Author: Andrea Feletto <andrea@andreafeletto.com>
Date:   Tue, 26 Apr 2022 17:49:18 +0200

add args for help and modules

Diffstat:
M.gitmodules | 3+++
MREADME.md | 5+++--
Mbuild.zig | 5+++++
Adeps/zig-clap | 1+
Msrc/main.zig | 29++++++++++++++++++++++++++---
5 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/.gitmodules b/.gitmodules @@ -10,3 +10,6 @@ [submodule "deps/zig-udev"] path = deps/zig-udev url = https://git.sr.ht/~andreafeletto/zig-udev +[submodule "deps/zig-clap"] + path = deps/zig-clap + url = https://github.com/Hejsil/zig-clap diff --git a/README.md b/README.md @@ -7,8 +7,9 @@ and displays battery capacity and screen brightness. Some important things are not implemented yet: -* configuration via cli flags * configuration via config file +* volume (alsa/pulseaudio/pipewire) module +* cpu module ## Build @@ -23,7 +24,7 @@ zig build -Drelease-safe --prefix ~/.local install Add the following toward the end of `$XDG_CONFIG_HOME/river/init`: ``` -riverctl spawn levee +riverctl spawn levee -m backlight -m battery ``` ## Dependencies diff --git a/build.zig b/build.zig @@ -20,6 +20,10 @@ pub fn build(b: *std.build.Builder) void { exe.step.dependOn(&scanner.step); scanner.addCSource(exe); + const clap = Pkg{ + .name = "clap", + .path = .{ .path = "deps/zig-clap/clap.zig" }, + }; const wayland = Pkg{ .name = "wayland", .path = .{ .generated = &scanner.result }, @@ -38,6 +42,7 @@ pub fn build(b: *std.build.Builder) void { .path = .{ .path = "deps/zig-udev/udev.zig" }, }; + exe.addPackage(clap); exe.addPackage(fcft); exe.addPackage(pixman); exe.addPackage(udev); diff --git a/deps/zig-clap b/deps/zig-clap @@ -0,0 +1 @@ +Subproject commit 511b357b9fd6480f46cf2a52b1d168471d1ec015 diff --git a/src/main.zig b/src/main.zig @@ -1,7 +1,10 @@ const std = @import("std"); const heap = std.heap; +const io = std.io; const mem = std.mem; +const os = std.os; +const clap = @import("clap"); const fcft = @import("fcft"); const Config = @import("Config.zig"); @@ -23,6 +26,17 @@ pub fn main() anyerror!void { fcft.init(.auto, false, .info); + // cli arguments + const params = comptime [_]clap.Param(clap.Help){ + try clap.parseParam("-h, --help Display this help and exit."), + try clap.parseParam("-m, --module <str>... Add module."), + }; + var args = try clap.parse(clap.Help, &params, .{}); + defer args.deinit(); + if (args.flag("--help")) { + return clap.help(io.getStdErr().writer(), &params); + } + // initialization var state: State = undefined; state.gpa = gpa.allocator(); @@ -34,9 +48,18 @@ pub fn main() anyerror!void { state.loop = try Loop.init(&state); // modules - try state.modules.register(Modules.Alsa); - try state.modules.register(Modules.Backlight); - try state.modules.register(Modules.Battery); + for (args.options("--module")) |module_name| { + if (mem.eql(u8, module_name, "alsa")) { + try state.modules.register(Modules.Alsa); + } else if (mem.eql(u8, module_name, "backlight")) { + try state.modules.register(Modules.Backlight); + } else if (mem.eql(u8, module_name, "battery")) { + try state.modules.register(Modules.Battery); + } else { + std.log.err("unknown module: {s}", .{ module_name }); + os.exit(1); + } + } // event loop try state.wayland.registerGlobals();