diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-29 09:01:46 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-01 00:12:16 -0300 |
| commit | 039ae6aa70d963f942d8a5747060c67599664af9 (patch) | |
| tree | 3f6448c9a7b3db81a076edeefce081990a9eea24 /src | |
| parent | e0a2fd56777cf0f571125650ec74e75c3f6a8c44 (diff) | |
| download | pardes-039ae6aa70d963f942d8a5747060c67599664af9.tar.gz pardes-039ae6aa70d963f942d8a5747060c67599664af9.zip | |
A terminal is typed into only when idle at an empty prompt
A look at a directory, or an exec at a terminal, typed its line after
whatever sat unsent at the prompt and ran the two joined (`echo TYPEDls`).
A terminal with text at its prompt now takes no line; a look at its
directory opens a new terminal, an exec runs as a command pane.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src')
| -rw-r--r-- | src/exec.zig | 8 | ||||
| -rw-r--r-- | src/ninep/ctl.zig | 26 |
2 files changed, 33 insertions, 1 deletions
diff --git a/src/exec.zig b/src/exec.zig index 6e437093..ebe90b98 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -37,6 +37,12 @@ pub fn takesCommandLine(p: *const Pardes, id: usize) bool { const pane = p.panes[id] orelse return false; // A command pane's child is its command, never a shell to type at. if (!pane.isTerminal() or pane.command != null) return false; + // Someone's line at the shell's prompt, typed and not sent: typing a + // command there would run it joined to theirs (`echo TYPEDls`). Only an + // idle, EMPTY prompt is typed at; otherwise a new pane runs the line. + // (Text in pardes's own edit buffer is not the shell's yet: an exec of + // it, or of anything, types only what it runs.) + if (panes.Terminal.promptInputReady(pane) and !panes.Terminal.promptInputEmpty(pane)) return false; // A mounted shell sits behind sudo's process supervisor. Its OSC 133 // prompt marks identify input readiness; the launcher's executable is // not the shell executable used by the ordinary process heuristic. @@ -371,7 +377,7 @@ fn spawnTtyWithMount(p: *Pardes, from: usize, v9fs: bool) ?*Pane { /// Whether `path` is a directory on this host, the turn out while it asks /// (it may be inside a mount this editor serves). -fn isDirectory(path: []const u8) bool { +pub fn isDirectory(path: []const u8) bool { var buf: [4096]u8 = undefined; const z = std.fmt.bufPrintSentinel(&buf, "{s}", .{path}, 0) catch return false; pardes.turn.yield(); diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index d1f920a2..95d81e3b 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -1886,6 +1886,32 @@ test "a terminal told the directory it already goes by logs no rename" { try testing.expect(th.logHas(p, try std.fmt.bufPrint(&rec, "rename {d} /usr", .{p.panes[term].?.serial}))); } +test "a terminal with text typed at its prompt is never typed into: a look at its directory opens another" { + const p = try th.withTerm(testing.allocator); + defer p.deinit(); + const term = p.paneBySerial(serialOf(p)).?; + p.setCwd(term, "/tmp"); + p.update(.{ .output = .{ .pane = @intCast(term), .bytes = "\x1b]133;A;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07TYPED" } }); + while (p.nextEffect()) |_| {} + var count: usize = 0; + for (p.panes) |slot| count += @intFromBool(slot != null); + try testing.expectEqual(Status.ok, wr(p, @intFromEnum(tree.TopFile.look), "/tmp\n").reply.status); + var typed_into = false; + while (p.nextEffect()) |effect| if (effect == .write and effect.write.pane == term) { + typed_into = true; + }; + try testing.expect(!typed_into); + var after: usize = 0; + for (p.panes) |slot| after += @intFromBool(slot != null); + try testing.expectEqual(count + 1, after); + // An exec at it runs in a pane of its own, not typed after TYPED. + _ = wr(p, Node.of(serialOf(p), .exec), "echo hi\n"); + while (p.nextEffect()) |effect| if (effect == .write and effect.write.pane == term) { + typed_into = true; + }; + try testing.expect(!typed_into); +} + test "size is monotonic: growing is never refused, and a size once taken is taken again" { const p = try Pardes.init(testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 60 }); defer p.deinit(); |
