diff options
Diffstat (limited to 'core/panes.zig')
| -rw-r--r-- | core/panes.zig | 146 |
1 files changed, 58 insertions, 88 deletions
diff --git a/core/panes.zig b/core/panes.zig index 6fd5c679..47765d90 100644 --- a/core/panes.zig +++ b/core/panes.zig @@ -33,7 +33,7 @@ pub const Pane = struct { pub const replica = .{ .local = .{ "pv", "pv_known" }, .derived = .{ "band_rows", "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" } }, @@ -243,8 +243,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). @@ -353,27 +351,8 @@ 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 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 @@ -404,67 +383,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 { 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 @@ -474,14 +400,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; } @@ -1127,6 +1048,23 @@ pub const Pane = struct { pane.feedOutput(p, said.print("{s}exit {s}\r\n", .{ lead, code })); pane.noteRun(p, "exit", code); p.needs_frame = true; + // A failed run whose report names places (a compiler's + // `path:line:col: error: ...`): an error of this pane, the places + // its words, the rows after its first its detail (SPEC ยง10.2). Its + // last rows only: a report's places are at its end. + if (status != 0) if (pane.terminal) |state| report: { + const grid = Term.grid(state); + const first = grid.total -| 400; + const rows = Term.editRows(state, p.scratch.allocator(), first, grid.total - first) catch break :report; + var found: pardes.Messages.Said = .{}; + if (pardes.Messages.readPlaces(&found, pane.cwdSlice(), rows) == 0) break :report; + var words: pardes.Kind.Buf(32) = .{}; + const kept = pardes.Messages.say(p, .@"error", id, words.print("exit {s}", .{code})); + kept.places = found.places; + kept.places_len = found.places_len; + kept.detail = found.detail; + kept.detail_len = found.detail_len; + }; } }; @@ -1679,14 +1617,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()); @@ -1791,7 +1729,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")); @@ -1991,3 +1929,35 @@ test "a prompt is typed on its own line in the notice band and leaves the tag ro p.update(.{ .key = .{ .cp = Key.enter } }); try std.testing.expect(pane.prompt == .none and pane.input.own == null); } + +test "a command whose run fails naming places is an error of its pane, those places its words, and the pane's next run takes it away" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a command pane's terminal + const gpa = std.testing.allocator; + const p = try Pardes.init(gpa, .{}); + defer p.deinit(); + while (p.nextEffect()) |_| {} + p.setCwd(.at(0), "/tmp/pardes-cmd"); + _ = try pardes.Kind.open(p, 1, pardes.Kind.test_kind.of(p), "/tmp/pardes-cmd/pic.ppm", null); + const dst = exec.execute(p, 1, "zig build") orelse return error.NoCommandPane; + while (p.nextEffect()) |_| {} + const pane = p.panes[dst].?; + p.update(.{ .output = .{ .pane = .at(dst), .bytes = "core/pick.zig:25:12: error: expected 2 argument(s), found 3\r\n const best = rank(q, name, 3);\r\n" } }); + p.update(.{ .exited = .{ .pane = .at(dst), .status = 1 } }); + const said = p.messages.headline() orelse return error.NothingSaid; + try std.testing.expectEqual(pardes.Messages.Kind.@"error", said.kind); + try std.testing.expectEqualStrings("exit 1", said.text.slice()); + try std.testing.expect(std.mem.endsWith(u8, said.src.slice(), " zig build")); + try std.testing.expectEqual(@as(u8, 1), said.places_len); + try std.testing.expectEqualStrings("/tmp/pardes-cmd/core/pick.zig", said.places[0].path.slice()); + try std.testing.expectEqualStrings(" const best = rank(q, name, 3);", said.detail[0].slice()); + var frame = std.heap.ArenaAllocator.init(gpa); + defer frame.deinit(); + const s = try p.render(frame.allocator()); + const r = p.view().rects[dst]; + try std.testing.expectEqualStrings("\u{2717}", s.at(r.x + config.GUTTER - 1, p.tagTop(pane, r)).grapheme()); + // Its next run: the last run's error goes. + p.update(.{ .eof = .{ .pane = .at(dst) } }); + try std.testing.expectEqual(@as(?usize, dst), exec.execute(p, 1, "zig build")); + while (p.nextEffect()) |_| {} + try std.testing.expect(p.messages.headline() == null or p.messages.headline().?.kind != .@"error"); +} |
