diff options
Diffstat (limited to 'core/panes.zig')
| -rw-r--r-- | core/panes.zig | 98 |
1 files changed, 10 insertions, 88 deletions
diff --git a/core/panes.zig b/core/panes.zig index 8939bd05..146b1360 100644 --- a/core/panes.zig +++ b/core/panes.zig @@ -32,7 +32,7 @@ pub const Pane = struct { pub const replica = .{ .local = .{ "pv", "pv_known" }, .derived = .{ "wrap_line", "wrap_col", "wrap_pad", "wrap_n", "body_wrapped", "context_rows", "body_rows", "body_visible_rows", "context_row_limit", "geometry_key", "geometry_len", "top_skip", "notices", "pan" }, - .len = .{ .{ "msg", "msg_len" }, .{ "msg_older", "msg_older_len" }, .{ "question", "question_len" }, .{ "shell_tail", "shell_tail_len" }, .{ "sel_snap", "nsel_snap" } }, + .len = .{ .{ "question", "question_len" }, .{ "shell_tail", "shell_tail_len" }, .{ "sel_snap", "nsel_snap" } }, // A picture's memory is its own allocator's (a dump loaded makes // it there). .alloc = .{ .{ "addon", "image" }, .{ "pdf", "image" }, .{ "terminal", "terminal" } }, @@ -242,8 +242,6 @@ pub const Pane = struct { /// A question with its answers in it (`repl_choice`). question: [96]u8 = undefined, question_len: u8 = 0, - /// The newest message says where an exec was sent: it is tinted. - msg_sent: bool = false, /// The revision an Exit or a Restore last warned this pane was modified /// at, and which of them: only that word goes ahead on the warning /// (builtins.zig warnModified). @@ -347,27 +345,9 @@ pub const Pane = struct { /// terminals only: the typed-text buffer standing in for shell rows ovl: ?Text.EditBuffer = null, tty_filter: bool = false, - msg: [256]u8 = undefined, - msg_len: u16 = 0, - /// Where the newest message line is in its life. - msg_life: MessageLife = .{}, - /// When it was said, in monotonic ms (Messages.expireUnattended). - msg_said_ms: i64 = 0, - /// The row (among the notice rows) the newest line holds for its life. - msg_slot: u8 = 0, - /// Earlier message lines still on screen, oldest first, each running its - /// own life: a new message stacks under them instead of replacing them. - msg_older: [message_stack]OlderMessage = undefined, - msg_older_len: u8 = 0, - /// The newest line is a builtin announcing itself in this step: what - /// the step says next replaces it rather than stacking under it. - msg_announcement: bool = false, - /// The newest line is a status (progress, a server's state): the next - /// line replaces it rather than stacking under it. - msg_status: bool = false, /// The transient lines this pane shows between its body and its tagline: - /// a builtin's message, the pending leader chord, a prompt waiting for - /// input. Rebuilt every frame from the state that owns each one, so a + /// the newest message said of it, the pending leader chord, a prompt + /// waiting for input. Rebuilt every frame from the state that owns each one, so a /// line that goes away is simply not added again and the rest close the /// gap -- there is no second copy of the truth to fall out of step. The /// body layer reserves exactly `len` rows for them, the way it already @@ -398,67 +378,14 @@ pub const Pane = struct { /// that view's focus leaving the pane drops it. prompt_view: u8 = 0, - pub const MessagePhase = enum { shown, lingering }; - /// One message line's life: shown, or lingering after the key or click - /// that dismissed it, `frame` frames of its linger gone. - pub const MessageLife = struct { - phase: MessagePhase = .shown, - frame: u16 = 0, - }; - /// Older message lines kept on screen under a new one. - pub const message_stack = 3; - pub const OlderMessage = struct { - pub const replica = .{ .len = .{.{ "text", "len" }} }; - text: [256]u8 = undefined, - len: u16 = 0, - life: MessageLife = .{}, - slot: u8 = 0, - - pub fn slice(line: *const OlderMessage) []const u8 { - return line.text[0..line.len]; - } - }; - - /// Move the newest line onto the stack of older ones, dropping the oldest - /// when it is full; the newest slot is left empty for what arrives. - pub fn pushOlderMessage(pane: *Pane) void { - if (pane.msg_older_len == message_stack) { - std.mem.copyForwards(OlderMessage, pane.msg_older[0 .. message_stack - 1], pane.msg_older[1..]); - pane.msg_older_len -= 1; - } - pane.msg_older[pane.msg_older_len] = .{ .text = pane.msg, .len = pane.msg_len, .life = pane.msg_life, .slot = pane.msg_slot }; - pane.msg_older_len += 1; - pane.msg_len = 0; - pane.msg_life = .{}; - } - - /// The first row no older line holds. A line keeps its row until it - /// leaves, and a new one fills the first gap: nothing on screen moves. - pub fn freeMessageSlot(pane: *const Pane) u8 { - var used: u8 = 0; - for (pane.msg_older[0..pane.msg_older_len]) |line| used |= @as(u8, 1) << @intCast(line.slot); - var slot: u8 = 0; - while (used & (@as(u8, 1) << @intCast(slot)) != 0) slot += 1; - return slot; - } - - pub fn removeOlderMessage(pane: *Pane, i: usize) void { - std.mem.copyForwards(OlderMessage, pane.msg_older[i .. pane.msg_older_len - 1], pane.msg_older[i + 1 .. pane.msg_older_len]); - pane.msg_older_len -= 1; - } - pub const Notices = struct { /// Painted bottom-up in this order, so a prompt keeps the row nearest /// the tagline that it has always had, and its cursor with it. - /// `older` is an earlier message line still on screen; `index` says - /// which (`Pane.msg_older`). - pub const Kind = enum { older, message, leader, prompt }; - pub const max = @typeInfo(Kind).@"enum".field_names.len - 1 + message_stack; + pub const Kind = enum { message, leader, prompt }; + pub const max = @typeInfo(Kind).@"enum".field_names.len; kinds: [max]Kind = undefined, - index: [max]u8 = @splat(0), - /// Each band's row below the body's top: message lines keep theirs, - /// so a band that leaves leaves a gap rather than moving the rest. + /// Each band's row below the body's top. row: [max]u8 = @splat(0), /// Where each band's chip starts, as an absolute grid column. A chip /// is only as wide as its own text, so the rest of the row underneath @@ -468,14 +395,9 @@ pub const Pane = struct { /// A band on the next row after every band so far. pub fn push(n: *Notices, kind: Kind) void { - n.pushAt(kind, 0, n.span()); - } - - pub fn pushAt(n: *Notices, kind: Kind, index: u8, row: u8) void { if (n.len >= max) return; n.kinds[n.len] = kind; - n.index[n.len] = index; - n.row[n.len] = row; + n.row[n.len] = n.span(); n.left[n.len] = std.math.maxInt(u16); n.len += 1; } @@ -1669,14 +1591,14 @@ test "owned cwd preserves long paths aliases and failed updates" { const effects = p.effects_len; exec.saveTo(p, 0, "file.txt"); try std.testing.expectEqual(effects, p.effects_len); - try std.testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "path too long") != null); + try std.testing.expect(std.mem.indexOf(u8, p.messages.saidBy(pane), "path too long") != null); const current = pane.cwdSlice(); allocator.fail_index = allocator.alloc_index; p.setCwd(.at(0), "/replacement"); try std.testing.expectEqual(current.ptr, pane.cwdSlice().ptr); try std.testing.expectEqualStrings(&path, pane.cwdSlice()); - try std.testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "out of memory") != null); + try std.testing.expect(std.mem.indexOf(u8, p.messages.saidBy(pane), "out of memory") != null); allocator.fail_index = std.math.maxInt(usize); p.setCwd(.at(0), "/replacement"); try std.testing.expectEqualStrings("/replacement", pane.cwdSlice()); @@ -1781,7 +1703,7 @@ test "owned cwd EOF failure retains the pane and Del retries its close" { try std.testing.expectEqual(parent, p.panes[0].?); try std.testing.expectEqual(parent, child.cwd.inherited); try std.testing.expectEqual(Text.Mode.normal, parent.body.mode); - try std.testing.expect(std.mem.indexOf(u8, parent.msg[0..parent.msg_len], "Del retries close") != null); + try std.testing.expect(std.mem.indexOf(u8, p.messages.saidBy(parent), "Del retries close") != null); try std.testing.expectEqual(@as(usize, 0), p.effects_len); allocator.fail_index = std.math.maxInt(usize); try std.testing.expect(p.executeBuiltinLine(0, "Del")); |
