summaryrefslogtreecommitdiff
path: root/src/terminal.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/terminal.zig')
-rw-r--r--src/terminal.zig17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/terminal.zig b/src/terminal.zig
index e737a831..81fae5db 100644
--- a/src/terminal.zig
+++ b/src/terminal.zig
@@ -417,9 +417,18 @@ pub fn panFor(p: *const Pardes, pane: *const Pane, r: pardes.Rect) u16 {
return @intCast(@min(pane.rows - shown, (at + 1) -| shown));
}
+/// A replica's speculation leaves an emulator be: it is the authority's
+/// (docs/next-daemon.md, phase 5), so the input waits for its order.
+fn authorityOnly() bool {
+ if (!pardes.tape.speculating()) return false;
+ pardes.tape.poison();
+ return true;
+}
+
/// Move the emulator's viewport by `delta` shell rows (negative scrolls back).
pub fn scrollGrid(pane: *Pane, delta: i32) void {
if (comptime !enabled) return;
+ if (authorityOnly()) return;
const state = pane.terminal orelse return;
state.vt.screens.active.scroll(.{ .delta_row = delta });
}
@@ -434,6 +443,7 @@ pub fn atBottom(pane: *const Pane) bool {
/// Snap the viewport back onto live output.
pub fn followOutput(pane: *Pane) void {
if (comptime !enabled) return;
+ if (authorityOnly()) return;
const state = pane.terminal orelse return;
state.vt.screens.active.scroll(.active);
}
@@ -442,6 +452,7 @@ pub fn followOutput(pane: *Pane) void {
/// a scrollback; the next resize retries with the same numbers.
pub fn resizeGrid(pane: *Pane, gpa: std.mem.Allocator, cols: u16, rows: u16) void {
if (comptime !enabled) return;
+ if (authorityOnly()) return;
const state = pane.terminal orelse return;
if (cols != pane.cols) for (0..pane.sel.len) |button| {
pane.clearPointerSelection(button);
@@ -643,6 +654,7 @@ pub fn screenTextLen(pane: *Pane) usize {
/// Release the emulator's heap. The Pane allocation itself is the core's.
pub fn deinitEmulator(pane: *Pane, gpa: std.mem.Allocator) void {
if (comptime !enabled) return;
+ if (authorityOnly()) return;
const state = pane.terminal orelse return;
if (comptime images_enabled) state.images.deinit(gpa);
state.stream.deinit();
@@ -654,6 +666,7 @@ pub fn deinitEmulator(pane: *Pane, gpa: std.mem.Allocator) void {
/// Allocate the live emulator half of a terminal pane. Slot ownership, serial
/// assignment, and spawn effects remain core lifecycle invariants.
pub fn create(gpa: std.mem.Allocator, cols: u16, rows: u16) !*Pane {
+ if (authorityOnly()) return error.OutOfMemory;
const pane = try createDoc(gpa, cols, rows);
errdefer gpa.destroy(pane);
if (comptime !enabled) return pane;
@@ -674,6 +687,9 @@ pub fn create(gpa: std.mem.Allocator, cols: u16, rows: u16) !*Pane {
});
state.stream = .init(.{ .handler = .{ .inner = state.vt.vtHandler() }, .allocator = gpa });
state.reply_len = 0;
+ // Every field its default (create leaves them what the heap had, which
+ // a digest then reads: two replicas must agree, src/replica.zig).
+ state.reply_dropped = 0;
state.mouse_cell = null;
state.images = if (images_enabled) .{} else {};
if (comptime images_enabled) TerminalImages.installPngDecoder();
@@ -900,6 +916,7 @@ pub fn feedOutput(p: *Pardes, pane: *Pane, bytes: []const u8) void {
// There are no pty reads at all without an emulator to parse them into.
if (comptime !enabled) return;
if (pane.terminal == null) return;
+ if (authorityOnly()) return;
const has_positions = pane.ovl != null or pane.body.cur_pinned or pane.body.vsel.active or
pane.body.msel.active or pane.body.nsel > 0 or pane.body.last_edit != null or pane.look_at != null or
pane.body.ed_undo_len > 0 or pane.body.ed_redo_len > 0 or pointerRowCount(pane) > 0;