summaryrefslogtreecommitdiff
path: root/core/draw.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/draw.zig')
-rw-r--r--core/draw.zig103
1 files changed, 83 insertions, 20 deletions
diff --git a/core/draw.zig b/core/draw.zig
index 68778667..2fc69feb 100644
--- a/core/draw.zig
+++ b/core/draw.zig
@@ -883,13 +883,17 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R
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();
const chrome = p.chromeTheme();
const tab = p.settings.tab;
const rows = pane.band_rows;
const columns = @max(band.columns, 1);
- const bg = tagGround(p, pane, active);
- const fg = if (active) chrome.tag_active_fg else chrome.tag_fg;
+ // The walk UI's inks on this tag's ground (colors.Roles, UX DESIGN.md
+ // D4), and on its cursor row's selection.
+ const ground = groundOf(p, pane, active);
+ const inks = chrome.roles.on(ground);
+ const selected = chrome.roles.selectedOn(ground);
+ const bg = inks.ground;
+ const fg = inks.text;
const storage = try arena.alloc(Cell, @as(usize, columns) * rows);
@memset(storage, .{});
var t: Surface = .{ .cols = columns, .rows = rows, .cells = storage, .tab = tab };
@@ -898,32 +902,41 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R
t.fill(0, row, columns, 1, .{ .bg = .{ .rgb = bg }, .font_role = .tagline });
const ln = try band.line(arena, tab, row);
_ = t.print(0, row, columns, ln.text, .{ .fg = .{ .rgb = fg }, .bg = .{ .rgb = bg }, .font_role = .tagline });
- // The spines and the rules between steps: the key ink.
+ // The spines and the rules between steps in the rule ink; a row's
+ // `▶` (the cursor) and `•` (marked) in the key ink.
var col: u16 = 0;
var at: usize = 0;
while (at < ln.text.len and col < columns) : (col += 1) {
const next = modal.nextGrapheme(ln.text, at);
- if (std.mem.eql(u8, ln.text[at..next], "│")) t.at(col, row).style.fg = .{ .rgb = chrome.box };
- if (std.mem.eql(u8, ln.text[at..next], "▶")) t.at(col, row).style.fg = .{ .rgb = chrome.box };
+ const glyph = ln.text[at..next];
+ if (std.mem.eql(u8, glyph, "│")) t.at(col, row).style.fg = .{ .rgb = inks.rule };
+ if (std.mem.eql(u8, glyph, "▶") or std.mem.eql(u8, glyph, "•")) t.at(col, row).style.fg = .{ .rgb = chrome.roles.key };
at = next;
}
for (ln.parts) |part| {
const end = @min(columns, part.col + part.width);
- if (part.row.on and part.col < end) t.tint(part.col, row, end - part.col, th.tag_sel_bg orelse th.sel_bg, th.sel_fg);
+ const on = if (part.row.on) selected else inks;
+ if (part.row.on and part.col < end) t.tint(part.col, row, end - part.col, selected.ground, selected.text);
var c = part.col;
var b: usize = 0;
while (b < part.row.text.len and c < end) : (c += 1) {
const next = modal.nextGrapheme(part.row.text, b);
const style = &t.at(c, row).style;
if (b < part.row.key) {
- style.fg = .{ .rgb = chrome.box };
+ style.fg = .{ .rgb = chrome.roles.key };
style.bold = true;
}
+ // A chord (Help's `SPC h t`): keys, at the text's weight.
+ if (b < part.row.chord) style.fg = .{ .rgb = chrome.roles.key };
if (b < part.row.pre) style.fg = .{ .rgb = if (active) chrome.tag_active_name_fg else chrome.tag_name_fg };
- if (part.row.dim or (b >= part.row.pre and b < part.row.pre + part.row.faint)) style.dim = true;
+ if (part.row.dim or (b >= part.row.pre and b < part.row.pre + part.row.faint)) style.fg = .{ .rgb = on.dim };
if (part.row.under) style.ul = .single;
+ // A matched letter: the match ink, bold, on the row's own
+ // ground (never a ground of its own: on the cursor row's
+ // selection one vanished).
for (part.row.marks) |m| if (m == b) {
- style.bg = .{ .rgb = chrome.search_bg };
+ style.fg = .{ .rgb = chrome.roles.match };
+ style.bold = true;
};
b = next;
}
@@ -967,9 +980,14 @@ fn inkTag(p: *Pardes, s: *Surface, shown: tagline.Shown, lines: []const []const
/// A pane's tag's ground: a reading pane's tint (its focus is its grip's),
/// else the focused tag's or the tag's.
fn tagGround(p: *Pardes, pane: *const Pane, active: bool) [3]u8 {
- const chrome = p.chromeTheme();
- if (pardes.Trail.reading(p, pane)) return chrome.tag_reading_bg;
- return if (active) chrome.tag_active_bg else chrome.tag_bg;
+ return p.chromeTheme().roles.on(groundOf(p, pane, active)).ground;
+}
+
+/// Which of a tag's grounds pane `pane`'s is: its walk UI inks
+/// (colors.Roles) are that ground's.
+fn groundOf(p: *Pardes, pane: *const Pane, active: bool) colors.TagGround {
+ if (pardes.Trail.reading(p, pane)) return if (active) .reading_focused else .reading;
+ return if (active) .focused else .plain;
}
fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: Rect, id: usize, active: bool) !void {
@@ -981,7 +999,8 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
const rows = pane.tag_rows - pane.band_rows;
const page_rgb = th.bg orelse th.tag_bg;
// Focus is visible along the tag without changing its live text grid.
- const tag_bg = tagGround(p, pane, active);
+ const inks = chrome.roles.on(groundOf(p, pane, active));
+ const tag_bg = inks.ground;
const tag_fg = if (active) chrome.tag_active_fg else chrome.tag_fg;
const tag_style: CellStyle = .{ .fg = .{ .rgb = tag_fg }, .bg = .{ .rgb = tag_bg }, .font_role = .tagline };
// Padding belongs to the same font row but keeps its default ink: a
@@ -995,6 +1014,8 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
const head = try TagState.head(p, arena, pane);
const tail = if (head) |h| h.text else tagline.curTail(pane);
const prefix_len = whole.len - tail.len;
+ // Out of rest, the walk UI's text ink (at rest the tag's own, unchanged).
+ const text_style: CellStyle = if (head == null) tag_style else .{ .fg = .{ .rgb = inks.text }, .bg = .{ .rgb = tag_bg }, .font_role = .tagline };
// A row per line shown, from `tag_top`: the tag's first line carries
// the prefix, the rest are the tag's own text alone.
const top = pane.tag_top;
@@ -1028,7 +1049,7 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
for (lines[0..rows], 0..) |line, row| {
// The scroll is the caret's line's: a shorter row shows nothing.
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);
+ _ = s.print(tx, tag_y + @as(u16, @intCast(row)), tw, line[start..], text_style);
}
// The pane's progress at its first row's right end, where the row has
// room for it (SPEC §10.2).
@@ -1048,9 +1069,9 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
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(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);
+ 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), inks.dim);
// 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);
+ 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), inks.dim);
// 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| {
@@ -1068,13 +1089,14 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
const style = &s.at(tx + @as(u16, @intCast(col)), y).style;
switch (span.style) {
.key => {
- style.fg = .{ .rgb = chrome.box };
+ style.fg = .{ .rgb = chrome.roles.key };
style.bold = true;
},
- .dim => style.dim = true,
+ .dim => style.fg = .{ .rgb = inks.dim },
.under => style.ul = .single,
.strike => style.strikethrough = true,
- .err => style.fg = .{ .rgb = chrome.diagnostic_error },
+ .err => style.fg = .{ .rgb = chrome.roles.err },
+ .rule => style.fg = .{ .rgb = inks.rule },
}
}
}
@@ -1745,3 +1767,44 @@ test "progress is said at the right end of its tag: a pane's at its tag's, a ser
s = try p.render(frame.allocator());
try std.testing.expect(std.mem.indexOf(u8, Row.of(s, tag_y, &buf), "\u{22ef}") == null);
}
+
+test "a tag out of rest draws its keys bold in the key ink and its hint in the dim ink, never faint (UX D4)" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 200, .rows = 30 });
+ defer p.deinit();
+ const pane = try p.setTestFile("one\n");
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ const roles = &p.chromeTheme().roles;
+ const inks = roles.on(if (pardes.Trail.reading(p, pane)) .reading_focused else .focused);
+ // SPC's level rolled, after its delay: `␣ ▸ … l lsp… … ↓ unroll · ? help`.
+ p.clock.now_ns = 5 * std.time.ns_per_s;
+ p.clock.stepped_ns = p.clock.now_ns;
+ p.update(.{ .key = .{ .cp = ' ' } });
+ p.advance(p.clock.now_ns);
+ p.clock.now_ns = p.view().tag_state.due_ns;
+ p.sync();
+ const s = try p.render(a);
+ const r = p.view().rects[p.view().active];
+ const row = s.cells[@as(usize, r.y) * s.cols ..][0 .. @as(usize, s.cols) * (pane.tag_rows - pane.band_rows)];
+ const Row = struct {
+ fn find(cells: []const Cell, word: []const u8) ?usize {
+ var at: usize = 0;
+ while (at + word.len <= cells.len) : (at += 1) {
+ for (word, cells[at..][0..word.len]) |c, cell| {
+ if (cell.len != 1 or cell.text[0] != c) break;
+ } else return at;
+ }
+ return null;
+ }
+ };
+ const hint = Row.find(row, "unroll").?;
+ try std.testing.expectEqual(Color{ .rgb = inks.dim }, row[hint].style.fg);
+ for (row) |cell| try std.testing.expect(!cell.style.dim);
+ var keys: usize = 0;
+ for (row) |cell| if (std.meta.eql(cell.style.fg, Color{ .rgb = roles.key })) {
+ try std.testing.expect(cell.style.bold);
+ keys += 1;
+ };
+ try std.testing.expect(keys > 3);
+}