~leon_plickat/public-inbox

allow cycling through integers in layout commands v1 PROPOSED

Stephen Eglen: 1
 allow cycling through integers in layout commands

 2 files changed, 24 insertions(+), 4 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~leon_plickat/public-inbox/patches/48061/mbox | git am -3
Learn more about email & git

[PATCH] allow cycling through integers in layout commands Export this patch

From: Leon Henrik Plickat <leonhenrik.plickat@stud.uni-goettingen.de>

---
 doc/stacktile.1   |  4 ++++
 src/stacktile.zig | 24 ++++++++++++++++++++----
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/doc/stacktile.1 b/doc/stacktile.1
index 2d851bb..59626d1 100644
--- a/doc/stacktile.1
+++ b/doc/stacktile.1
@@ -241,6 +241,10 @@ Suppoerted values are \fBgravity\fR, \fBmain-limit\fR, \fBmain-ratio\fR,
.P
See the matching variables in the layout configuration section for a description
and for value limitations.
.P
If directly setting integer variables, multiple possible values can be provided,
seprated by colon (for example like this: 20:40:70) and stacktile will cycle
through them.
.RE
.
.P
diff --git a/src/stacktile.zig b/src/stacktile.zig
index 99fbb1f..35f8b04 100644
--- a/src/stacktile.zig
+++ b/src/stacktile.zig
@@ -346,13 +346,31 @@ const LayoutConfig = struct {
    }

    fn intAssign(comptime T: type, _old: ?T, layout_value: T, _value: []const u8, operation: []const u8) !T {
        const value = fmt.parseInt(T, _value, 10) catch return error.BadInt;
        const old = if (_old) |o| o else layout_value;
        if (mem.eql(u8, operation, "=")) {
            return value;
            // Find match and then return next value.
            var it = mem.split(u8, _value, ":");
            while (it.next()) |token| {
                const t = fmt.parseInt(T, token, 10) catch return error.BadInt;
                if (t != old) continue;

                // If there is no next value, wrap around to first one.
                const next_token = it.next() orelse blk: {
                    var iit = mem.split(u8, _value, ":");
                    break :blk iit.next().?;
                };
                return fmt.parseInt(T, next_token, 10) catch return error.BadInt;
            }

            // Fall back to first value in list if no matches are found.
            it = mem.split(u8, _value, ":");
            const token = it.next() orelse _value;
            return fmt.parseInt(T, token, 10) catch return error.BadInt;
        } else if (mem.eql(u8, operation, "+=")) {
            const value = fmt.parseInt(T, _value, 10) catch return error.BadInt;
            return old +| value;
        } else if (mem.eql(u8, operation, "-=")) {
            const value = fmt.parseInt(T, _value, 10) catch return error.BadInt;
            return old -| value;
        } else {
            return error.UnknownOperation;
@@ -529,8 +547,6 @@ const Layout = struct {
};

const OutputConfig = struct {
    const IdentifierType = enum { name, connector };

    /// Holds either a potential Layout name or a pointer to a Layout.
    /// Output configs and layouts can be defined in the config file in an
    /// arbitrary order. So first we store the desired layout name, then after
-- 
2.40.1