diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/Messages.zig | 12 | ||||
| -rw-r--r-- | core/Pick.zig | 98 | ||||
| -rw-r--r-- | core/body_layer.zig | 45 | ||||
| -rw-r--r-- | core/colors.zig | 7 | ||||
| -rw-r--r-- | core/draw.zig | 11 | ||||
| -rw-r--r-- | core/look.zig | 6 |
6 files changed, 170 insertions, 9 deletions
diff --git a/core/Messages.zig b/core/Messages.zig index 41344d1f..6231e3d1 100644 --- a/core/Messages.zig +++ b/core/Messages.zig @@ -679,6 +679,10 @@ pub const Row = struct { text: []const u8 = "", /// The message the left says, when it says one. lead: ?*const Said = null, + /// The left in the dim ink (a picker's sentence, UX D7), but for the + /// bytes `word` (an address, in the text's). + quiet_left: bool = false, + word: [2]usize = .{ 0, 0 }, }; /// Room for the notice row's line: the widest window's at the tagline's @@ -704,8 +708,10 @@ pub fn noticeRow(p: *const Pardes, width: usize, out: *[notice_row_cap]u8) Row { live += 1; if (s.kind == .question) questions += 1; } - const lead = m.headline(); - if (lead) |s| { + // While a picker previews, its sentence (UX D7), before any message. + const said = pardes.Pick.sentence(p, &w); + const lead = if (said == null) m.headline() else null; + if (said != null) {} else if (lead) |s| { w.print("{s} ", .{s.kind.glyph()}) catch {}; // Its cause first, unless its words name it already. const words = s.words(); @@ -743,7 +749,7 @@ pub fn noticeRow(p: *const Pardes, width: usize, out: *[notice_row_cap]u8) Row { for (0..gap) |_| w.writeByte(' ') catch {}; const right_at = w.end; w.writeAll(tail) catch {}; - return .{ .left = cut, .right = right_at, .text = w.buffered(), .lead = lead }; + return .{ .left = cut, .right = right_at, .text = w.buffered(), .lead = lead, .quiet_left = said != null, .word = said orelse .{ 0, 0 } }; } /// What notice band `i` says. The grid pass and the band layers both diff --git a/core/Pick.zig b/core/Pick.zig index cb5f605d..efadc881 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -680,6 +680,45 @@ pub fn steps(p: *Pardes, arena: std.mem.Allocator) ![]Band.Step { // ---- the preview ---- +/// The line (from 0) pane `pane`'s body lands the live picker's cursor row +/// on, while it is that picker's landing pane previewing that row's file +/// (UX D7: drawn on the hit ground, body_layer.zig); null else. +pub fn landingLine(p: *Pardes, arena: std.mem.Allocator, pane: *const Pane) ?usize { + const pk = live(p) orelse return null; + if (!pk.previews or pk.landing != pane.serial or pk.source == .themes) return null; + const s = &p.view().tag_state; + if (pk.shown != s.rows.at or count(p, pk) == 0) return null; + const row = rowAt(p, pk, arena, s.rows.at) catch return null; + const place = switch (row.target) { + .place => |t| t, + else => return null, + }; + const f = pane.file orelse return null; + if (!std.mem.eql(u8, f.path, place.path)) return null; + return @intCast(@max(0, pane.body.cur_row)); +} + +/// The notice row's sentence while a picker previews (UX D7), written to +/// `w`: where Enter lands (`here`, or the owner's reader by its address, +/// a word to Look at), that the body is the preview, and Shift-Enter's new +/// pane; the address's bytes in what was written, or null with no picker +/// previewing. +pub fn sentence(p: *const Pardes, w: *std.Io.Writer) ?[2]usize { + const pk = live(p) orelse return null; + if (!pk.previews or pk.source == .themes) return null; + if (pk.landing == pk.owner) { + w.writeAll("⏎ lands here") catch return null; + } else { + w.writeAll("⏎ lands in ") catch return null; + } + const lo = w.end; + if (pk.landing != pk.owner) w.print("@p{d}", .{pk.owner}) catch return null; + const hi = w.end; + if (pk.landing != pk.owner) w.writeAll("'s reader") catch return null; + w.writeAll(" · its text is the preview · S-⏎ a new pane") catch return null; + return .{ lo, hi }; +} + /// The landing pane's body showing the current row's place (SPEC §5.3): /// a file at its line, the query's matches lit for a Grep. Its own text is /// set aside the first time, put back when the picker rolls up. A file an @@ -745,7 +784,7 @@ fn preview(p: *Pardes, pk: *Pick) void { pane.body.cur_col = 0; return; } - look.focusPaneLine(p, id, at, .center); + look.focusPaneLine(p, id, at, .third); // A Grep's matches in the file lit, as its own pane would have them. if (pk.source == .grep) pane.places.search(p, pane, .list, pk.id, std.mem.trim(u8, s.field.text(), " "), true, null, false); } @@ -1984,3 +2023,60 @@ test "the themes picker marks the theme in use: `in use` at its row's right end band = (try Band.of(p, a, pane, id)).?; try std.testing.expectEqualStrings("in use", Find.row(band, pardes.colors.themes[was].name).?.meta); } + +test "a picker's preview is legible as one (UX D7): its landing line on the hit ground with `▸` in the gutter, a third of the body above it, and the notice row saying where Enter lands" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 }); + defer p.deinit(); + p.settings.jumps = .walk; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + var text: std.ArrayList(u8) = .empty; + defer text.deinit(std.testing.allocator); + for (1..81) |i| try text.print(std.testing.allocator, "line {d} of the file\n", .{i}); + const path = try testFile(p, &tmp, "long.zig", text.items); + defer p.gpa.free(path); + _ = try p.setTestFile("held\n"); + const asker = p.view().active; + Trail.keep(p.panes[asker].?); + const rows = try std.fmt.allocPrint(std.testing.allocator, "{s}:40:6 line 40 of the file\n", .{path}); + defer std.testing.allocator.free(rows); + open(p, asker, .list, "Refs", "", rows); + const pk = live(p).?; + const reader = p.paneBySerial(pk.landing).?; + p.update(.tick); + const pane = p.panes[reader].?; + try std.testing.expectEqualStrings(path, pane.file.?.path); + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const s = try p.render(frame.allocator()); + const r = p.view().rects[reader]; + const body_y = p.bodyTop(pane, r); + // Line 40 a third of the way down: ⌈rows/3⌉ rows of context above it. + var at: ?u16 = null; + for (0..pane.rows) |row| if (pane.wrapAt(p.settings.tab, @intCast(row)).line == 39) { + at = @intCast(row); + break; + }; + try std.testing.expectEqual(@as(?u16, @intCast((pane.rows + 2) / 3)), at); + const y = body_y + at.?; + const roles = &p.chromeTheme().roles; + const tx = r.x + pardes.config.GUTTER; + const gutter = File.gutterWidth(pane); + // Its text on the hit ground across the row; the row above as it was. + for (gutter..r.w - pardes.config.GUTTER) |x| try std.testing.expectEqual(pardes.Color{ .rgb = roles.hit }, s.at(tx + @as(u16, @intCast(x)), y).style.bg); + try std.testing.expect(!std.meta.eql(s.at(tx + gutter + 2, y - 1).style.bg, pardes.Color{ .rgb = roles.hit })); + // `▸` in the key ink in the gutter's cell after the number. + const mark = s.at(tx + gutter - 1, y); + try std.testing.expectEqualStrings("▸", mark.grapheme()); + try std.testing.expectEqual(pardes.Color{ .rgb = roles.key }, mark.style.fg); + // The notice row: where Enter lands, the owner's address a word in it. + var buf: [pardes.Messages.notice_row_cap]u8 = undefined; + const said = pardes.Messages.noticeRow(p, 120, &buf); + const want = try std.fmt.allocPrint(frame.allocator(), "⏎ lands in @p{d}'s reader · its text is the preview · S-⏎ a new pane", .{p.panes[asker].?.serial}); + try std.testing.expect(std.mem.startsWith(u8, said.text, want)); + try std.testing.expect(said.quiet_left); + try std.testing.expectEqualStrings(try std.fmt.allocPrint(frame.allocator(), "@p{d}", .{p.panes[asker].?.serial}), said.text[said.word[0]..said.word[1]]); + // At rest: no ground, no mark, the row back to its own. + p.update(.{ .key = .{ .cp = pardes.Key.escape } }); + try std.testing.expect(!pardes.Messages.noticeRow(p, 120, &buf).quiet_left); +} diff --git a/core/body_layer.zig b/core/body_layer.zig index 6ce2b6be..7bff3c31 100644 --- a/core/body_layer.zig +++ b/core/body_layer.zig @@ -349,7 +349,11 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane panes.File.recolorSyntax(p, s, pane, f, r, tx, tw, body_h); panes.Tables.paint(p, s, pane, r, tx, tw, body_h); drawWrapMarkers(p, s, pane, r, tx, tw, body_h, pane_bg); + // A picker's landing line under the places it lights (UX D7). + const landing = pardes.Pick.landingLine(p, arena, pane); + if (landing) |line| paintLanding(p, s, pane, r, tx, tw, body_h, line); pane.places.paint(p, s, pane, r, body_h); + if (landing) |line| paintLandingSpan(p, s, pane, r, f, line); pardes.Prompt.paintGutter(p, s, pane, r, body_h); panes.Query.paint(p, s, pane, r, body_h); } else if (pane.isTerminal()) { @@ -650,6 +654,47 @@ pub fn wordAt(p: *Pardes, arena: std.mem.Allocator, id: usize, row: usize, col: return text.items[b.lo..b.hi]; } +/// A picker's landing line (UX D7): its text on the hit ground across +/// the body's width, and `▸` in the key ink in the gutter's cell after its +/// number (the one a prompt's current place has, Prompt.paintGutter), on +/// each row it wraps onto. +fn paintLanding(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, tx: u16, tw: u16, body_h: u16, line: usize) void { + const roles = &p.chromeTheme().roles; + const gutter = File.gutterWidth(pane); + const number = gutter -| File.laneCells(pane) -| pane.layers.heat -| 1; + const body_y = p.bodyTop(pane, r); + var vr: u16 = pane.context_rows; + while (vr < body_h) : (vr += 1) { + const w = pane.wrapAt(p.settings.tab, vr); + if (w.line != @as(i32, @intCast(line))) continue; + for (gutter..tw) |x| { + const cell = s.at(tx + @as(u16, @intCast(x)), body_y + vr); + cell.default = false; + cell.style.bg = .{ .rgb = roles.hit }; + } + if (gutter > 0 and w.at == 0) { + var style = s.at(tx + number, body_y + vr).style; + style.fg = .{ .rgb = roles.key }; + s.set(tx + number, body_y + vr, "▸", style); + } + } +} + +/// The landing line's matched span (a Grep's match at the row's column) on +/// the current hit's ground, over the places lit on it (UX D7). +fn paintLandingSpan(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, f: *panes.File.State, line: usize) void { + if (!pane.places.shows(pane)) return; + const hits = pane.places.hits.items; + const ls = File.lineStart(p.gpa, f, line); + const caret = ls + @as(usize, @intCast(@max(0, pane.body.cur_col))); + var i = panes.Places.firstFrom(hits, ls); + while (i < hits.len and hits[i].start <= caret) : (i += 1) { + if (hits[i].end <= caret) continue; + File.paintWordSelection(p, s, pane, r, @intCast(line), @intCast(hits[i].start - ls), @intCast(hits[i].end - ls), p.chromeTheme().roles.hit_current); + return; + } +} + /// Painted targets (SPEC §4.4), while a motion root's level shows in this /// body's tag: each of its keys at the line it would go to, in the gutter /// (`g e t b .` for `g`; for `]` the next and for `[` the previous diff --git a/core/colors.zig b/core/colors.zig index d4abf2b5..6b578f09 100644 --- a/core/colors.zig +++ b/core/colors.zig @@ -562,7 +562,7 @@ pub const ChromeTheme = struct { pub fn fromTheme(th: *const Theme) ChromeTheme { // The initial chrome is resolved at compile time: contrast takes pow. - @setEvalBranchQuota(200_000); + @setEvalBranchQuota(1_000_000); const active_bg = focusTint(th); const active_fg = th.tag_active_fg orelse th.tag_fg; // A name is always tinted: a theme that names no tint gets one of @@ -619,6 +619,8 @@ pub const Inks = struct { ground: [3]u8, text: [3]u8, dim: [3]u8, rule: [3]u8 }; pub const Roles = struct { tag: [4]Inks, selected: [4]Inks, + /// The notice row's (the tagline's ground): its dim words. + notice: Inks, /// Key cells, a level's or a row's key letters, `▶`, `•`, a target's /// keys: 4.5:1 on every tag ground and on the selection. key: [3]u8, @@ -669,6 +671,7 @@ pub const Roles = struct { inks.* = inksOn(ground, ink); selected.* = inksOn(selectionOf(th.tag_sel_bg orelse th.sel_bg, ground, inks.text), inks.text); } + r.notice = inksOn(th.tagline_bg orelse th.tag_bg, th.tagline_fg orelse th.tag_fg); const tag_grounds = [_][3]u8{ plain, focused, reading, r.selected[0].ground, r.selected[1].ground, r.selected[2].ground, r.selected[3].ground }; r.key = pushAway(th.box, &tag_grounds, ink_floor); r.match = pushAway(matchHue(th), &tag_grounds, ink_floor); @@ -1547,7 +1550,7 @@ test "every theme's walk UI roles meet their floors on every ground they are dra const body_ink = th.fg orelse th.tag_fg; const tags = [_][3]u8{ r.tag[0].ground, r.tag[1].ground, r.tag[2].ground, r.selected[0].ground, r.selected[1].ground, r.selected[2].ground, r.selected[3].ground }; const messages = [_][3]u8{ r.tag[0].ground, r.tag[1].ground, r.tag[2].ground, page }; - for (r.tag ++ r.selected) |inks| { + for (r.tag ++ r.selected ++ [1]Inks{r.notice}) |inks| { const text = contrast(inks.text, inks.ground); try checks.append(a, .{ .what = "text", .got = text, .floor = @min(Roles.text_floor, Reach.of(&.{inks.ground})) }); try checks.append(a, .{ .what = "dim", .got = contrast(inks.dim, inks.ground), .floor = @min(Roles.dim_floor, text) }); diff --git a/core/draw.zig b/core/draw.zig index 1e53d1d0..16dfde5e 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -640,12 +640,21 @@ fn paintNoticeRow(p: *Pardes, s: *Surface) !void { 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) }; + // The dim ink of the notice row's ground (colors.Roles: 3:1 at least). + const dim: Color = .{ .rgb = chrome.roles.notice.dim }; 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])); + // A picker's sentence: dim, its address in the text's ink. + if (row.quiet_left) { + const lo = panes.File.displayWidth(tab, row.text[0..@min(row.word[0], row.left)]); + const hi = panes.File.displayWidth(tab, row.text[0..@min(row.word[1], row.left)]); + for (cells[0..left], 0..) |*cell, x| if ((x < lo or x >= hi) and std.meta.eql(cell.style.fg, ink)) { + cell.style.fg = dim; + }; + } 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 }; diff --git a/core/look.zig b/core/look.zig index 21043250..b3354a5c 100644 --- a/core/look.zig +++ b/core/look.zig @@ -803,7 +803,7 @@ pub fn advanceLookHover(p: *Pardes) void { p.look_hover_wait = null; } -pub fn focusPaneLine(p: *Pardes, id: usize, at_in: Spot, landing: enum { center, keep }) void { +pub fn focusPaneLine(p: *Pardes, id: usize, at_in: Spot, landing: enum { center, third, keep }) void { if (id >= MAX_PANES) return; const pane = p.panes[id] orelse return; p.view().active = id; @@ -822,7 +822,9 @@ pub fn focusPaneLine(p: *Pardes, id: usize, at_in: Spot, landing: enum { center, if (at.line > panes.File.nlines(p.gpa, f)) return; // centred (its first row of text half the body's rows down, as // zz), clamped at the top; a text that fits is shown whole - if (landing == .center) panes.File.setTop(pane, if (pane.textFits()) .{ .line = 0 } else panes.File.walkRows(p.settings.tab, pane, .{ .line = at.line - 1, .row = panes.File.rowOf(p.settings.tab, pane, at.line - 1, 0) }, -@as(i64, pane.rows / 2)).to); + // or a third of them down (a picker's preview, UX D7: context above + // its landing line, the rest below) + if (landing != .keep) panes.File.setTop(pane, if (pane.textFits()) .{ .line = 0 } else panes.File.walkRows(p.settings.tab, pane, .{ .line = at.line - 1, .row = panes.File.rowOf(p.settings.tab, pane, at.line - 1, 0) }, -@as(i64, if (landing == .third) (pane.rows + 2) / 3 else pane.rows / 2)).to); } pane.body.cur_row = std.math.cast(i32, at.line - 1) orelse return; pane.body.cur_col = columnOn(pane, pane.body.cur_row, at.col); |
