summaryrefslogtreecommitdiff
path: root/core/Core.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/Core.zig')
-rw-r--r--core/Core.zig119
1 files changed, 55 insertions, 64 deletions
diff --git a/core/Core.zig b/core/Core.zig
index 61d8c7e9..2c04cc64 100644
--- a/core/Core.zig
+++ b/core/Core.zig
@@ -183,6 +183,10 @@ pub const View = struct {
/// A key that waits for the next: the leader (SPC) or the window prefix
/// (Ctrl-w), one at a time.
prefix: enum { none, leader, window } = .none,
+ /// A background question SPC e gave the keyboard: the serial of the
+ /// pane it waits on (0: none). Its next key answers it; Esc leaves it
+ /// waiting (keys.zig handleKey).
+ answering: u32 = 0,
/// The register the running normal command names (`"<reg>`); 0 for the
/// default one.
register: u21 = 0,
@@ -343,6 +347,11 @@ locations_cache: locations.Cache = .{},
tty_filter_palette: pardes.Term.FilterPalette = .{},
font_request_taken: bool = false,
custom_theme: ?Theme = null,
+/// The theme the window wears while a picker of them (or `:theme `)
+/// previews one, by index, and its chrome (colors.previewTheme); the
+/// session's own theme untouched under it.
+theme_preview: ?u16 = null,
+preview_chrome: ChromeTheme = colors.initial_chrome,
/// bodyChrome's: the theme it was worked out for, and it.
body_chrome: ?struct { theme: Theme, chrome: ChromeTheme } = null,
theme_file_path: config.Settings.Text(limits.host_path_cap) = .{},
@@ -359,8 +368,8 @@ chrome: colors.ChromeTheme = colors.initial_chrome,
frames: *FrameStats = undefined,
own_frames: FrameStats = .{},
quit: bool = false,
-/// A detached session with no frontend attached: nothing renders, so
-/// no input ever dismisses a message (Messages.expireUnattended).
+/// A detached session with no frontend attached: nothing renders, and a
+/// 9P write may size its view (ninep/ctl.zig `size`).
unattended: bool = false,
haptic: HapticSlot = if (platform == .macos) .none else {},
/// The look just run found nothing (look.zig missed).
@@ -402,6 +411,9 @@ lsp_ask: Ask = .{},
pipe: Pipe = .{},
/// A query pane's Grep, and its Find's listing, on a worker (Stream.zig).
stream: Stream = .{},
+/// The pickers: the one live in a view's tag, and the last ones rolled
+/// up, which their list words and Resume reopen (Pick.zig).
+picks: [pardes.Pick.max_lists]?*pardes.Pick = @splat(null),
/// The panes' `Changes` (jj.zig): what was asked of jj, and what it
/// answered for each pane, by its serial: the session's, not a field of
/// every pane (a digest and a rollback copy walk every pane's fields at
@@ -531,7 +543,7 @@ pub const replica = .{
"opts", "dump_out", "dump_export",
"tape",
},
- .derived = .{ "shell_rows", "diff_output", "locations_cache", "retired_panes", "tty_filter_palette", "body_chrome" },
+ .derived = .{ "shell_rows", "diff_output", "locations_cache", "retired_panes", "tty_filter_palette", "body_chrome", "theme_preview", "preview_chrome" },
// The host's handles, the state file every session of the user
// shares (and Recent read from it), this session's closed panes, and
// the files of a host with no file system of its own. (The 9P
@@ -935,6 +947,7 @@ pub fn deinit(p: *Pardes) void {
look.cancelLookHover(p);
if (p.repl_ask) |ask| p.gpa.free(ask.text);
for (0..MAX_PANES) |id| p.dropPendingWrite(id);
+ pardes.Pick.deinitAll(p);
// The panes, then those retired these last two frames.
inline for (.{ &p.panes, &p.retired_panes.previous, &p.retired_panes.current }) |slots| for (slots) |*slot| if (slot.*) |pane| {
pardes.panes.teardownPane(p, pane);
@@ -1038,7 +1051,8 @@ fn reportFocus(p: *Pardes) void {
// program hears of it a round trip later (a write there would stop the
// speculation: pty_write is `keeps_stopping`'s).
if (p.tape.speculating) return;
- if (v.focus_told) |old| if (p.panes[old.id]) |pane| {
+ // A damaged dump's pane past the slots names none.
+ if (v.focus_told) |old| if (old.id < MAX_PANES) if (p.panes[old.id]) |pane| {
if (pane.serial == old.serial and pardes.Term.modes(pane.terminal).focus) p.emitWrite(old.id, "\x1b[O");
};
if (want) |new| if (pardes.Term.modes(p.panes[new.id].?.terminal).focus) p.emitWrite(new.id, "\x1b[I");
@@ -1589,11 +1603,6 @@ pub fn pump(p: *Pardes, host: Host) !void {
} else 0;
_ = p.tape.host(p, .wait_input, .{timeout});
}
- // Detached, nobody's key dismisses a message: they go on the clock,
- // here in the step, where the clock read is taped (the host's wait
- // did it, untaped, and a replay kept a message its session had let
- // go).
- Messages.expireUnattended(p);
p.frames.mark_start = FrameStats.nowNs();
if (p.tape.host(p, .now, .{})) |now| p.advance(now);
p.settle();
@@ -1714,18 +1723,13 @@ fn updateInner(p: *Pardes, ev: Event) void {
// Its bands as its state stands: a step reads them (a press on a chip, a
// body's top under them), and what a frame drew, a view put back or a
// dump left in Pane.notices (derived) is not what every core has.
- for (p.panes, 0..) |slot, id| if (slot) |pane| Messages.collectNotices(p, pane, v.rects[id], id);
+ for (p.panes, 0..) |slot, id| if (slot) |pane| Messages.collectNotices(p, pane, v.rects[id]);
defer pardes.panes.File.syncTwins(p);
defer p.reportFocus();
// A tick with no deadline due is the one event that cannot change
// the screen.
p.needs_frame = p.needs_frame or ev != .tick;
p.shell_rows.sweep(p.gpa);
- Messages.expireUnattended(p);
- // An announcement stands in only until its own step says more.
- for (p.panes) |slot| if (slot) |pane| {
- pane.msg_announcement = false;
- };
// A Look's hover outlives a tick, a batch of rows coming in (no
// gesture), a move with no button, and a change to another pane.
const hover_stays = switch (ev) {
@@ -1740,15 +1744,9 @@ fn updateInner(p: *Pardes, ev: Event) void {
look.cancelLookHover(p);
}
switch (ev) {
- .key, .mouse => {
- for (p.panes) |slot| {
- if (slot) |pane| Messages.dismissMessage(p, pane);
- }
- v.clip_pending = null;
- },
+ .key, .mouse => v.clip_pending = null,
.tick => {
Stream.step(p);
- Messages.advanceMessages(p);
for (0..p.panes.len) |id| exec.flushReplEnter(p, id, false);
},
else => {},
@@ -1836,6 +1834,7 @@ fn updateInner(p: *Pardes, ev: Event) void {
pardes.Prompt.settle(p);
// Each live query pane's rows, made from what changed this step.
pardes.panes.Query.produceAll(p, ev == .tick, ev == .key);
+ pardes.Pick.produceAll(p, ev == .tick);
_ = p.scratch.reset(.{ .retain_with_limit = memory.limits.scratch_kept });
p.sync();
p.fsReport();
@@ -1917,10 +1916,10 @@ pub const SavePath = Effect.Buf(effect_path_cap);
pub const noteLateFailure = pardes.tape.taped(noteLateFailureInner);
fn noteLateFailureInner(p: *Pardes, id: Pane.Id) void {
// Said by reportFailure just now: its words fitted whole, the
- // reason kept; else what the message row has.
+ // reason kept; else what was said of the pane last.
const said = if (p.fs.said_at == p.fs.failures and p.fs.said_len > 0)
p.fs.said[0..p.fs.said_len]
- else if (p.panes[id.index()]) |pane| pane.msg[0..pane.msg_len] else return;
+ else if (p.panes[id.index()]) |pane| p.messages.saidBy(pane) else return;
const kept = @import("Messages.zig").clip(said, p.fs.late_failure.len);
@memcpy(p.fs.late_failure[0..kept.len], kept);
p.fs.late_failure_len = @intCast(kept.len);
@@ -1931,7 +1930,7 @@ fn noteLateFailureInner(p: *Pardes, id: Pane.Id) void {
pub const presented = pardes.tape.taped(presentedInner);
fn presentedInner(p: *Pardes) void {
const v = p.view();
- for (p.panes, 0..) |slot, id| if (slot) |pane| Messages.collectNotices(p, pane, v.rects[id], id);
+ for (p.panes, 0..) |slot, id| if (slot) |pane| Messages.collectNotices(p, pane, v.rects[id]);
if (v.pointer_inside and v.drag != .none) {
v.hover_col = v.pointer_raw_col;
v.hover_row = v.pointer_raw_row;
@@ -2040,6 +2039,15 @@ pub fn sync(p: *Pardes) void {
caret_row = std.mem.count(u8, shown.text[0..@min(shown.fromReal(cur), shown.text.len)], "\n");
}
if (!pane.tag_expanded) wanted = 1;
+ // Out of rest the head is the tag's text (TagState), and the tag
+ // keeps the rows its own text takes at least: a head shorter than
+ // it (a root's key cell, before its level shows) moved the body up
+ // and back down a moment later; a terminal's exactly those, its pty
+ // its body (a resize the program under it saw at every C-w and SPC).
+ if (pardes.TagState.hostOf(p) == id) {
+ const rest = layout.wantedTagRows(p, id);
+ wanted = if (pane.isTerminal()) rest else @max(wanted, rest);
+ }
pane.tag_rows = @intCast(@min(wanted, MAX_TAG_ROWS, @max(BOX_H, r.h -| 1)));
if (pane.collapsed) pane.tag_rows = BOX_H;
if (pane.focus == .tag and pane.prompt != .name) {
@@ -2047,7 +2055,7 @@ pub fn sync(p: *Pardes) void {
var top: usize = pane.tag_top;
if (cur < top) top = cur;
if (cur >= top + pane.tag_rows) top = cur + 1 - pane.tag_rows;
- pane.tag_top = @intCast(@min(top, lines - pane.tag_rows));
+ pane.tag_top = @intCast(@min(top, lines -| pane.tag_rows));
} else pane.tag_top = 0;
// The band unrolled under the tag's text pushes the body down:
// the tag's rows, as everything under them counts them.
@@ -2087,7 +2095,7 @@ pub fn sync(p: *Pardes) void {
}.ready, .{pane}));
// Which bands a pane shows is the step's, as its geometry is:
// what is drawn under them, and where a click lands, read it.
- Messages.collectNotices(p, pane, r, id);
+ Messages.collectNotices(p, pane, r);
// The greeting `ls` of a new terminal in a directory is typed at
// its shell's FIRST prompt, or never: typed later it would land
// in whatever runs then, or in the middle of a line someone
@@ -2137,12 +2145,14 @@ fn sizes(p: *const Pardes, pane: *const Pane) bool {
}
pub fn theme(p: *const Pardes) *const Theme {
+ if (p.theme_preview) |i| return &themes[i];
if (p.custom_theme) |*custom| return custom;
return &themes[p.settings.theme];
}
/// The colours of the chrome: the theme's, set as it changes.
pub fn chromeTheme(p: *const Pardes) *const ChromeTheme {
+ if (p.theme_preview != null) return &p.preview_chrome;
return &p.chrome;
}
@@ -2174,7 +2184,7 @@ pub fn nextWake(p: *const Pardes) ?u64 {
for (p.panes) |slot| if (slot) |pane| if (pane.places.busy(pane)) return next;
const kinds = pardes.Kind.wake(p);
if (kinds) |due| if (due <= next) return next;
- if (pardes.panes.Query.busy(p)) return next;
+ if (pardes.panes.Query.busy(p) or pardes.Pick.busy(p)) return next;
// A typed Grep waiting out its pause.
const streaming = p.stream.wake(next);
if (streaming) |due| if (due <= next) return next;
@@ -2184,10 +2194,11 @@ pub fn nextWake(p: *const Pardes) ?u64 {
const delay = config.look_preview_delay_frames;
frames = @max(1, delay -| waiting.frames);
}
- for (p.panes) |slot| if (slot) |pane| {
- const wait = Messages.messageWake(p, pane) orelse continue;
+ // A message dims at the end of its bright time.
+ if (Messages.dimDue(p)) |due| {
+ const wait = @max(1, (due - p.clock.stepped_ns + frame_ns - 1) / frame_ns);
frames = if (frames) |soonest| @min(soonest, wait) else wait;
- };
+ }
// 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.clock.stepped_ns and pane.question_due_ns != Pane.question_asked) {
@@ -2252,7 +2263,6 @@ fn advanceInner(p: *Pardes, now_ns: u64) void {
// Only waiting until `due`: its counters move there at once.
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.clock.stepped_ns += (held - 1) * frame;
}
@@ -2658,36 +2668,18 @@ test "TreeContext rows in the tag style keep the message rows" {
p.update(.{ .resize = .{ .cols = 60, .rows = 16, .row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 6, .tagline_h = 12 } } });
pane.file.?.tree_context = true;
pane.file.?.scroll = 8;
- pane.msg_len = 0;
+ p.messages.live_len = 0;
p.sync();
_ = try p.render(p.scratch.allocator());
const full_height = p.surface.body_layers[0].viewport.h;
try std.testing.expect(p.surface.body_layers[0].rows > full_height);
try std.testing.expectEqual(FontRole.tagline, p.surface.body_layers[0].cells[0].style.font_role);
- pane.msg[0] = '!';
- pane.msg_len = 1;
- p.sync();
- _ = try p.render(p.scratch.allocator());
- // An overlay takes nothing: the message is a chip OVER the body's first
- // row, so the viewport keeps every row it had.
- try std.testing.expectEqual(full_height, p.surface.body_layers[0].viewport.h);
- const r = p.view().rects[0];
- const band = for (p.surface.tagLayers()) |*layer| {
- if (layer.rows != 0 and layer.kind == .notice) break layer;
- } else return error.NoNoticeBand;
- try std.testing.expectEqual(p.bodyTop(pane, r), band.viewport.y);
- try std.testing.expectEqual(p.surface.body_layers[0].viewport.y, band.viewport.y);
- // Sized to its message, flush with the pane's right edge, and the text
- // right aligned a cell short of that edge.
- try std.testing.expectEqual(r.x + r.w, band.viewport.x + band.viewport.w);
- try std.testing.expect(band.viewport.w < r.w - config.GUTTER);
- try std.testing.expectEqualStrings("!", band.cells[layout.tagCapacity(p, band.viewport.w) - 2].grapheme());
- pane.msg_len = 0;
- p.view().prefix = .leader;
+ // A message is on the notice row, not over the body: the viewport
+ // keeps every row it had.
+ _ = Messages.keep(p, .notice, pane.serial, "", "!");
p.sync();
_ = try p.render(p.scratch.allocator());
try std.testing.expectEqual(full_height, p.surface.body_layers[0].viewport.h);
- p.view().prefix = .none;
}
test "TreeContext command and custom tag survive a workspace round trip" {
@@ -3069,7 +3061,7 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe
try std.testing.expect(file.repl == null);
try std.testing.expect(p.executeBuiltinLine(1, "Repl pithon"));
try std.testing.expect(p.panes[1].?.repl == null);
- try std.testing.expect(std.mem.indexOf(u8, p.panes[1].?.msg[0..p.panes[1].?.msg_len], "python") != null);
+ try std.testing.expect(std.mem.indexOf(u8, p.messages.saidBy(p.panes[1].?), "python") != null);
try std.testing.expect(p.executeBuiltinLine(1, "Repl python"));
// again, as a code fence may name it: no change
try std.testing.expect(p.executeBuiltinLine(1, "Repl PY"));
@@ -3083,8 +3075,7 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe
Sent.drain(p);
try std.testing.expectEqualStrings("ls\r", Sent.said(1));
try std.testing.expect(!Sent.spawned);
- try std.testing.expect(file.msg_sent);
- try std.testing.expectEqualStrings("\u{2192} python-a", file.msg[0..file.msg_len]);
+ try std.testing.expectEqualStrings("\u{2192} python-a", p.messages.saidBy(file));
// A body's click written back to event is done as the click: sent. A
// line written to exec came back as F and runs as the command it was.
{
@@ -3207,7 +3198,7 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe
p.update(.{ .key = .{ .cp = 'b' } });
Sent.drain(p);
try std.testing.expect(Sent.len[1] == 0 and Sent.len[2] == 0);
- try std.testing.expectEqualStrings("Repl: the REPL chosen is gone; nothing sent", file.msg[0..file.msg_len]);
+ try std.testing.expectEqualStrings("Repl: the REPL chosen is gone; nothing sent", p.messages.saidBy(file));
try std.testing.expect(p.executeBuiltinLine(2, "Repl python"));
try std.testing.expectEqualStrings("python-b", exec.replId(&idbuf, p.panes[2].?));
@@ -3224,7 +3215,7 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe
try std.testing.expectEqual(Pane.Prompt.none, file.prompt);
Sent.drain(p);
try std.testing.expect(Sent.len[1] == 0 and Sent.len[2] == 0 and !Sent.spawned);
- try std.testing.expect(std.mem.indexOf(u8, file.msg[0..file.msg_len], "no program running") != null);
+ try std.testing.expect(std.mem.indexOf(u8, p.messages.saidBy(file), "no program running") != null);
host.taken[1] = true;
host.taken[2] = true;
@@ -3234,7 +3225,7 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe
try std.testing.expect(p.executeBuiltinLine(1, "Repl python"));
try std.testing.expectEqualStrings("python-a", exec.replId(&idbuf, p.panes[1].?));
try std.testing.expect(p.executeBuiltinLine(2, "Repl"));
- try std.testing.expectEqualStrings("Repl: python-b", p.panes[2].?.msg[0..p.panes[2].?.msg_len]);
+ try std.testing.expectEqualStrings("Repl: python-b", p.messages.saidBy(p.panes[2].?));
// A command pane is a REPL while its command runs: done, it is none,
// and a done one cannot be bound. A document pane is no terminal.
@@ -3313,13 +3304,13 @@ test "Term+fish, one word a tag can hold, opens a terminal on that shell" {
const caller = p.panes[0].?;
try std.testing.expect(p.executeBuiltinLine(0, "Term /nonexistent"));
try std.testing.expect(p.view().active == before and caller.shell == null);
- try std.testing.expect(std.mem.indexOf(u8, caller.msg[0..caller.msg_len], "shell \"/nonexistent\" not found") != null);
+ try std.testing.expect(std.mem.indexOf(u8, p.messages.saidBy(caller), "shell \"/nonexistent\" not found") != null);
try std.testing.expect(p.executeBuiltinLine(0, "Term fsh-not-a-shell"));
try std.testing.expect(caller.shell == null);
// A directory passes access(X_OK); it is no shell either.
try std.testing.expect(p.executeBuiltinLine(0, "Term /etc"));
try std.testing.expect(p.view().active == before);
- try std.testing.expect(std.mem.indexOf(u8, caller.msg[0..caller.msg_len], "Term: not a shell: /etc is a directory") != null);
+ try std.testing.expect(std.mem.indexOf(u8, p.messages.saidBy(caller), "Term: not a shell: /etc is a directory") != null);
// Only a word that says so splits at `+`: `Dump+x.zon` is no Dump.
try std.testing.expect(!p.executeBuiltinLine(0, "Dump+x.zon"));
try std.testing.expect(!p.executeBuiltinLine(0, "Msg+hello"));
@@ -3679,7 +3670,7 @@ test "Tab N draws every pane's tab N cells wide and clicks count past it; bare T
try std.testing.expectEqual(@as(i32, 1), pane.body.cur_col);
// Bare, it says the width.
try std.testing.expect(p.executeBuiltinLine(0, "Tab"));
- try std.testing.expectEqualStrings("Tab 8", pane.msg[0..pane.msg_len]);
+ try std.testing.expectEqualStrings("Tab 8", p.messages.saidBy(pane));
// Out of range: refused, the width kept.
try std.testing.expect(p.executeBuiltinLine(0, "Tab 0"));
try std.testing.expectEqual(@as(u16, 8), p.settings.tab);
@@ -4109,7 +4100,7 @@ test "bytes for a terminal past what may wait for it are dropped and said, never
p.emitWrite(0, big);
try std.testing.expectEqual(@as(usize, 0), p.pending_write_bytes);
const pane = p.panes[0].?;
- try std.testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "dropped") != null);
+ try std.testing.expect(std.mem.indexOf(u8, p.messages.saidBy(pane), "dropped") != null);
}
test "a bracketed paste larger than the ring still closes its bracket" {