~andreafeletto/levee

f2b74950b7431f6024814ff54cbc0949e29e9a5d — Andrea Feletto 27 days ago 485b6cb
add args for help and modules
5 files changed, 38 insertions(+), 5 deletions(-)

M .gitmodules
M README.md
M build.zig
A deps/zig-clap
M src/main.zig
M .gitmodules => .gitmodules +3 -0
@@ 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

M README.md => README.md +3 -2
@@ 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

M build.zig => build.zig +5 -0
@@ 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);

A deps/zig-clap => deps/zig-clap +1 -0
@@ 0,0 1,1 @@
Subproject commit 511b357b9fd6480f46cf2a52b1d168471d1ec015

M src/main.zig => src/main.zig +26 -3
@@ 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();