diff options
Diffstat (limited to 'core/Core.zig')
| -rw-r--r-- | core/Core.zig | 96 |
1 files changed, 45 insertions, 51 deletions
diff --git a/core/Core.zig b/core/Core.zig index 6ee82370..296f4159 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -177,6 +177,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, @@ -353,8 +357,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). @@ -1583,11 +1587,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(); @@ -1715,11 +1714,6 @@ fn updateInner(p: *Pardes, ev: Event) void { // 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 +1728,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 => {}, @@ -1910,10 +1898,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); @@ -2033,6 +2021,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 +2037,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. @@ -2177,10 +2174,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 +2243,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; } @@ -2641,35 +2638,33 @@ 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; + // 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()); - // 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); + // ...and the leader's chip (a shown level's last leaf) is an overlay + // at the body's top (the level itself wraps the tag: TagState). const r = p.view().rects[0]; + p.view().prefix = .leader; + p.view().leader_n = 0; + p.view().tag_state.used[0] = 'q'; + p.view().tag_state.due_ns = 1; + p.clock.now_ns = 1; + p.sync(); + _ = try p.render(p.scratch.allocator()); 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; - 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; } @@ -3052,7 +3047,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 +3061,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 +3184,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 +3201,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 +3211,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 +3290,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 +3656,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 +4086,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" { |
