~novakane/public-inbox

rivercarro: Implement main-location-cycle v2 SUPERSEDED

: 1
 Implement main-location-cycle
Hugo Machet: 1
 Implement main-location-cycle

 2 files changed, 26 insertions(+), 0 deletions(-)
#1166888 .build.yml failed
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/50159/mbox | git am -3
Learn more about email & git

[PATCH rivercarro v2] 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 v2: redo the code to only iterate a single time and avoid using
external array.

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

 src/main.zig | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/src/main.zig b/src/main.zig
index 877d8b2..54d2517 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_str| {
                            const cur_loc = std.meta.stringToEnum(Location, loc_str) orelse {
                                log.err("unknown location: {s}", .{loc_str});
                                return;
                            };
                            if (picked == null or pick_next) {
                                picked = cur_loc;
                                if (pick_next) {
                                    break;
                                }
                            }
                            if (cur_loc == 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 23s

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

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

✗ #1166888 FAILED rivercarro/patches/.build.yml https://builds.sr.ht/~novakane/job/1166888

Re: [PATCH rivercarro v2] Implement main-location-cycle Export this patch

Just a few nitpiks, I'd like a rename of:
  loc_str -> loc
  cur_loc -> current


Other than that that seems fine, I tested a bit and seems to works as
expected

ALso the man page probably should look like this, if you want to add it,
maybe a small example is needed

diff --git a/doc/rivercarro.1 b/doc/rivercarro.1
index aed476d18b89..b728bcccdec6 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


> 
> + .@"main-location-cycle" => {
> 
> + var loc_it = std.mem.splitSequence(u8, raw_arg, ",");
> 

var loc_it = mem.splitSequence(u8, raw_arg, ",");

> 
> + picked = cur_loc;
> 
> + if (pick_next) {
> 
> + break;
> 
> + }

if (next) break;

This is fine on one line

> 
> + }
> 
> + if (cur_loc == 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
>