diff options
Diffstat (limited to 'src/addon_test.zig')
| -rw-r--r-- | src/addon_test.zig | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/src/addon_test.zig b/src/addon_test.zig index 7b151ee6..7c9950d7 100644 --- a/src/addon_test.zig +++ b/src/addon_test.zig @@ -2,9 +2,11 @@ //! The addon is loaded into a session of its own (80x24, no terminal, no //! disk, its jobs run at once, its clock virtual, starting at 1 s and moved //! by `tick` and `settle` alone), a pane of it opened, and the script's -//! lines run in turn, each printed with the pane's tag (the kind's own -//! prefix), cells and placements after it; a script compares the output -//! with what it wants as a snapshot script does (`diff`). +//! lines run in turn, each printed with the start of the pane's tag (the +//! kind's prefix, the core's art words, the path), cells and placements +//! after it; a script compares the output with what it wants as a snapshot +//! script does (`diff`). A call into the kind over its budget (16 ms in a +//! Debug pardes) is said, and fails the script. //! //! open [path] a pane of the kind (the first step opens one bare) //! key hjkl<up> keys, a character or <up> <down> <left> <right> @@ -16,9 +18,11 @@ //! (`window CxR` says what the kind paints) //! seed 7 what every pane's seed is made from (before open) //! click 3 1 a left click at the body's column 3, row 1 -//! focus, blur the window takes the keyboard, or loses it -//! graphics on|off a frontend that shows pictures, or one without -//! them (glyph art, the start's) +//! focus, blur the view's window takes the keyboard, or loses it +//! graphics on|off the view's frontend shows pictures, or not +//! (glyph art, the start's) +//! view 2 on|off into view 2 (1 is the start's; one opened as the +//! first is), its frontend with pictures or not //! dump the pane's record (its length) loaded into a //! fresh pane, which the script goes on with //! body, ctl the pane's body, or its ctl file's read @@ -64,6 +68,7 @@ fn run(io: std.Io, gpa: std.mem.Allocator, lib: []const u8, script_path: ?[]cons var now: u64 = std.time.ns_per_s; p.advance(now); var id: ?usize = null; + var said = false; var lines = std.mem.splitScalar(u8, script, '\n'); while (lines.next()) |raw| { const line = std.mem.trim(u8, raw, " \t\r"); @@ -110,9 +115,15 @@ fn run(io: std.Io, gpa: std.mem.Allocator, lib: []const u8, script_path: ?[]cons p.update(.{ .mouse = .{ .button = .left, .kind = mk, .col = body.x + col, .row = body.y + row } }); } else if (is(verb, "focus") or is(verb, "blur")) { p.update(.{ .focus = is(verb, "focus") }); - } else if (is(verb, "graphics")) { - // A frontend that shows pictures (`graphics on`), or glyph art. - p.update(.{ .frontend = .{ .windowed = false, .native_images = std.mem.eql(u8, arg, "on") } }); + } else if (is(verb, "graphics") or is(verb, "view")) { + // Into view N (another client's), then its frontend: with + // pictures (`on`), or glyph art. + if (is(verb, "view")) { + const n = std.fmt.parseInt(u8, arg[0..@min(1, arg.len)], 10) catch 1; + while (n > 1 and !pardes.views.isOpen(p, n - 1)) _ = p.openView() orelse break; + if (pardes.views.isOpen(p, n -| 1)) p.toView(n -| 1); + } + p.update(.{ .frontend = .{ .windowed = false, .native_images = std.mem.endsWith(u8, arg, "on") } }); } else if (is(verb, "dump")) { id = try reloaded(p, gpa, at, out); } else if (is(verb, "body") or is(verb, "ctl")) { @@ -127,8 +138,18 @@ fn run(io: std.Io, gpa: std.mem.Allocator, lib: []const u8, script_path: ?[]cons if (!p.executeBuiltinLine(at, line)) try out.print("not a word here: {s}\n", .{verb}); } drain(p); + // A tick owed (a pane opened or loaded here, outside a step) and a + // view whose facts a frame's layout changed (its tag wrapped), as + // a host steps for them. + if (p.panes[id.?]) |pane| if (window(p, id.?) != null and (pane.addon.?.next_tick == 1 or Kind.viewOwed(p, pane.addon.?, id.?))) { + p.update(.tick); + drain(p); + }; try show(p, gpa, id.?, out, opened or is(verb, "size")); + if (Kind.breach.len > 0 and !said) try out.print("addon-test: {s}\n", .{Kind.breach.slice()}); + said = Kind.breach.len > 0; } + if (said) return error.OverBudget; } fn open(p: *Pardes, k: u8, path: ?[]const u8) !usize { @@ -212,9 +233,8 @@ fn show(p: *Pardes, gpa: std.mem.Allocator, id: usize, out: *std.Io.Writer, size defer arena.deinit(); const s = try p.render(arena.allocator()); const pane = p.panes[id] orelse return out.writeAll("(the pane is gone)\n"); - const slot = pane.addon.?; if (size) if (window(p, id)) |w| try out.print("window {d}x{d}\n", .{ w.w, w.h }); - try out.print("tag {s}\n", .{if (slot.prefix.len > 0) slot.prefix.slice() else slot.nameOf()}); + try out.print("tag {s}\n", .{try Kind.prefix(p, arena.allocator(), pane)}); const r = (s.region(.body, id) orelse return).rect; for (r.y..r.y + r.h) |y| { var row: std.ArrayList(u8) = .empty; |
