~novakane/public-inbox

rivercarro: Implement main-location-cycle v3 APPLIED

: 1
 Implement main-location-cycle

 2 files changed, 26 insertions(+), 0 deletions(-)
#1167664 .build.yml failed



          
          
          
          
Next
March 13, 2024 at 12:22 PM, "Iskren Chernev" <me@iskren.info> wrote:
Next
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/~novakane/public-inbox/patches/50179/mbox | git am -3
Learn more about email & git

[PATCH rivercarro v3] Implement main-location-cycle Export this patch

From: Iskren Chernev <me@iskren.info>

It is useful to cycle between layout with a single command, without
caring what is the current layout. The command accepts a list of
Locations divided by comma (','). If the current location is not in the
list, the first one is chosen. Otherwise the next in the list (wrapping
around) is taken.
---
Changes in v3: Rename variables and add documentation entries.

Changes in v2: redo the code to only iterate a single time and avoid using
external array.

v2: https://lists.sr.ht/~novakane/public-inbox/patches/50159
v1: https://lists.sr.ht/~novakane/public-inbox/patches/50127


 doc/rivercarro.1 |  3 +++
 src/main.zig     | 23 +++++++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/doc/rivercarro.1 b/doc/rivercarro.1
index aed476d..b728bcc 100644
--- a/doc/rivercarro.1
+++ b/doc/rivercarro.1
@@ -135,6 +135,9 @@ is added/subtracted from the current value. If there is no sign,
.BI main\-location\  top|bottom|left|right|monocle
Set the location of the main area in the layout.
.TP
.BI main\-location\-cycle\  list
Comma separated list of locations to cycle through.
.TP
.BI main\-count\  value
Set or modify the number of views in the main area of the layout. If
.I value
diff --git a/src/main.zig b/src/main.zig
index 877d8b2..c585024 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -64,6 +64,7 @@ const Command = enum {
    @"outer-gaps",
    gaps,
    @"main-location",
    @"main-location-cycle",
    @"main-count",
    @"main-ratio",
    @"width-ratio",
@@ -188,6 +189,28 @@ const Output = struct {
                            return;
                        };
                    },
                    .@"main-location-cycle" => {
                        var loc_it = std.mem.splitSequence(u8, raw_arg, ",");
                        // select the first one, then the one after the current
                        var picked: ?Location = null;
                        var pick_next: bool = false;
                        while (loc_it.next()) |loc| {
                            const current = std.meta.stringToEnum(Location, loc) orelse {
                                log.err("unknown location: {s}", .{loc});
                                return;
                            };
                            if (picked == null or pick_next) {
                                picked = current;
                                if (pick_next) {
                                    break;
                                }
                            }
                            if (current == output.cfg.main_location) {
                                pick_next = true;
                            }
                        }
                        output.cfg.main_location = picked.?;
                    },
                    .@"main-count" => {
                        const arg = fmt.parseInt(i32, raw_arg, 10) catch |err| {
                            log.err("failed to parse argument: {}", .{err});
-- 
2.44.0
rivercarro/patches/.build.yml: FAILED in 52s

[Implement main-location-cycle][0] v3 from [][1]

[0]: https://lists.sr.ht/~novakane/public-inbox/patches/50179
[1]: mailto:me@iskren.info

✗ #1167664 FAILED rivercarro/patches/.build.yml https://builds.sr.ht/~novakane/job/1167664
Thanks, pushed to main, I force pushed a few formatting change that you
missed in my previous review, but I kinda messed up the email so I don't
blame you xD

Not gonna lie, this is a pretty cool feature I didn't know I need, as
someone who only use left and monocle too, this is nice to only use one
key