repos / zmx

session persistence for terminal processes
git clone https://github.com/neurosnap/zmx.git

commit
64feea6
parent
c539ebc
author
Eric Bower
date
2025-10-10 21:57:44 -0400 EDT
fix: allow zig optimization

fix: help text
4 files changed,  +47, -9
M AGENTS.md
+17, -0
 1@@ -18,6 +18,23 @@ The goal of this project is to create a way to attach and detach terminal sessio
 2 - **Test filter (Zig)**: `zig build test -Dtest-filter=<test name>`
 3 - **Formatting (Zig)**: `zig fmt .`
 4 
 5+## finding library source code
 6+
 7+Before trying anything else, run the `zigdoc` command to find an API with documentation:
 8+
 9+```
10+zigdoc {symbol}
11+# examples
12+zigdoc ghostty-vt
13+zigdoc clap
14+zigdoc libxev
15+zigdoc std.ArrayList
16+zigdoc std.mem.Allocator
17+zigdoc std.http.Server
18+```
19+
20+Only if that doesn't work should you grep the project dir.
21+
22 ## finding libxev source code
23 
24 To inspect the source code for libxev, look inside the `libxev_src` folder.
M build.zig
+4, -1
 1@@ -15,7 +15,10 @@ pub fn build(b: *std.Build) void {
 2 
 3     // You'll want to use a lazy dependency here so that ghostty is only
 4     // downloaded if you actually need it.
 5-    if (b.lazyDependency("ghostty", .{})) |dep| {
 6+    if (b.lazyDependency("ghostty", .{
 7+        .target = target,
 8+        .optimize = optimize,
 9+    })) |dep| {
10         exe_mod.addImport(
11             "ghostty-vt",
12             dep.module("ghostty-vt"),
M src/cli.zig
+21, -3
 1@@ -1,5 +1,6 @@
 2 const std = @import("std");
 3 const clap = @import("clap");
 4+const posix = std.posix;
 5 
 6 const SubCommands = enum {
 7     help,
 8@@ -27,10 +28,27 @@ const main_params = clap.parseParamsComptime(
 9 const MainArgs = clap.ResultEx(clap.Help, &main_params, main_parsers);
10 
11 pub fn help() !void {
12+    const help_text =
13+        \\Usage: zmx <command>
14+        \\
15+        \\Commands:
16+        \\  help       Show this help message
17+        \\  daemon     Start the zmx daemon
18+        \\  attach     Attach to a session
19+        \\  detach     Detach from a session
20+        \\  kill       Kill a session
21+        \\  list       List all sessions
22+        \\
23+        \\Options:
24+        \\
25+    ;
26+    _ = try posix.write(posix.STDOUT_FILENO, help_text);
27+
28     var buf: [1024]u8 = undefined;
29-    var stderr_writer = std.fs.File.stderr().writer(&buf);
30-    const writer: *std.Io.Writer = &stderr_writer.interface;
31-    try clap.help(writer, clap.Help, &main_params, .{});
32+    var stdout_file = std.fs.File{ .handle = posix.STDOUT_FILENO };
33+    var writer = stdout_file.writer(&buf);
34+    try clap.help(&writer.interface, clap.Help, &main_params, .{});
35+    try writer.interface.flush();
36 }
37 
38 pub fn parse(gpa: std.mem.Allocator, iter: *std.process.ArgIterator) !MainArgs {
M src/main.zig
+5, -5
 1@@ -18,7 +18,11 @@ pub fn main() !void {
 2     var res = try cli.parse(allocator, &iter);
 3     defer res.deinit();
 4 
 5-    const command = res.positionals[0] orelse return cli.help();
 6+    const command = res.positionals[0] orelse {
 7+        try cli.help();
 8+        return;
 9+    };
10+
11     switch (command) {
12         .help => try cli.help(),
13         .daemon => try daemon.main(),
14@@ -28,7 +32,3 @@ pub fn main() !void {
15         .kill => try kill.main(),
16     }
17 }
18-
19-test "simple test" {
20-    try std.testing.expectEqual(42, 42);
21-}