~novakane/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH rivercarro v2] Implement main-location-cycle

Details
Message ID
<20240312113328.3621-1-me@iskren.info>
DKIM signature
pass
Download raw message
Patch: +23 -0
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] build failed

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CZRQMTFZHGYJ.C2QOTVTQ2JP1@fra01>
In-Reply-To
<20240312113328.3621-1-me@iskren.info> (view parent)
DKIM signature
missing
Download raw message
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]: me@iskren.info

✗ #1166888 FAILED rivercarro/patches/.build.yml https://builds.sr.ht/~novakane/job/1166888
Details
Message ID
<0905399466902f3362f838ae1be724cab4bfbccc@hmachet.com>
In-Reply-To
<20240312113328.3621-1-me@iskren.info> (view parent)
DKIM signature
pass
Download raw message
Patch: +3 -0
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
>
Reply to thread Export thread (mbox)