Alright, we stay on your first idea for now, a command
`main-location-cycle` that takes a comma separated list of max 5
locations, if there stll a need for this limitation.
For the implementations I let you decide what you want, note that you
don't need to make something too complex, shorter and more concise code
is nice if it doesn't add too much complexity. Static array or
something like std.ArrayListUnmanaged() are not bad :)
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.
---
src/main.zig | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/src/main.zig b/src/main.zig
index 877d8b2..26b2440 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,34 @@ const Output = struct {
return;
};
},
+ .@"main-location-cycle" => {+ var loc_cnt: u8 = 0;+ // support a maximum of 10 locations+ var locs: [10]Location = undefined;+ var loc_it = std.mem.splitSequence(u8, raw_arg, ",");+ while (loc_it.next()) |loc_str| : (loc_cnt += 1) {+ if (loc_cnt >= 10) {+ log.err("too many locations in cycle, max 10", .{});+ return;+ }+ locs[loc_cnt] = std.meta.stringToEnum(Location, loc_str) orelse {+ log.err("unknown location: {s}", .{loc_str});+ return;+ };+ }+ var fi: i8 = -1;+ for (0.., locs[0..loc_cnt]) |i, loc| {+ if (output.cfg.main_location == loc) {+ fi = @intCast(i);+ break;+ }+ }+ fi = fi + 1;+ if (fi == loc_cnt) {+ fi = 0;+ }+ output.cfg.main_location = locs[@intCast(fi)];+ }, .@"main-count" => {
const arg = fmt.parseInt(i32, raw_arg, 10) catch |err| {
log.err("failed to parse argument: {}", .{err});
--
2.44.0
I'm not against adding this feature but I don't get the point of adding
a list of 10 locations. I would prefer to just allow cycling through the
5 locations, since you can't add custom locations, unless you have a
good reason for adding it like this?