summaryrefslogtreecommitdiff
path: root/src/Term.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 03:56:36 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commit34641e435fcbae0af578189760d5ebb05bc07f9a (patch)
tree52957c9fe379df12199b605e68786077d66a68d6 /src/Term.zig
parent79a1e816ceb13ef81b712007716c8add2de75434 (diff)
downloadpardes-34641e435fcbae0af578189760d5ebb05bc07f9a.tar.gz
pardes-34641e435fcbae0af578189760d5ebb05bc07f9a.zip
Term: a core without a terminal boots to a scratch pane, and a test skips only where it needs a terminal (docs/next-terminal.md, Phase 1, the no-terminal core): Pardes.init's shell boots (.shell, .classic, .tty, .tty_shell) are one scratch pane when Term.ops is null, so a test that booted a shell for convenience runs on it, where every one of them skipped before (Term.open refused with SkipZigTest under a test); Term.open refuses with error.NoTerminal, said by errorWords as Term.none, so Term and an exec no shell can take (a command pane) refuse in words (`Term: no terminal in this build`, `exec: ...`), and takesCommandLine is false with no terminal pane; a +Pager pages the bytes as they are (Term.page, unchanged); no boot message: the no-terminal core is a test build alone, read by no person, and a message at boot put seven core tests (the message log, the notice bands, the Del question's wake, a press on a column's rule) out of core-test; a test that fails for want of a terminal says so on its first line (`if (pardes.Term.ops == null) return error.SkipZigTest; // a shell`: a shell, a command pane, the classic boot's three shells, it reads the emulator, ...), 99 tests in 25 files, and ninep/testing.zig's withTerm, the fixture of 29 that assert a terminal pane, once; each attributed by its failure on the scratch boot (NoTerminal from newShell or newCommand, a shell's pane, prompt, pty bytes or tag asserted, the classic boot's panes indexed) and by reading its body; no assertion changes; test: Term.zig ends with the no-terminal core's three (each boot a scratch pane and no terminal; Term, newShell and an exec refused in words, no line typed at a shell; a program's output paged as plain text); core-test (no terminal) 411 passed / 535 skipped of 946 to 810 passed / 139 skipped of 949, shell-test 992: 989 passed, the three no-terminal tests skipped
Diffstat (limited to 'src/Term.zig')
-rw-r--r--src/Term.zig53
1 files changed, 51 insertions, 2 deletions
diff --git a/src/Term.zig b/src/Term.zig
index 8bd6e05b..cf94c6d5 100644
--- a/src/Term.zig
+++ b/src/Term.zig
@@ -105,9 +105,10 @@ pub fn emulatorOf(s: *State) *@import("term").terminal.State {
// ---- lifecycle ----
/// A new terminal, `cols` by `rows`, allocated with `gpa` (its own from
-/// then on). Refused in a core without one (a test of one skips).
+/// then on). Refused in a core without one: `error.NoTerminal`, which a
+/// word reports as `none` says it.
pub fn open(gpa: std.mem.Allocator, cols: u16, rows: u16) !*State {
- const o = ops orelse return if (builtin.is_test) error.SkipZigTest else error.NoTerminal;
+ const o = ops orelse return error.NoTerminal;
const s = try gpa.create(State);
errdefer gpa.destroy(s);
s.* = .{ .impl = try o.open(gpa, cols, rows) };
@@ -446,3 +447,51 @@ pub fn blank(s: *State, r: *const Replica, lo: u64, hi: u64) void {
pub fn dumpScreen(s: *State, w: *std.Io.Writer) !void {
return the().dumpScreen(s.impl, w);
}
+
+// ---- a core without a terminal (core-test's) ----
+
+test "a core without a terminal boots to a scratch pane" {
+ if (ops != null) return error.SkipZigTest;
+ const pardes = @import("pardes.zig");
+ for ([_]pardes.Options{ .{}, .{ .tty_only = true }, .{ .boot = .tty }, .{ .shells = 3 } }) |opts| {
+ const p = try pardes.Pardes.init(std.testing.allocator, opts);
+ defer p.deinit();
+ const pane = p.panes[0].?;
+ try std.testing.expect(pane.terminal == null);
+ try std.testing.expect(pane.file != null);
+ try std.testing.expectEqual(null, p.panes[1]);
+ }
+}
+
+test "a core without a terminal: Term refuses in words, and no line is typed at a shell" {
+ if (ops != null) return error.SkipZigTest;
+ const pardes = @import("pardes.zig");
+ const p = try pardes.Pardes.init(std.testing.allocator, .{ .file = "mise.toml" });
+ defer p.deinit();
+ try std.testing.expectError(error.NoTerminal, p.newShell(p.freeSlot().?, ""));
+ try std.testing.expect(p.executeBuiltinLine(0, "Term"));
+ const pane = p.panes[0].?;
+ try std.testing.expectEqualStrings("Term: " ++ none, pane.msg[0..pane.msg_len]);
+ // A line no shell can take runs in a command pane, a terminal: refused.
+ try std.testing.expectEqual(null, pardes.exec.execute(p, 0, "make"));
+ try std.testing.expectEqualStrings("exec: " ++ none, pane.msg[0..pane.msg_len]);
+ for (p.panes, 0..) |slot, id| if (slot) |_| try std.testing.expect(!pardes.exec.takesCommandLine(p, id));
+}
+
+test "a core without a terminal pages a program's output as plain text" {
+ if (ops != null) return error.SkipZigTest;
+ const pardes = @import("pardes.zig");
+ const raw = "one\n\x1b[31mtwo\x1b[0m\n";
+ const paged = try page(std.testing.allocator, raw);
+ defer paged.deinit(std.testing.allocator);
+ try std.testing.expectEqualStrings(raw, paged.text);
+ try std.testing.expectEqual(0, paged.spans.len);
+ const p = try pardes.Pardes.init(std.testing.allocator, .{ .stdin_text = "one\ntwo\n" });
+ defer p.deinit();
+ for (p.panes) |slot| if (slot) |pane| if (pane.file) |f| if (f.pager) {
+ try std.testing.expectEqualStrings("one\ntwo\n", f.content);
+ try std.testing.expectEqual(0, f.pager_spans.len);
+ return;
+ };
+ return error.NoPager;
+}