summaryrefslogtreecommitdiff
path: root/src/Term.zig
diff options
context:
space:
mode:
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;
+}