diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/Band.zig | 17 | ||||
| -rw-r--r-- | core/Pick.zig | 60 | ||||
| -rw-r--r-- | core/draw.zig | 5 |
3 files changed, 78 insertions, 4 deletions
diff --git a/core/Band.zig b/core/Band.zig index a8d97bb4..e562da1d 100644 --- a/core/Band.zig +++ b/core/Band.zig @@ -56,6 +56,9 @@ pub const Row = struct { /// tint; the `faint` bytes after them dimmed (a path's directory). pre: u16 = 0, faint: u16 = 0, + /// Said at the row's right end in the dim ink, two cells off its text + /// at least, and the first to give way (UX D5): `in use`. + meta: []const u8 = "", }; /// A column of rows. A level of more than 9 rows flows into two columns @@ -375,7 +378,7 @@ fn place(band: *Band, p: *Pardes, arena: std.mem.Allocator, pane: *Pane, id: usi for (band.steps[0..band.nsteps]) |*step| { if (step.doc) continue; var widest: usize = 0; - for (step.rows) |row| widest = @max(widest, File.displayWidth(tab, row.text)); + for (step.rows) |row| widest = @max(widest, File.displayWidth(tab, row.text) + if (row.meta.len > 0) 2 + File.displayWidth(tab, row.meta) else 0); const column: u16 = @intCast(@min(widest + 2, std.math.maxInt(u16) / 4, @max(min_width, band.columns -| x))); step.width = if (step.two) 2 * column + 1 else column; need += step.width + 2; @@ -493,14 +496,26 @@ pub fn line(band: *const Band, arena: std.mem.Allocator, tab: u16, y: u16) !Line col += @intCast(File.displayWidth(tab, lead)); try parts.append(arena, .{ .col = col, .width = per -| @as(u16, @intCast(File.displayWidth(tab, lead))), .row = row }); const room = per -| @as(u16, @intCast(File.displayWidth(tab, lead))); + const at = col; const cut = File.byteAtDisplay(tab, row.text, room); try text.appendSlice(arena, row.text[0..cut]); col += @intCast(File.displayWidth(tab, row.text[0..cut])); + if (metaShown(tab, row, room)) { + const meta: u16 = @intCast(File.displayWidth(tab, row.meta)); + while (col < at + room - meta) : (col += 1) try text.append(arena, ' '); + try text.appendSlice(arena, row.meta); + col += meta; + } } } return .{ .text = text.items, .parts = parts.items }; } +/// Whether row `row`'s meta fits `room` cells after its text. +pub fn metaShown(tab: u16, row: Row, room: u16) bool { + return row.meta.len > 0 and File.displayWidth(tab, row.text) + 2 + File.displayWidth(tab, row.meta) <= room; +} + /// The word under column `col` of band row `y` of pane `id`, at the /// tagline's pitch: what B2 executes and B3 looks at. pub fn wordAt(p: *Pardes, arena: std.mem.Allocator, id: usize, y: u16, col: u16) !?[]const u8 { diff --git a/core/Pick.zig b/core/Pick.zig index 6026f11b..cb5f605d 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -458,7 +458,7 @@ const Target = union(enum) { none, place: struct { path: []const u8, at: look.Sp /// Row `i` as the band shows it and what it points at, its text in /// `arena`. -const Row = struct { text: []const u8, pre: u16 = 0, faint: u16 = 0, dim: bool = false, marks: []const u16 = &.{}, target: Target = .none }; +const Row = struct { text: []const u8, pre: u16 = 0, faint: u16 = 0, dim: bool = false, marks: []const u16 = &.{}, target: Target = .none, meta: []const u8 = "" }; fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) !Row { const dir = pk.dir.slice(); @@ -526,7 +526,10 @@ fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) !Row { const f = owner.file orelse return row; row.target = .{ .place = .{ .path = f.path, .at = .{ .line = cand.ref } } }; }, - .themes => {}, + // The theme in use says so, whichever the window wears (POLISH 12). + .themes => if (p.custom_theme == null and cand.ref == p.settings.theme) { + row.meta = "in use"; + }, .recent, .jumplist, .list, .grep, .all => { const t = look.parsePathLine(text); row.pre = @intCast(t.end); @@ -669,7 +672,7 @@ pub fn steps(p: *Pardes, arena: std.mem.Allocator) ![]Band.Step { const rows = try arena.alloc(Band.Row, w.hi - w.lo); for (rows, w.lo..) |*row, i| { const r = try rowAt(p, pk, arena, i); - row.* = .{ .text = r.text, .on = i == s.rows.at, .mark = marked(pk, idOf(pk, i)) != null, .dim = r.dim, .pre = r.pre, .faint = r.faint, .marks = r.marks, .index = @intCast(i) }; + row.* = .{ .text = r.text, .on = i == s.rows.at, .mark = marked(pk, idOf(pk, i)) != null, .dim = r.dim, .pre = r.pre, .faint = r.faint, .marks = r.marks, .index = @intCast(i), .meta = r.meta }; } out[0] = .{ .rows = rows }; return out; @@ -1930,3 +1933,54 @@ test "n and N walk the newest list or search word, or the one Looked at (SPEC ยง p.update(.{ .key = .{ .cp = 'n', .text = "n" } }); try std.testing.expect(pane.places.current != null and !std.meta.eql(was, pane.places.current)); } + +test "the themes picker marks the theme in use: `in use` at its row's right end in the dim ink, the cursor on it when it opens, the mark staying on it while the window wears another (POLISH 12, UX A15)" { + const Key_ = pardes.Key; + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 }); + defer p.deinit(); + const pane = try p.setTestFile("one\n"); + const id = p.view().active; + var frame = std.heap.ArenaAllocator.init(std.testing.allocator); + defer frame.deinit(); + const a = frame.allocator(); + const was = p.settings.theme; + for (" tt") |c| p.update(.{ .key = .{ .cp = c } }); + const s = &p.view().tag_state; + try std.testing.expectEqual(@as(u16, @intCast(was)), s.rows.at); + const Find = struct { + fn row(band: Band, text: []const u8) ?Band.Row { + for (band.steps[0..band.nsteps]) |step| for (step.rows) |r| if (std.mem.eql(u8, r.text, text)) return r; + return null; + } + }; + var band = (try Band.of(p, a, pane, id)).?; + const worn = Find.row(band, pardes.colors.themes[was].name).?; + try std.testing.expectEqualStrings("in use", worn.meta); + try std.testing.expect(worn.on); + // One row says it. + var said: usize = 0; + for (band.steps[0..band.nsteps]) |step| for (step.rows) |r| { + said += @intFromBool(r.meta.len > 0); + }; + try std.testing.expectEqual(@as(usize, 1), said); + // Drawn at the row's right end, in the dim ink of the selection it is on. + _ = try p.render(a); + const layer = &p.surface.tag_layers[pardes.BAND_LAYER]; + const roles = &p.chromeTheme().roles; + const on = roles.selectedOn(if (pardes.Trail.reading(p, pane)) .reading_focused else .focused); + var found = false; + for (0..layer.rows) |row| { + const cells = layer.cells[row * layer.cols ..][0..layer.cols]; + var at: usize = 0; + while (at + 6 <= cells.len) : (at += 1) { + if (!std.mem.eql(u8, cells[at].grapheme(), "i") or !std.mem.eql(u8, cells[at + 1].grapheme(), "n") or !std.mem.eql(u8, cells[at + 3].grapheme(), "u")) continue; + try std.testing.expectEqual(pardes.Color{ .rgb = on.dim }, cells[at].style.fg); + found = true; + } + } + try std.testing.expect(found); + // The window wearing the next: the mark stays on the theme in use. + p.update(.{ .key = .{ .cp = if (was + 1 < pardes.colors.themes.len) Key_.down else Key_.up } }); + band = (try Band.of(p, a, pane, id)).?; + try std.testing.expectEqualStrings("in use", Find.row(band, pardes.colors.themes[was].name).?.meta); +} diff --git a/core/draw.zig b/core/draw.zig index 673d3386..9f9abb58 100644 --- a/core/draw.zig +++ b/core/draw.zig @@ -945,6 +945,11 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R }; b = next; } + // Its meta, right-aligned in the part (Band.line), dim. + if (pardes.Band.metaShown(tab, part.row, part.width) and part.col + part.width <= columns) { + const meta: u16 = @intCast(panes.File.displayWidth(tab, part.row.meta)); + for (part.col + part.width - meta..part.col + part.width) |x| t.at(@intCast(x), row).style.fg = .{ .rgb = on.dim }; + } } } const count = @as(usize, columns) * rows; |
