summaryrefslogtreecommitdiff
path: root/core/panes.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/panes.zig')
-rw-r--r--core/panes.zig24
1 files changed, 16 insertions, 8 deletions
diff --git a/core/panes.zig b/core/panes.zig
index fd152e1e..1c103bd1 100644
--- a/core/panes.zig
+++ b/core/panes.zig
@@ -53,6 +53,10 @@ pub const Pane = struct {
return @backingInt(id);
}
};
+ /// Del's question asked, its time not had yet: the step that asks
+ /// reads no clock (a far client's would wait on the session's), and
+ /// core time is the last frame's, seconds old in an idle session.
+ pub const question_asked: u64 = std.math.maxInt(u64);
/// The words that throw unsaved text away (builtins.zig warnModified).
pub const Discarding = enum { Exit, Restore, get, Del, Delcol };
@@ -218,7 +222,9 @@ pub const Pane = struct {
repl_enter: u8 = 0,
repl_enter_due_ns: u64 = 0,
/// When Del's question (`del_side`) goes up on the notice band, on the
- /// shell's clock (config.del_question_delay_ns after it was asked).
+ /// shell's clock (config.del_question_delay_ns after it was asked):
+ /// `question_asked` until the next advance, which counts the delay
+ /// from its own time (Core.advance).
question_due_ns: u64 = 0,
/// A question with its answers in it (`repl_choice`).
question: [96]u8 = undefined,
@@ -715,7 +721,7 @@ pub const Pane = struct {
pub fn feedOutput(pane: *Pane, p: *Pardes, bytes: []const u8) void {
// There are no pty reads at all without an emulator to parse them into.
const state = pane.terminal orelse return;
- if (tape.authorityOnly("a terminal's output")) return;
+ if (p.tape.authorityOnly("a terminal's output")) return;
const has_positions = pane.ovl != null or pane.body.cur_pinned or pane.body.vsel.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 pane.pointerRowCount() > 0;
@@ -1026,11 +1032,11 @@ pub const Pane = struct {
/// started, for Kill: it runs from the shell's next C mark to its D.
/// ponytail: of several lines queued for a shell not up yet, only the
/// last is remembered, as the first of them.
- pub fn noteCommand(pane: *Pane, line: []const u8) void {
- const state = pane.terminal orelse return;
+ pub fn noteCommand(pane: *Pane, line: []const u8, started: u32) void {
+ if (pane.terminal == null) return;
const said = std.mem.trim(u8, line, " \t");
const word = said[0 .. std.mem.indexOfAny(u8, said, " \t") orelse said.len];
- var sent: @typeInfo(@FieldType(Pane, "sent_command")).optional.child = .{ .seq = Term.prompt(state).started +% 1 };
+ var sent: @typeInfo(@FieldType(Pane, "sent_command")).optional.child = .{ .seq = started +% 1 };
sent.len = @intCast(@min(word.len, sent.word.len));
@memcpy(sent.word[0..sent.len], word[0..sent.len]);
pane.sent_command = sent;
@@ -1166,7 +1172,6 @@ pub fn createDoc(gpa: std.mem.Allocator, cols: u16, rows: u16) !*Pane {
/// A terminal pane: a pane and its emulator. Slot ownership, serial
/// assignment and spawn effects remain core lifecycle invariants.
pub fn createTerminal(gpa: std.mem.Allocator, cols: u16, rows: u16) !*Pane {
- if (tape.authorityOnly("open a terminal")) return error.OutOfMemory;
const pane = try createDoc(gpa, cols, rows);
errdefer gpa.destroy(pane);
pane.terminal = try Term.open(emulatorGpa(gpa), cols, rows);
@@ -1230,7 +1235,7 @@ pub fn retirePane(p: *Pardes, pane: *Pane) void {
if (pane.isTerminal()) p.emit(.{ .close_pty = .{ .pane = .at(id) } });
// Its pty's end and its emulator are the authority's: a replica's
// speculation that closes a terminal waits for it.
- if (pane.terminal != null) tape.poison("close a terminal");
+ if (pane.terminal != null) p.tape.poison("close a terminal");
ctlfs.events.noteRetire(p, pane);
// ...and so do bytes still queued for the pty it no longer has.
p.dropPendingWrite(id);
@@ -1271,7 +1276,7 @@ pub fn teardownPane(p: *Pardes, pane: *Pane) void {
}
// A pane with none (a file's, a picker's, a preview's) closes in a
// speculation as anywhere.
- if (pane.terminal) |state| if (!tape.authorityOnly("close a terminal")) {
+ if (pane.terminal) |state| if (!p.tape.authorityOnly("close a terminal")) {
Term.close(state, p.gpa);
pane.terminal = null;
};
@@ -1307,6 +1312,8 @@ pub fn installPane(p: *Pardes, id: usize, pane: *Pane) void {
pub fn newShell(p: *Pardes, id: usize, cwd: []const u8) !*Pane {
std.debug.assert(p.panes[id] == null);
if (cwd.len > limits.host_path_cap) return error.PathTooLong;
+ // A speculation opens no emulator: a terminal is the authority's to open.
+ if (p.tape.authorityOnly("open a terminal")) return error.OutOfMemory;
const pane = try panes.createTerminal(p.gpa, p.view().screen_w, p.view().screen_h);
// Named by the directory it is started in from the first, so the
// shell saying it is there is no rename (`new N /` then `rename`);
@@ -1339,6 +1346,7 @@ pub fn newCommand(p: *Pardes, id: usize, cwd: []const u8, line: []const u8) !*Pa
if (cwd.len > limits.host_path_cap) return error.PathTooLong;
const owned = try p.gpa.dupe(u8, line);
errdefer p.gpa.free(owned);
+ if (p.tape.authorityOnly("open a terminal")) return error.OutOfMemory;
const pane = try panes.createTerminal(p.gpa, p.view().screen_w, p.view().screen_h);
pane.command = owned;
pane.command_pty = true;