diff options
Diffstat (limited to 'core/panes.zig')
| -rw-r--r-- | core/panes.zig | 183 |
1 files changed, 86 insertions, 97 deletions
diff --git a/core/panes.zig b/core/panes.zig index 6fd5c679..e4ed3e9d 100644 --- a/core/panes.zig +++ b/core/panes.zig @@ -32,8 +32,8 @@ pub const Pane = struct { /// it (views.zig). (The 9P server's part of `fs` says so in its type.) 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" } }, + .derived = .{ "band_rows", "ghost_at", "ghost_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 = .{ .{ "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). @@ -273,6 +271,10 @@ pub const Pane = struct { /// Its walk: the places it stepped through, its owner when it is a /// reader, whether it is held (Trail.zig, pick-ui SPEC §6). trail: Trail = .{}, + /// The selections its recipe word's sam prompts made (gpa), for Look + /// on the word to put back (Prompt.zig, SPEC §7.5). + recipe_sels: []modal.Selection = &.{}, + recipe_pri: u16 = 0, /// `gw`'s words, labelled in order while it waits for a label to be /// typed (gpa-owned); `jump_first` is the label's first letter once typed. jump: std.ArrayList(modal.Selection) = .empty, @@ -353,32 +355,19 @@ 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 + /// 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 /// reserves rows for sticky context headers. notices: Notices = .{}, + /// A message's detail as the body drawn last has it (body_layer.zig + /// messageGhosts): `ghost_rows` read-only rows after body row + /// `ghost_at` (its line's last), the rows below drawn that many lower. + /// The mouse reads it, so that a click lands on what is drawn under it. + ghost_at: u16 = 0, + ghost_rows: u16 = 0, /// Each other view's share of this pane, while it is not live /// (views.zig): its cursor, scroll and place in that view's layout. pv: [views.max]views.PaneView = undefined, @@ -404,67 +393,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 { 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 +410,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; } @@ -633,6 +564,14 @@ pub const Pane = struct { return @min(pane.scrolled_to orelse output, output); } + /// Body row `vr` as drawn, as the row map counts it (`wrapAt`): a row + /// under a message's detail is `ghost_rows` higher there; a row of the + /// detail is the line's it explains. + pub fn textRow(pane: *const Pane, vr: i32) i32 { + if (pane.ghost_rows == 0 or vr <= pane.ghost_at) return vr; + return @max(pane.ghost_at, vr - pane.ghost_rows); + } + /// The line and byte a body row shows from. pub fn wrapAt(pane: *Pane, tab: u16, vr: i32) struct { line: i32, at: i32, pad: i32 = 0 } { File.geometry(tab, pane); @@ -1127,6 +1066,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; + }; } }; @@ -1297,6 +1253,7 @@ pub fn teardownPane(p: *Pardes, pane: *Pane) void { pane.input.deinit(p.gpa); pane.jump.deinit(p.gpa); pane.places.deinit(p.gpa); + p.gpa.free(pane.recipe_sels); @import("jj.zig").forget(p, pane.serial); if (pane.query) |q| { q.deinit(p.gpa); @@ -1679,14 +1636,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 +1748,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")); @@ -1954,7 +1911,7 @@ test "a prompt chip is a band with its caret, still on the grid, and only the ch for (pane.sel) |selection| try std.testing.expect(selection.state == .none); } -test "a prompt is typed on its own line in the notice band and leaves the tag row alone" { +test "a Save prompt is typed on its own line in the notice band and leaves the tag row alone" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 }); defer p.deinit(); const pane = try p.setTestFile("one two\n"); @@ -1964,13 +1921,13 @@ test "a prompt is typed on its own line in the notice band and leaves the tag ro const tag_before = try std.testing.allocator.dupe(Cell, p.surface.tag_layers[0].cells); defer std.testing.allocator.free(tag_before); - // `s` keeps a prompt on the band (a text's `/` is its query pane's - // line 1 now, Query.zig). - p.update(.{ .key = .{ .cp = 's' } }); + // Save's path keeps a prompt on the band (a body's `s`, `|` and `/` + // ask in its tag, Prompt.zig). + startPrompt(p, pane, &pane.body, .save); p.update(.{ .key = .{ .cp = 't', .text = "tw" } }); p.update(.{ .key = .{ .cp = Key.left } }); - try std.testing.expect(pane.prompt == .search and pane.focus == .body); - try std.testing.expectEqualStrings(config.select_marker ++ "tw", pane.promptText().?); + try std.testing.expect(pane.prompt == .save and pane.focus == .body); + try std.testing.expectEqualStrings(config.save_marker ++ "/tw", pane.promptText().?); _ = frame.reset(.retain_capacity); _ = try p.render(frame.allocator()); // The tagline is exactly what it was: nothing of the prompt is in it. @@ -1987,7 +1944,39 @@ test "a prompt is typed on its own line in the notice band and leaves the tag ro const grid = p.surface.cursor orelse return error.MissingPromptCursor; try std.testing.expectEqual(p.bodyTop(pane, p.view().rects[0]), grid.y); - // Submitting searches for what was typed and gives the prompt its line back. - p.update(.{ .key = .{ .cp = Key.enter } }); + // Esc gives the prompt its line back. + p.update(.{ .key = .{ .cp = Key.escape } }); 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"); +} |
