summaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/main.zig b/src/main.zig
index d4edc74d..ada5f3b9 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -109,7 +109,8 @@ const help_text =
\\ --attach=<name> ...the session called <name> (its --9p or
\\ --detach name, else its pid)
\\ --attach=<host>:<name> a client of session <name> on another machine,
- \\ over `ssh -L` to its pardes-replica.sock
+ \\ a terminal's or a window's (either kind's
+ \\ session), over `ssh -L` to its pardes-replica.sock
\\ ($PARDES_SSH: the ssh command, words, default
\\ `ssh`; and
\\ $PARDES_REMOTE_RUNTIME: its runtime directory,
@@ -802,7 +803,6 @@ fn nativeMain(std_init: std.process.Init) !void {
opts.store_path = storePath(init.io, arena, init.environ_map);
if (found.dir) |d| @import("crash.zig").setDir(d);
if (attach) |name| if (std.mem.lastIndexOfScalar(u8, name, ':')) |colon| {
- if (comptime pardes.platform != .tty) badArgs(init.io, "a window is no replica client yet: run `pardes --attach={s}` in a terminal", .{name});
remoteAttach(init, opts, name[0..colon], name[colon + 1 ..]);
};
if (attach) |name| if (!resuming) attachTo(init.io, name);
@@ -981,12 +981,23 @@ fn commOf(pid: []const u8, buf: *[64]u8) []const u8 {
return std.mem.trimEnd(u8, buf[0..@intCast(got)], "\n");
}
-/// `pardes --attach=<where>:<name>`: a replica client (tty.zig `remote`),
-/// through the socket `where` names, or through `ssh -L` of host `where`'s
-/// replica socket to one of this process's.
+/// The replica client of this build's frontend: a terminal's (tty.zig) or a
+/// window's (gui.zig).
+fn clientOf(init: std.process.Init, opts: pardes.Options, path: []const u8, name: []const u8, far: bool) !void {
+ switch (pardes.platform) {
+ .tty => try @import("tty/tty.zig").remote(init, opts, path, name, far),
+ .gui => try @import("gui/gui.zig").remote(init, opts, path, name, far),
+ else => unreachable,
+ }
+}
+
+/// `pardes --attach=<where>:<name>` (`pardes-gui` too): a replica client
+/// (tty.zig and gui.zig `remote`), through the socket `where` names, or
+/// through `ssh -L` of host `where`'s replica socket to one of this
+/// process's.
fn remoteAttach(init: std.process.Init, opts: pardes.Options, where: []const u8, name: []const u8) noreturn {
const io = init.io;
- if (comptime pardes.platform != .tty) unreachable;
+ if (comptime pardes.platform != .tty and pardes.platform != .gui) unreachable;
const Say = struct {
fn no(o: std.Io, comptime fmt: []const u8, args: anytype) noreturn {
var buf: [700]u8 = undefined;
@@ -995,7 +1006,7 @@ fn remoteAttach(init: std.process.Init, opts: pardes.Options, where: []const u8,
}
};
if (std.mem.indexOfScalar(u8, where, '/') != null) {
- @import("tty/tty.zig").remote(init, opts, where, name, false) catch |err| Say.no(io, "{t}", .{err});
+ clientOf(init, opts, where, name, false) catch |err| Say.no(io, "{t}", .{err});
std.process.exit(0);
}
// ssh -L <here>:<there> <host>, until the socket here answers.
@@ -1066,7 +1077,7 @@ fn remoteAttach(init: std.process.Init, opts: pardes.Options, where: []const u8,
const ts: std.c.timespec = .{ .sec = 0, .nsec = 10 * std.time.ns_per_ms };
_ = std.c.nanosleep(&ts, null);
}
- @import("tty/tty.zig").remote(init, opts, here, name, true) catch |err| {
+ clientOf(init, opts, here, name, true) catch |err| {
Ssh.end();
Say.no(io, "{t}", .{err});
};