summaryrefslogtreecommitdiff
path: root/src/Core.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/Core.zig')
-rw-r--r--src/Core.zig92
1 files changed, 41 insertions, 51 deletions
diff --git a/src/Core.zig b/src/Core.zig
index 8d88fcbd..b24eb6cc 100644
--- a/src/Core.zig
+++ b/src/Core.zig
@@ -23,6 +23,7 @@ const Handover = pardes.Handover;
const Host = pardes.Host;
const ImagePlace = pardes.ImagePlace;
const Jump = pardes.Jump;
+const Ask = pardes.lsp.Ask;
const Key = pardes.Key;
const Loc = Jump.Loc;
const MAX_COLS = pardes.MAX_COLS;
@@ -143,12 +144,8 @@ twin_groups: std.ArrayList(pardes.panes.File.TwinGroup) = .empty,
/// what changed.
mousein_buttons: u8 = 0,
next_twin: u32 = 1,
-jumps: [MAX_JUMPS]Loc = undefined,
-njumps: usize = 0,
-jcur: usize = 0,
-/// The next place tracked is an entry of its own however near the last
-/// (a query answered: Ctrl-o goes back to where it was asked).
-jump_force: bool = false,
+/// The places jumped from (Jump.zig).
+jumps: Jump = .{},
look_src: [MAX_PANES]u32 = undefined,
n_look_src: usize = 0,
look_walk_owner: ?u32 = null,
@@ -293,20 +290,9 @@ repl_ask: ?struct { from: u32, lang: u8, text: []u8, offered: [26]u32 = @splat(0
/// a click, a 9P write, a startup line or a pane's shell exiting.
can_ask: bool = false,
-lsp_seq: u32 = 0,
-/// The last query asked (Lspwhy explains it): its kind, argument, and
-/// the pane and place it was asked at.
-lsp_last: ?struct { kind: lsp.Kind, arg: Effect.Buf(128), serial: u32, offset: u32 } = null,
-lsp_wait: ?struct {
- id: u32,
- kind: lsp.Kind,
- pane: usize,
- serial: u32,
- revision: u32,
- arg: Effect.Buf(128),
- row: i32 = 0,
- col: i32 = 0,
-} = null,
+/// The question to the language servers awaited, and the last asked
+/// (lsp/Ask.zig).
+lsp_ask: Ask = .{},
pipe: Pipe = .{},
/// A query pane's Grep, and its Find's listing, on a worker (Stream.zig).
@@ -320,13 +306,7 @@ needs_frame: bool = true,
/// Set by a shell whose present was skipped (no swapchain image): the
/// frame is still owed, and the next pump draws it again.
present_skipped: bool = false,
-/// Core time. `now_ns` is the shell's monotonic clock as `advance` was
-/// last given it; `stepped_ns` is how far its timings have been
-/// stepped along it, in whole frames of `frame_ns`. Idle, the two are
-/// the same instant.
-now_ns: u64 = 0,
-stepped_ns: u64 = 0,
-clock_started: bool = false,
+clock: Clock = .{},
/// Builtins announce themselves on the message row. Off while startup
/// configuration is applied: those lines are nobody clicking, and should
/// not leave the row holding the name of the last one.
@@ -435,7 +415,7 @@ pub const replica = .{
// session's closed panes, and the files of a host with no file
// system of its own.
.authority = .{ "host", "fs", "store", "recent", "db", "fallback" },
- .len = .{ .{ "jumps", "njumps" }, .{ "look_src", "n_look_src" }, .{ "leader_keys", "leader_n" }, .{ "col_x", "ncol" }, .{ "col_w", "ncol" }, .{ "session_dir", "session_dir_len" } },
+ .len = .{ .{ "look_src", "n_look_src" }, .{ "leader_keys", "leader_n" }, .{ "col_x", "ncol" }, .{ "col_w", "ncol" }, .{ "session_dir", "session_dir_len" } },
};
/// The message row's entry points, called from everywhere as
@@ -1397,7 +1377,7 @@ pub fn pump(p: *Pardes, host: Host) !void {
// The clock read whether or not it is wanted: what a replica
// waits on is its own (a picture decoding wakes only a frame
// that draws it), and the tape has the same calls either way.
- const now = if (v.now) |clock| clock(h.ctx) else p.now_ns;
+ const now = if (v.now) |clock| clock(h.ctx) else p.clock.now_ns;
const timeout: u32 = if (p.nextWake()) |due| wake: {
const ms = ((due -| now) + std.time.ns_per_ms - 1) / std.time.ns_per_ms;
break :wake @intCast(std.math.clamp(ms, 1, std.math.maxInt(u32)));
@@ -1445,7 +1425,7 @@ pub fn pump(p: *Pardes, host: Host) !void {
p.present_skipped = false;
if (v.post_present) |f| f(h.ctx);
// Still moving: the next frame is owed a period from now.
- const owed = if (p.nextWake()) |due| due <= p.stepped_ns + frame_ns else false;
+ const owed = if (p.nextWake()) |due| due <= p.clock.stepped_ns + frame_ns else false;
p.frames.record(FrameStats.nowNs(), owed, skipped);
}
@@ -1947,7 +1927,7 @@ pub fn bodyChrome(p: *Pardes) *const ChromeTheme {
/// which is what lets every shell sleep exactly as long as nothing
/// changes; what moves on the screen is the frontends' own.
pub fn nextWake(p: *const Pardes) ?u64 {
- const next = p.stepped_ns + frame_ns;
+ const next = p.clock.stepped_ns + frame_ns;
// Held 9P writes go in when they pause: wake for it, never before
// the next frame (writes served before the shell's clock was first
// seen are stamped 0, which `advance` would count back from).
@@ -1965,7 +1945,7 @@ pub fn nextWake(p: *const Pardes) ?u64 {
const streaming = p.stream.wake(next);
if (streaming) |due| if (due <= next) return next;
var frames: ?u64 = null;
- if (streaming) |due| frames = @max(1, (due -| p.stepped_ns + frame_ns - 1) / frame_ns);
+ if (streaming) |due| frames = @max(1, (due -| p.clock.stepped_ns + frame_ns - 1) / frame_ns);
if (p.look_hover_wait) |waiting| {
const delay = config.look_preview_delay_frames;
frames = @max(1, delay -| waiting.frames);
@@ -1976,14 +1956,14 @@ pub fn nextWake(p: *const Pardes) ?u64 {
};
// Del's question goes up at the end of its delay: a frame then, and
// none after (stepped time has reached it).
- for (p.panes) |slot| if (slot) |pane| if (pane.prompt == .del_side and pane.question_due_ns > p.stepped_ns) {
- const wait = @max(1, (pane.question_due_ns - p.stepped_ns + frame_ns - 1) / frame_ns);
+ for (p.panes) |slot| if (slot) |pane| if (pane.prompt == .del_side and pane.question_due_ns > p.clock.stepped_ns) {
+ const wait = @max(1, (pane.question_due_ns - p.clock.stepped_ns + frame_ns - 1) / frame_ns);
frames = if (frames) |soonest| @min(soonest, wait) else wait;
};
// A paste's Enter waiting on its REPL goes at the end of its wait,
// a time on the clock: the frames from `stepped_ns` that reach it.
for (p.panes) |slot| if (slot) |pane| if (pane.repl_enter > 0) {
- const wait = @max(1, (pane.repl_enter_due_ns -| p.stepped_ns + frame_ns - 1) / frame_ns);
+ const wait = @max(1, (pane.repl_enter_due_ns -| p.clock.stepped_ns + frame_ns - 1) / frame_ns);
frames = if (frames) |soonest| @min(soonest, wait) else wait;
};
// A terminal's kitty animation, at its next frame. Only a time still
@@ -1991,12 +1971,12 @@ pub fn nextWake(p: *const Pardes) ?u64 {
// and a past one would wake every frame for nothing.
for (p.panes) |slot| if (slot) |pane| if (pardes.panes.terminal.animationDueMs(pane)) |due_ms| {
const due = due_ms *| std.time.ns_per_ms;
- if (due > p.stepped_ns) {
- const wait = @max(1, (due - p.stepped_ns + frame_ns - 1) / frame_ns);
+ if (due > p.clock.stepped_ns) {
+ const wait = @max(1, (due - p.clock.stepped_ns + frame_ns - 1) / frame_ns);
frames = if (frames) |soonest| @min(soonest, wait) else wait;
}
};
- return if (frames) |n| p.stepped_ns + n * frame_ns else null;
+ return if (frames) |n| p.clock.stepped_ns + n * frame_ns else null;
}
/// For shells that only need a yes or no: macOS, which keeps its own
@@ -2015,10 +1995,10 @@ pub fn advance(p: *Pardes, now_ns: u64) void {
const taped = tape.enter(p, .{ .advance = now_ns });
defer tape.leave(p, taped);
// The first time a shell's clock is seen, core time starts there.
- const started = p.clock_started;
- p.clock_started = true;
- p.now_ns = now_ns;
- if (!started) p.stepped_ns = now_ns;
+ const started = p.clock.started;
+ p.clock.started = true;
+ p.clock.now_ns = now_ns;
+ if (!started) p.clock.stepped_ns = now_ns;
const frame = frame_ns;
var moving: u32 = 0;
// The session's ticks are the recording session's: a picture still
@@ -2027,34 +2007,34 @@ pub fn advance(p: *Pardes, now_ns: u64) void {
while (tape.value(.wake, nextWake, .{p})) |due| {
if (due > now_ns) break;
// Only waiting until `due`: its counters move there at once.
- const held = (due - p.stepped_ns) / frame;
+ const held = (due - p.clock.stepped_ns) / frame;
if (held > 1) {
Messages.holdMessages(p, held - 1);
if (p.look_hover_wait) |*waiting| waiting.frames +|= @intCast(@min(held - 1, std.math.maxInt(u16)));
- p.stepped_ns += (held - 1) * frame;
+ p.clock.stepped_ns += (held - 1) * frame;
}
// Back from a stall, the moving frames it missed are not all
// run at once: the rest are stepped from now, at their pace.
if (moving == max_catch_up_frames) {
- p.stepped_ns = now_ns;
+ p.clock.stepped_ns = now_ns;
return;
}
moving += 1;
- p.stepped_ns += frame;
+ p.clock.stepped_ns += frame;
p.update(.tick);
// A stepped frame is a frame to draw. (A `.tick` does not ask
// for one itself: the last frame of a fade used never to be
// drawn.)
p.needs_frame = true;
} else {
- p.stepped_ns = now_ns;
+ p.clock.stepped_ns = now_ns;
return;
}
// A 60 Hz display frame is 16.67 ms and ours 16: without this, every
// 24th display frame would take two steps, a hitch in every fade.
// An overshoot this small is let go; a larger one (144 Hz lands 4.8
// ms past) is kept, so the average rate stays right.
- if (moving > 0 and now_ns - p.stepped_ns < vsync_slack_ns) p.stepped_ns = now_ns;
+ if (moving > 0 and now_ns - p.clock.stepped_ns < vsync_slack_ns) p.clock.stepped_ns = now_ns;
}
pub const vsync_slack_ns = 1500 * std.time.ns_per_us;
@@ -2099,6 +2079,16 @@ pub const Column = struct {
serial: u32 = 0,
};
+/// Core time. `now_ns` is the shell's monotonic clock as `advance` was
+/// last given it; `stepped_ns` is how far its timings have been stepped
+/// along it, in whole frames of `frame_ns`. Idle, the two are the same
+/// instant.
+pub const Clock = struct {
+ now_ns: u64 = 0,
+ stepped_ns: u64 = 0,
+ started: bool = false,
+};
+
pub const Boot = enum {
/// the document named on the command line, or the pane explaining why not
document,
@@ -2848,7 +2838,7 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe
// Python's echo only restarts a short wait: the Enter goes once the
// echo of the whole paste has gone quiet.
try std.testing.expectEqualStrings("", Sent.said(1));
- p.now_ns = p.panes[1].?.repl_enter_due_ns;
+ p.clock.now_ns = p.panes[1].?.repl_enter_due_ns;
p.update(.tick);
Sent.drain(p);
try std.testing.expectEqualStrings("\r", Sent.said(1));
@@ -2856,7 +2846,7 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe
_ = exec.executeFrom(p, 0, "print(11)\nprint(22)", true);
Sent.drain(p);
try std.testing.expectEqualStrings("\x1b[200~print(11)\nprint(22)\x1b[201~", Sent.said(1));
- p.now_ns = p.panes[1].?.repl_enter_due_ns;
+ p.clock.now_ns = p.panes[1].?.repl_enter_due_ns;
p.update(.tick);
Sent.drain(p);
try std.testing.expectEqualStrings("\r\r", Sent.said(1));
@@ -2865,7 +2855,7 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe
p.update(.tick); // on the clock: not yet, however old core time is
Sent.drain(p);
try std.testing.expect(std.mem.endsWith(u8, Sent.said(1), "\x1b[200~print(2)\x1b[201~"));
- p.now_ns = p.panes[1].?.repl_enter_due_ns; // the clock reaches its wait
+ p.clock.now_ns = p.panes[1].?.repl_enter_due_ns; // the clock reaches its wait
p.update(.tick);
Sent.drain(p);
try std.testing.expectEqualStrings("\r", Sent.said(1));