diff options
Diffstat (limited to 'core/draw.zig')
| -rw-r--r-- | core/draw.zig | 185 |
1 files changed, 144 insertions, 41 deletions
diff --git a/core/draw.zig b/core/draw.zig index 5282b1c9..dbbb6148 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -95,7 +95,7 @@ pub fn place(p: *Pardes, s: *Surface) void { for (&p.panes, 0..) |*slot, id| { const pane = slot.* orelse continue; paneFacts(p, &p.facts, id, pane); - Messages.collectNotices(p, pane, v.rects[id], id); + Messages.collectNotices(p, pane, v.rects[id]); const r = v.rects[id]; if (r.w <= config.GUTTER or r.h == 0) continue; const owner: u8 = @intCast(id); @@ -161,10 +161,12 @@ pub fn place(p: *Pardes, s: *Surface) void { const active_col = if (layout.findPane(p, v.active)) |found| found.col else null; for (0..p.view().ncol) |c| { if (v.col_w[c] == 0) continue; - s.addRegion(.{ .kind = .column, .owner = @intCast(c), .serial = v.cols[c].serial, .active = active_col == c, .rect = .{ .x = v.col_x[c], .y = p.topBarHeight(), .w = v.col_w[c], .h = s.rows -| p.topBarHeight() } }); + s.addRegion(.{ .kind = .column, .owner = @intCast(c), .serial = v.cols[c].serial, .active = active_col == c, .rect = .{ .x = v.col_x[c], .y = p.topBarHeight(), .w = v.col_w[c], .h = s.rows -| (p.topBarHeight() + layout.noticeRowHeight(p)) } }); } if (p.settings.workspace_tag) s.addRegion(.{ .kind = .workspace_tag, .rect = .{ .x = 0, .y = 0, .w = s.cols, .h = p.topBarHeight() } }); + const foot = layout.noticeRowHeight(p); + if (foot > 0) s.addRegion(.{ .kind = .notice_row, .rect = .{ .x = 0, .y = s.rows - foot, .w = s.cols, .h = foot } }); } /// A pane's grip in the grid: `box` focused, else halfway between its ring @@ -228,12 +230,9 @@ fn joinNotice(p: *Pardes, s: *Surface, arena: std.mem.Allocator, region: Region) const kind = pane.notices.kinds[i]; const r = v.rects[id]; const chip = region.rect.w; - var leader_buf: [Messages.leader_room]u8 = undefined; - const text = Messages.noticeText(p, pane, i, &leader_buf); + const text = Messages.noticeText(pane, i); const bg = chrome.tag_bg; - // Where an exec was sent to a REPL reads in the tag's name tint, set - // apart from what the editor says. - const fg = if (kind == .message and pane.msg_sent) chrome.tag_name_fg else chrome.tag_fg; + const fg = chrome.tag_fg; // Nothing to say, or too narrow for a layer: a blank chip on the grid. if (text.len == 0 or r.w <= TAG_TEXT_INSET) { s.fill(region.rect.x, region.rect.y, chip, 1, .{ .bg = .{ .rgb = bg }, .font_role = .tagline }); @@ -349,7 +348,7 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface { // Separators have their own role; a scrollbar need not frame the page. const whole = s.regions[0].rect; s.fill(whole.x, whole.y, whole.w, whole.h, .{ .bg = .{ .rgb = chrome.border } }); - for (0..p.view().ncol) |c| if (v.cols[c].n == 0) s.fill(v.col_x[c], p.topBarHeight() + layout.columnBarHeight(p), v.col_w[c], s.rows -| (p.topBarHeight() + layout.columnBarHeight(p)), .{ .bg = .{ .rgb = chrome.empty_col } }); + for (0..p.view().ncol) |c| if (v.cols[c].n == 0) s.fill(v.col_x[c], p.topBarHeight() + layout.columnBarHeight(p), v.col_w[c], s.rows -| (p.topBarHeight() + layout.columnBarHeight(p) + layout.noticeRowHeight(p)), .{ .bg = .{ .rgb = chrome.empty_col } }); for (&p.panes, 0..) |*slot, id| { const pane = slot.* orelse continue; @@ -374,6 +373,7 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface { }; try paintHeaders(p, s); + try paintNoticeRow(p, s); // debug overlay: a small stats box drawn last, top-right ("Debug") if (p.settings.debug) if (p.panes[v.active]) |at| { @@ -482,6 +482,12 @@ fn renderPane(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: s.fill(r.x, tag_y, config.GUTTER, @min(1, pane.tag_rows), box_style); if (dirty and pane.tag_rows > 0 and config.GUTTER > 1) s.set(r.x + config.GUTTER - 1, tag_y, "*", .{ .fg = .{ .rgb = inkOn(boxDirty(p)) }, .bg = .{ .rgb = boxDirty(p) }, .bold = true, .font_role = .tagline }); + // The mark (pick-ui SPEC §2): the status of the most important live + // message about the pane, in the box's second cell, on the dirty ground + // when there is unsaved text: a cell of the box's, never the tag's + // text, so it moves nothing. + if (pane.tag_rows > 0 and config.GUTTER > 1) if (p.messages.markOf(pane)) |kind| + s.set(r.x + config.GUTTER - 1, tag_y, kind.glyph(), .{ .fg = .{ .rgb = Messages.ink(chrome, kind) }, .bg = .{ .rgb = if (dirty) boxDirty(p) else box_bg }, .bold = true, .font_role = .tagline }); s.fill(r.x, tag_y + 1, config.GUTTER, pane.tag_rows -| 1, .{ .bg = .{ .rgb = band }, .font_role = .tagline, @@ -569,6 +575,19 @@ fn paintHeaders(p: *Pardes, s: *Surface) !void { viewport.x += inset; viewport.w -= inset; try renderHeaderLayer(p, layer, .workspace, 0, viewport, tagline.topbar(p), top, chrome.tagline_bg, chrome.tagline_fg); + // A server's progress (a message of no pane) at its first row's + // right end, where the row has room for it. + if (layer.rows > 0 and top == 0) for (p.messages.live[0..p.messages.live_len]) |*said| { + if (said.kind != .progress or said.pane != 0) continue; + var buf: [Messages.LoggedMessage.cap + 8]u8 = undefined; + const text = std.fmt.bufPrint(&buf, "{s} {s}", .{ Messages.Kind.progress.glyph(), said.words() }) catch break; + const width = panes.File.displayWidth(p.settings.tab, text); + const used = panes.File.displayWidth(p.settings.tab, modal.lineSlice(tagline.topbar(p), 0)); + const room = layout.tagCapacity(p, viewport.w); + var row: Surface = .{ .cols = layer.cols, .rows = 1, .cells = layer.cells[0..layer.cols], .tab = p.settings.tab }; + if (used + 2 + width < room) _ = row.print(@intCast(room - 1 - width), 0, @intCast(width), text, .{ .fg = .{ .rgb = Messages.ink(chrome, .progress) }, .bg = .{ .rgb = chrome.tagline_bg }, .font_role = .tagline }); + break; + }; joinHeaderRows(s, layer, chrome.tagline_fg); } const column_rows = layout.columnBarHeight(p); @@ -597,6 +616,43 @@ fn paintHeaders(p: *Pardes, s: *Surface) !void { }; } +/// The notice row (Messages.noticeRow), the live messages' index at the +/// window's foot: a header layer at the tagline's pitch in the workspace +/// tag's colours, the glyph in its kind's, a message gone dim and the +/// counts at the right end dimmed. +fn paintNoticeRow(p: *Pardes, s: *Surface) !void { + const region = s.region(.notice_row, Region.none) orelse return; + const chrome = p.chromeTheme(); + var viewport = region.rect; + const inset = @min(TAG_TEXT_INSET, viewport.w); + s.fill(viewport.x, viewport.y, inset, viewport.h, .{ .bg = .{ .rgb = chrome.tagline_bg }, .font_role = .tagline }); + viewport.x += inset; + viewport.w -= inset; + var buf: [Messages.notice_row_cap]u8 = undefined; + const row = Messages.noticeRow(p, layout.tagCapacity(p, viewport.w) -| 1, &buf); + const layer = &s.tag_layers[pardes.NOTICE_ROW_LAYER]; + try renderHeaderLayer(p, layer, .notice_row, 0, viewport, row.text, 0, chrome.tagline_bg, chrome.tagline_fg); + if (layer.rows == 0) return; + const dim: Color = .{ .rgb = colors.mix(chrome.tagline_fg, chrome.tagline_bg) }; + const ink: Color = .{ .rgb = chrome.tagline_fg }; + const cells = layer.cells[0..layer.cols]; + const tab = p.settings.tab; + const left = @min(cells.len, panes.File.displayWidth(tab, row.text[0..row.left])); + const right = @min(cells.len, panes.File.displayWidth(tab, row.text[0..row.right])); + if (row.lead) |lead| { + if (lead.kind == .@"error" or lead.kind == .warn) if (cells.len > 0 and std.meta.eql(cells[0].style.fg, ink)) { + cells[0].style.fg = .{ .rgb = if (lead.kind == .@"error") chrome.diagnostic_error else chrome.diagnostic_warning }; + }; + if (lead.faded(p.clock.now_ns, p.settings.message_linger_ms)) for (cells[0..left]) |*cell| { + if (std.meta.eql(cell.style.fg, ink)) cell.style.fg = dim; + }; + } + for (cells[right..]) |*cell| if (std.meta.eql(cell.style.fg, ink)) { + cell.style.fg = dim; + }; + joinHeaderRows(s, layer, chrome.tagline_fg); +} + /// Copy a header's layer into the grid under it, row by row, and its caret. fn joinHeaderRows(s: *Surface, layer: *const pardes.Layer, fg: [3]u8) void { const v = layer.viewport; @@ -631,7 +687,7 @@ fn joinCells(s: *Surface, x: u16, y: u16, cells: []const Cell, from: usize, w: u if (!cells[from].default and cells[from].len == 0) blank(&row[x], ink); } -fn tagTintRange(pane: *const Pane, tag: []const u8, prefix_len: usize) ?struct { lo: usize, hi: usize } { +fn tagTintRange(p: *const Pardes, pane: *const Pane, tag: []const u8, prefix_len: usize) ?struct { lo: usize, hi: usize } { if (pane.isTerminal()) { // `tag` is the first row; a prefix longer than it ran to a second. var words = std.mem.tokenizeAny(u8, tag[@min(prefix_len, tag.len)..], " \t\r\n"); @@ -642,7 +698,7 @@ fn tagTintRange(pane: *const Pane, tag: []const u8, prefix_len: usize) ?struct { } return null; } - var start: usize = tagline.nameAt(pane); + var start: usize = tagline.nameAt(p, pane); const name = if (pane.file) |file| if (pane.prompt == .name) pane.input.own orelse file.path else file.path else if (pane.addon) |k| blk: { @@ -689,7 +745,7 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v const editing: ?*Text = if (v.header != null and switch (kind) { .workspace => p.headerColumn() == null, .column => p.headerColumn() == id, - .pane, .notice, .body, .band => false, + .pane, .notice, .body, .band, .notice_row => false, }) tagline.focusedHeader(p) else null; const scroll = if (editing != null) v.header_scroll else 0; for (0..viewport.h) |index| { @@ -741,7 +797,7 @@ fn renderHeaderLayer(p: *Pardes, layer: *pardes.Layer, kind: TagKind, id: u16, v const mine = switch (kind) { .workspace => column == null, .column => column == id, - .pane, .notice, .body, .band => false, + .pane, .notice, .body, .band, .notice_row => false, }; const swept = sweep.span(text.len); const start = modal.lineStartOffset(text, index + top); @@ -822,7 +878,7 @@ fn joinPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r /// grid: the spines and steps in the tag's tint, the keys in the key ink, /// the cursor's row tinted as a selection. fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: Rect, id: usize, active: bool) !void { - const layer = &s.tag_layers[pardes.BAND_LAYER_BASE + id]; + const layer = &s.tag_layers[pardes.BAND_LAYER]; if (r.w <= TAG_TEXT_INSET) return; const band = (try pardes.Band.of(p, arena, pane, id)) orelse return; const th = p.theme(); @@ -955,7 +1011,7 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, else if (pane.prompt == .name) caret: { // A drafted name is the prefix: its caret is on row 0 of the tag, // the rows it wrapped onto included. - const at = modal.positionAt(shown.text, shown.fromReal(tagline.nameAt(pane) + @as(usize, @intCast(@max(0, pane.input.cur_col))))); + const at = modal.positionAt(shown.text, shown.fromReal(tagline.nameAt(p, pane) + @as(usize, @intCast(@max(0, pane.input.cur_col))))); if (at.row < top or at.row >= top + rows) break :caret null; break :caret .{ .row = at.row - top, .at = @min(lines[at.row - top].len, at.col) }; } else if (pane.focus == .tag and pane.prompt == .none and head == null) caret: { @@ -972,14 +1028,27 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, const start = @min(line.len, panes.File.rawAtDisplay(p.settings.tab, line, pane.tag_scroll)); _ = s.print(tx, tag_y + @as(u16, @intCast(row)), tw, line[start..], tag_style); } + // The pane's progress at its first row's right end, where the row has + // room for it (SPEC §10.2). + if (top == 0 and rows > 0) for (p.messages.live[0..p.messages.live_len]) |*said| { + if (said.kind != .progress or said.pane != pane.serial) continue; + var buf: [Messages.LoggedMessage.cap + 8]u8 = undefined; + const text = std.fmt.bufPrint(&buf, "{s} {s}", .{ Messages.Kind.progress.glyph(), said.words() }) catch break; + const width = panes.File.displayWidth(p.settings.tab, text); + const used = panes.File.displayWidth(p.settings.tab, lines[0]); + if (used + 2 + width <= tw) _ = s.print(tx + @as(u16, @intCast(tw - width)), tag_y, @intCast(width), text, .{ .fg = .{ .rgb = Messages.ink(chrome, .progress) }, .bg = .{ .rgb = tag_bg }, .font_role = .tagline }); + break; + }; // The name's tint, in the tag's first line, over whichever rows it // wrapped onto. const first_line = whole[0 .. std.mem.indexOfScalar(u8, whole, '\n') orelse whole.len]; - if (tagTintRange(pane, first_line, prefix_len)) |name| if (name.lo < name.hi) + if (tagTintRange(p, pane, first_line, prefix_len)) |name| if (name.lo < name.hi) inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, name.lo, @min(name.hi, first_line.len), if (active) chrome.tag_active_name_fg else chrome.tag_name_fg); // A walk's forward steps, after the name, dimmed (Trail.zig). - const ahead = tagline.forwardSpan(pane); + const ahead = tagline.forwardSpan(p, pane); if (ahead[0] < ahead[1]) inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, ahead[0], @min(ahead[1], first_line.len), chrome.lineno); + // A search word its places no longer light, dimmed (Prompt.zig). + if (pardes.Prompt.unlit(p, pane)) |span| inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, span[0], @min(span[1], first_line.len), chrome.lineno); // The head's keys in the key ink, its dimmed, underlined and struck // words (TagState.Span), over whichever rows they wrapped onto. if (head) |h| for (h.spans) |span| { @@ -1003,6 +1072,7 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, .dim => style.dim = true, .under => style.ul = .single, .strike => style.strikethrough = true, + .err => style.fg = .{ .rgb = chrome.diagnostic_error }, } } } @@ -1281,8 +1351,8 @@ test "place puts every part where the painters and layers put it, in every layou } } -test "the word under the pointer on a notice is lit in its layer and in the grid's copy" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 41, .rows = 12 }); +test "the word under the pointer on the notice row is lit in its layer and in the grid's copy" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 61, .rows = 12 }); defer p.deinit(); _ = try p.setTestFile("text\n"); var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); @@ -1290,36 +1360,35 @@ test "the word under the pointer on a notice is lit in its layer and in the grid try std.testing.expect(p.executeBuiltinLine(p.view().active, "Msg Look here")); p.sync(); var s = try p.render(arena.allocator()); - const notice = for (s.regionList()) |region| { - if (region.kind == .notice) break region; - } else return error.TestExpectedNotice; - const row = s.cells[@as(usize, notice.rect.y) * s.cols ..][0..s.cols]; - // "here", the chip's last word, before its blank edge. - const here = notice.rect.x + notice.rect.w - 5; + const foot = s.region(.notice_row, Region.none) orelse return error.TestExpectedNoticeRow; + try std.testing.expectEqual(s.rows - 1, foot.rect.y); + const row = s.cells[@as(usize, foot.rect.y) * s.cols ..][0..s.cols]; + // "here": the message's last word, `· /test.txt Look here`, 17 + // columns in. + const here: u16 = TAG_TEXT_INSET + 17; try std.testing.expectEqualStrings("h", row[here].grapheme()); p.view().pointer_inside = true; p.view().hover_col = here + 1; - p.view().hover_row = notice.rect.y; + p.view().hover_row = foot.rect.y; _ = arena.reset(.retain_capacity); s = try p.render(arena.allocator()); - const lit = s.cells[@as(usize, notice.rect.y) * s.cols ..][0..s.cols]; - const sel: Color = .{ .rgb = p.theme().sel_bg }; + const lit = s.cells[@as(usize, foot.rect.y) * s.cols ..][0..s.cols]; + const sel: Color = .{ .rgb = p.theme().tag_sel_bg orelse p.theme().sel_bg }; for (lit[here..][0..4]) |cell| try std.testing.expectEqual(sel, cell.style.bg); try std.testing.expect(!std.meta.eql(sel, lit[here - 2].style.bg)); - const layer = for (s.tagLayers()) |*layer| { - if (layer.rows != 0 and layer.kind == .notice) break layer; - } else return error.TestExpectedNotice; + const layer = &s.tag_layers[pardes.NOTICE_ROW_LAYER]; + try std.testing.expectEqual(TagKind.notice_row, layer.kind); const lit_in_layer = for (layer.cells) |cell| { if (std.meta.eql(sel, cell.style.bg)) break true; } else false; try std.testing.expect(lit_in_layer); } -test "a notice wider than its band, as a shader's compile error is, draws its end and nothing past it" { +test "a message wider than the notice row, as a shader's compile error is, gives way to the row's right end and draws nothing past the row" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 20 }); defer p.deinit(); - // A gui-shaped core: its tagline is narrower than the body, so a notice's - // band holds more columns than its chip has cells. + // A gui-shaped core: its tagline is narrower than the body, so the + // row's layer holds more columns than the grid has cells. p.update(.{ .resize = .{ .cols = 80, .rows = 20, .row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 6, .tagline_h = 12 } } }); _ = try p.setTestFile("text\n"); var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); @@ -1332,13 +1401,12 @@ test "a notice wider than its band, as a shader's compile error is, draws its en for (0..30) |_| p.update(.tick); _ = arena.reset(.retain_capacity); const s = try p.render(arena.allocator()); - const notice = for (s.regionList()) |region| { - if (region.kind == .notice) break region; - } else return error.TestExpectedNotice; - // Text up to the chip's blank last cell, and no padding ink. - const row = s.cells[@as(usize, notice.rect.y) * s.cols ..][notice.rect.x..][0..notice.rect.w]; - try std.testing.expectEqualStrings(" ", row[row.len - 1].grapheme()); - try std.testing.expect(!std.mem.eql(u8, " ", row[row.len - 2].grapheme())); + const layer = &s.tag_layers[pardes.NOTICE_ROW_LAYER]; + try std.testing.expectEqual(layout.tagCapacity(p, s.cols - TAG_TEXT_INSET), layer.cols); + // The counts at the row's end, whole, a blank cell short of it. + const cells = layer.cells[0..layer.cols]; + try std.testing.expectEqualStrings(" ", cells[cells.len - 1].grapheme()); + try std.testing.expectEqualStrings("m", cells[cells.len - 2].grapheme()); } } @@ -1621,7 +1689,7 @@ fn apart(a: *const Pardes, b: *const Pardes) bool { var pdb: [pane_names.len]u64 = undefined; _ = pardes.walk.fieldDigests(Pane, x, &pda); _ = pardes.walk.fieldDigests(Pane, y, &pdb); - for (pane_names, pda, pdb) |name, u, v| if (u != v and !std.mem.eql(u8, name, "msg_said_ms") and !std.mem.eql(u8, name, "cwd")) { + for (pane_names, pda, pdb) |name, u, v| if (u != v and !std.mem.eql(u8, name, "cwd")) { if (std.mem.eql(u8, name, "file")) if (x.file) |*fx| if (y.file) |*fy| { const file_names = comptime pardes.walk.fieldNames(panes.File.State); var fda: [file_names.len]u64 = undefined; @@ -1640,3 +1708,38 @@ fn apart(a: *const Pardes, b: *const Pardes) bool { } return any; } + +test "progress is said at the right end of its tag: a pane's at its tag's, a server's at the workspace tag's, and it goes when it ends" { + const p = try Pardes.init(std.testing.allocator, .{ .cols = 160, .rows = 20 }); + defer p.deinit(); + const pane = try p.setTestFile("text\n"); + const id = p.view().active; + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + var buf: [512]u8 = undefined; + const Row = struct { + fn of(s: *const Surface, y: u16, out: []u8) []const u8 { + var n: usize = 0; + for (0..s.cols) |x| { + const g = s.cells[@as(usize, y) * s.cols + x].grapheme(); + @memcpy(out[n..][0..g.len], g); + n += g.len; + } + return std.mem.trimEnd(u8, out[0..n], " "); + } + }; + p.setStatus(.at(id), "Changes: jj\u{2026}"); + p.setStatus(.at(pardes.MAX_PANES), "--:--:-- lsp zls: indexing 3/10"); + p.sync(); + var s = try p.render(frame.allocator()); + const tag_y = p.tagTop(pane, p.view().rects[id]); + try std.testing.expect(std.mem.endsWith(u8, Row.of(s, tag_y, &buf), "\u{22ef} Changes: jj\u{2026}")); + try std.testing.expect(std.mem.endsWith(u8, Row.of(s, 0, &buf), "\u{22ef} lsp zls: indexing 3/10")); + // Its mark meanwhile, and neither is the notice row's. + try std.testing.expectEqualStrings("\u{22ef}", s.at(p.view().rects[id].x + config.GUTTER - 1, tag_y).grapheme()); + try std.testing.expect(p.messages.headline() == null); + p.setStatus(.at(id), ""); + _ = frame.reset(.retain_capacity); + s = try p.render(frame.allocator()); + try std.testing.expect(std.mem.indexOf(u8, Row.of(s, tag_y, &buf), "\u{22ef}") == null); +} |
