diff options
Diffstat (limited to 'core/Core.zig')
| -rw-r--r-- | core/Core.zig | 140 |
1 files changed, 74 insertions, 66 deletions
diff --git a/core/Core.zig b/core/Core.zig index 6ee82370..2c04cc64 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -153,7 +153,13 @@ pub const View = struct { /// Whether the host window has the keyboard (Event.focus), and the pane /// whose program was last told it has it (reportFocus). window_focused: bool = true, - focus_told: ?struct { id: usize, serial: u32 } = null, + focus_told: ?struct { + // A slot of the session's, looked at before it is used, as + // `active` is (a damaged image's indexed past the panes). + pub const replica = .{ .index = .{.{ "id", Pardes, "panes" }} }; + id: usize, + serial: u32, + } = null, hover_col: u16 = 0, hover_row: u16 = 0, pointer_raw_col: u16 = 0, @@ -177,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, @@ -337,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) = .{}, @@ -353,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). @@ -440,6 +455,9 @@ in_head: usize = 0, in_len: usize = 0, registers: Registers = .{}, +/// The text prompts' histories (Prompt.zig): search and select's, the +/// pipes', the command line's. +prompt_history: pardes.Prompt.History = .{}, macro: Macro = .{}, /// an edited text nothing kept (a tag's shown text): see edit.retireEditText retired_edit: ?[]u8 = null, @@ -525,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 @@ -1033,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"); @@ -1394,7 +1413,8 @@ fn refillPendingWrites(p: *Pardes) void { /// may be handed to a different pane next frame. pub fn dropPendingWrite(p: *Pardes, id: usize) void { const pw = p.pending_write[id] orelse return; - p.pending_write_bytes -= pw.bytes.len - pw.off; + // (Saturating: a damaged image's total may say less than its parts.) + p.pending_write_bytes -|= pw.bytes.len - pw.off; p.gpa.free(pw.bytes); p.pending_write[id] = null; } @@ -1583,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(); @@ -1708,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) { @@ -1734,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 => {}, @@ -1826,6 +1830,8 @@ fn updateInner(p: *Pardes, ev: Event) void { // Each pane's places find a frame's more on a tick, and on any other // step the ones an edit or a scroll left unfound in the view. for (p.panes) |slot| if (slot) |pane| pane.places.settle(p, pane, ev == .tick); + // Their search words and a search prompt with them (Prompt.zig). + 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); @@ -1910,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); @@ -1924,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; @@ -2033,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) { @@ -2040,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. @@ -2080,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 @@ -2130,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; } @@ -2177,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) { @@ -2245,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; } @@ -2297,7 +2314,17 @@ pub fn appendPlacement(p: *Pardes, place: Placement) bool { return true; } -pub const PendingWrite = struct { bytes: []u8, off: usize = 0 }; +pub const PendingWrite = struct { + /// What is written held to the bytes (walk.zig `.place`): a damaged + /// image's past them freed a count below zero. + pub const replica = .{ .place = .{.{ "off", "lastOff" }} }; + bytes: []u8, + off: usize = 0, + + pub fn lastOff(pw: *const PendingWrite) usize { + return pw.bytes.len; + } +}; /// The session layouts `init` can put on screen. One name each, so choosing /// between them reads as a choice instead of a chain of ifs over four options. @@ -2641,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" { @@ -3052,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")); @@ -3066,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. { @@ -3190,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].?)); @@ -3207,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; @@ -3217,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. @@ -3296,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")); @@ -3662,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); @@ -4092,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" { |
