summaryrefslogtreecommitdiff
path: root/core/Term.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/Term.zig')
-rw-r--r--core/Term.zig63
1 files changed, 47 insertions, 16 deletions
diff --git a/core/Term.zig b/core/Term.zig
index fde36420..89773f77 100644
--- a/core/Term.zig
+++ b/core/Term.zig
@@ -14,8 +14,17 @@ const dump = @import("dump.zig");
const File = @import("File.zig");
const iface = plain.term;
+/// Writes into this process's emulators (a read fed, a grid reflowed, a
+/// view moved, one opened, closed, loaded or made again): whether a unit's
+/// replay made one, the replica engine's one rule (core/replica.zig
+/// `confirm`) reads across that replay, on its one thread.
+pub var writes: u32 = 0;
+/// The reloads this process made (a join's, on every side) and their time,
+/// for the soak's join line (test/replicas.zig `--bytes`).
+pub var reloads: struct { n: u32 = 0, ns: u64 = 0, worst_ns: u64 = 0 } = .{};
+
/// The terminal module's entries; null in a core built without it.
-pub const ops: ?*const iface.Ops = if (@import("term_options").terminal) &@import("term").ops else null;
+pub const ops: ?*const iface.Ops = if (@import("pardes_options").terminal) &@import("term").ops else null;
/// What a core without a terminal says, once, where one would have been.
pub const none = "no terminal in this build";
@@ -30,6 +39,8 @@ pub const Moves = iface.Moves;
pub const MouseMods = iface.MouseMods;
pub const MouseButton = iface.MouseButton;
pub const MouseAction = iface.MouseAction;
+/// A grid cell (the one a program last heard the mouse at: Pane.term_mouse).
+pub const Coordinate = iface.Parts.Coordinate;
pub const Page = iface.Page;
pub const Span = iface.Span;
pub const Ink = iface.Ink;
@@ -92,6 +103,9 @@ pub const State = struct {
defer arena.deinit();
const parts = try walk.load(iface.Parts, arena.allocator(), bytes[8..][0..n], null);
out.* = .{ .impl = try o.load(gpa, bytes[8 + n ..], &parts) };
+ writes +%= 1;
+ // A replica's (a join's, a closed terminal brought back in a step).
+ if (tape.replaying() or dump.terminal_gpa != null) o.direct(out.impl);
}
};
@@ -112,6 +126,10 @@ pub fn open(gpa: std.mem.Allocator, cols: u16, rows: u16) !*State {
const s = try gpa.create(State);
errdefer gpa.destroy(s);
s.* = .{ .impl = try o.open(gpa, cols, rows) };
+ writes +%= 1;
+ // A replica's emulator loads its program's images by direct data alone
+ // (P32): what is read off the session's machine is the session's.
+ if (tape.replaying()) o.direct(s.impl);
return s;
}
@@ -119,10 +137,27 @@ pub fn open(gpa: std.mem.Allocator, cols: u16, rows: u16) !*State {
/// one it was opened with): the allocator a caller hands is not used.
pub fn close(s: *State, _: std.mem.Allocator) void {
const own = the().gpa(s.impl);
+ writes +%= 1;
the().close(s.impl);
own.destroy(s);
}
+/// Its emulator made again from its own snapshot, where it is: at a join
+/// every side does it, so that all hold the same pages (ghostty prunes its
+/// history a page at a time, and a snapshot does not say how its rows were
+/// cut into pages). The snapshot's hash, which every side compares.
+pub fn reload(s: *State) !u64 {
+ writes +%= 1;
+ const t0 = @import("FrameStats.zig").nowNs();
+ defer {
+ reloads.n += 1;
+ const dt = @import("FrameStats.zig").nowNs() -| t0;
+ reloads.ns += dt;
+ reloads.worst_ns = @max(reloads.worst_ns, dt);
+ }
+ return the().reload(s.impl);
+}
+
/// When its next kitty animation frame is due (ms on the core's clock), as
/// its last drawn frame left it; null when nothing plays.
pub fn due(s: *const State) ?u64 {
@@ -132,6 +167,7 @@ pub fn due(s: *const State) ?u64 {
/// Loaded from a dump without its shell: its program's modes reset, its
/// history marked off from what the next shell prints.
pub fn revive(s: *State) void {
+ writes +%= 1;
the().revive(s.impl);
}
@@ -150,6 +186,7 @@ pub fn stop() void {
/// One read of its program's output (`Told` says where the tracked rows
/// went).
pub fn feed(s: *State, bytes: []const u8, tracked: []const i32, rows: []i32, erased: []bool) Told {
+ writes +%= 1;
return the().feed(s.impl, bytes, tracked, rows, erased);
}
@@ -161,25 +198,30 @@ pub fn grid(s: ?*const State) Grid {
/// Its view to a row of its history, or onto its output (null).
pub fn viewTo(s: *State, at: ?usize) void {
+ writes +%= 1;
the().viewTo(s.impl, at);
}
/// Its view moved by a number of rows (negative scrolls back).
pub fn scroll(s: *State, delta: i32) void {
+ writes +%= 1;
the().scroll(s.impl, delta);
}
/// Its view back onto its output.
pub fn follow(s: *State) void {
+ writes +%= 1;
the().follow(s.impl);
}
/// Its grid reflowed, now or when `resizeDeferred` makes it.
pub fn resize(s: *State, cols: u16, rows: u16, later: bool) void {
+ writes +%= 1;
the().resize(s.impl, cols, rows, later);
}
pub fn resizeDeferred(s: *State) bool {
+ writes +%= 1;
return the().resizeDeferred(s.impl);
}
@@ -204,13 +246,13 @@ pub fn key(s: *State, k: plain.Key, out: *std.Io.Writer) !void {
/// One mouse event for its program, as the mode and format it set ask for
/// it; empty when the program does not hear of it.
-pub fn mouse(s: *State, buf: *[64]u8, action: MouseAction, button: ?MouseButton, mods: MouseMods, col: i32, row: i32, any_pressed: bool) []const u8 {
- return the().mouse(s.impl, buf, action, button, mods, col, row, any_pressed);
+pub fn mouse(s: *State, last: *?Coordinate, buf: *[64]u8, action: MouseAction, button: ?MouseButton, mods: MouseMods, col: i32, row: i32, any_pressed: bool) []const u8 {
+ return the().mouse(s.impl, last, buf, action, button, mods, col, row, any_pressed);
}
/// A wheel turn for its program; null when the wheel is not the program's.
-pub fn wheel(s: *State, buf: *[64]u8, turn: MouseButton, col: u16, row: u16, mods: MouseMods) ?[]const u8 {
- return the().wheel(s.impl, buf, turn, col, row, mods);
+pub fn wheel(s: *State, last: *?Coordinate, buf: *[64]u8, turn: MouseButton, col: u16, row: u16, mods: MouseMods) ?[]const u8 {
+ return the().wheel(s.impl, last, buf, turn, col, row, mods);
}
/// A paste as xterm makes one: three parts, the text between the brackets
@@ -354,17 +396,6 @@ pub fn images(s: *State, gpa: std.mem.Allocator, at: ImagesAt, out: *std.ArrayLi
the().images(s.impl, gpa, at, out, frame, frame_cols);
}
-/// The Petscii builtin on it: its kitty graphics as glyph art, or back to
-/// pixels; null for none.
-pub fn petscii(s: ?*const State) ?bool {
- const o = ops orelse return null;
- return o.petscii(if (s) |state| state.impl else null);
-}
-
-pub fn togglePetscii(s: *State) void {
- the().togglePetscii(s.impl);
-}
-
/// Whether the screen showing holds any kitty graphics image.
pub fn hasImages(s: ?*const State) bool {
const o = ops orelse return false;