git.lucas.co / cce-compositor
Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git

commit7348ab6312b091fa5a87c0bdbfa75654e8394a4f
parent7f822dfe74
authorIsaac Freund <[email protected]>
date2020-06-16 17:06
docs: add rivertile man page

 build.zig           |  1 +
 doc/rivertile.1.scd | 38 ++++++++++++++++++++++++++++++++++++++
 rivertile/main.zig  | 26 ++++++++++++++++++++------
 3 files changed, 59 insertions(+), 6 deletions(-)

diff --git a/build.zig b/build.zig
index 58116dd..58f98c8 100644
--- a/build.zig
+++ b/build.zig
@@ -217,6 +217,7 @@ const ScdocStep = struct {
     const scd_paths = [_][]const u8{
         "doc/river.1.scd",
         "doc/riverctl.1.scd",
+        "doc/rivertile.1.scd",
         "doc/river-layouts.1.scd",
     };
 
diff --git a/doc/rivertile.1.scd b/doc/rivertile.1.scd
new file mode 100644
index 0000000..3a7fd49
--- /dev/null
+++ b/doc/rivertile.1.scd
@@ -0,0 +1,38 @@
+RIVERTILE(1) "github.com/ifreund/river" "General Commands Manual"
+
+# NAME
+
+rivertile - tiled layout generator for river
+
+# SYNOPSIS
+
+*rivertile* *left*|*right*|*top*|*bottom* [args passed by river]
+
+# DESCRIPTION
+
+*rivertile* is a layout generator for river. It produces tiled layouts with
+split master/secondary stacks in four configurable orientations.
+
+# OPTIONS
+
+*left*
+	Place the master stack on the left side of the output.
+
+*right*
+	Place the master stack on the right side of the output.
+
+*top*
+	Place the master stack at the top of the output.
+
+*bottom*
+	Place the master stack at the bottom of the output.
+
+# EXAMPLE
+
+Set river's layout to *rivertile*'s *left* layout using riverctl
+
+	riverctl layout rivertile left
+
+# SEE ALSO
+
+*river-layouts*(7), *river*(1), *riverctl*(1)
diff --git a/rivertile/main.zig b/rivertile/main.zig
index 8171dcc..911754e 100644
--- a/rivertile/main.zig
+++ b/rivertile/main.zig
@@ -45,13 +45,17 @@ const Orientation = enum {
 /// |                       |            |
 /// +-----------------------+------------+
 pub fn main() !void {
+    const args = std.os.argv;
+    if (args.len != 7) printUsageAndExit();
+
     // first arg must be left, right, top, or bottom
-    const master_location = std.meta.stringToEnum(Orientation, std.mem.spanZ(std.os.argv[1])).?;
+    const master_location = std.meta.stringToEnum(Orientation, std.mem.spanZ(args[1])) orelse
+        printUsageAndExit();
 
     // the other 5 are passed by river and described in river-layouts(7)
-    const num_views = try std.fmt.parseInt(u32, std.mem.spanZ(std.os.argv[2]), 10);
-    const master_count = try std.fmt.parseInt(u32, std.mem.spanZ(std.os.argv[3]), 10);
-    const master_factor = try std.fmt.parseFloat(f64, std.mem.spanZ(std.os.argv[4]));
+    const num_views = try std.fmt.parseInt(u32, std.mem.spanZ(args[2]), 10);
+    const master_count = try std.fmt.parseInt(u32, std.mem.spanZ(args[3]), 10);
+    const master_factor = try std.fmt.parseFloat(f64, std.mem.spanZ(args[4]));
 
     const width_arg: u32 = switch (master_location) {
         .left, .right => 5,
@@ -59,8 +63,8 @@ pub fn main() !void {
     };
     const height_arg: u32 = if (width_arg == 5) 6 else 5;
 
-    const output_width = try std.fmt.parseInt(u32, std.mem.spanZ(std.os.argv[width_arg]), 10);
-    const output_height = try std.fmt.parseInt(u32, std.mem.spanZ(std.os.argv[height_arg]), 10);
+    const output_width = try std.fmt.parseInt(u32, std.mem.spanZ(args[width_arg]), 10);
+    const output_height = try std.fmt.parseInt(u32, std.mem.spanZ(args[height_arg]), 10);
 
     const secondary_count = num_views - master_count;
 
@@ -126,3 +130,13 @@ pub fn main() !void {
 
     try stdout_buf.flush();
 }
+
+fn printUsageAndExit() noreturn {
+    const usage: []const u8 =
+        \\Usage: rivertile left|right|top|bottom [args passed by river]
+        \\
+    ;
+
+    std.debug.warn(usage, .{});
+    std.os.exit(1);
+}