diff options
Diffstat (limited to 'core/Prompt.zig')
| -rw-r--r-- | core/Prompt.zig | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/core/Prompt.zig b/core/Prompt.zig index 64e030e0..4db7e424 100644 --- a/core/Prompt.zig +++ b/core/Prompt.zig @@ -819,7 +819,7 @@ pub fn unlit(p: *const Pardes, pane: *Pane) ?[2]usize { } /// The gutter's marks while a prompt is typed (SPEC §7.1): `▸` on the -/// current place's line and `▪` on every other line holding a place (`/ +/// current place's line alone (`/ /// ?`); `┃` on each line the selections a sam prompt began with cover (`s /// S K A-K`), its scope. In the blank after a row's line number, on a /// line's first row. @@ -836,8 +836,12 @@ pub fn paintGutter(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, body_h: const tab = p.settings.tab; const x = gutterX(pane, r); const y = p.bodyTop(pane, r); - const ink = p.chromeTheme().box; + const ink = p.chromeTheme().roles.key; const nlines = File.nlines(p.gpa, f); + // `▸` on the current place's line alone: the lines with places are the + // rail's ticks (Places.addTicks), never glyphs of their own (UX D14). + const c = set.current orelse return; + if (c >= hits.len) return; var last: i32 = -1; var vr: u16 = 0; while (vr < body_h) : (vr += 1) { @@ -847,12 +851,11 @@ pub fn paintGutter(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, body_h: last = line; const ls = File.lineStart(p.gpa, f, @intCast(line)); const next = File.lineStart(p.gpa, f, @intCast(line + 1)); - const i = Places.firstFrom(hits, ls); - if (i == hits.len or hits[i].start >= @max(next, ls + 1)) continue; - const current = if (set.current) |c| c < hits.len and hits[c].start >= ls and hits[c].start < @max(next, ls + 1) else false; + if (hits[c].start < ls or hits[c].start >= @max(next, ls + 1)) continue; var style = s.at(x, y + vr).style; style.fg = .{ .rgb = ink }; - s.set(x, y + vr, if (current) "▸" else "▪", style); + s.set(x, y + vr, "▸", style); + return; } } @@ -1077,10 +1080,13 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !TagState.Head { try styled(arena, &text, &spans, try std.fmt.allocPrint(arena, " = {s}", .{verb}), .dim); try text.print(arena, " {s}", .{w.buffered()}); } + // A pattern that is no regex: why, in the err ink, in place of the + // hints (UX D14), what is shown meanwhile dim. if (pr.bad) { try text.appendSlice(arena, " "); try styled(arena, &text, &spans, regexMessage(line), .err); - try text.print(arena, " · the {d} from before shown, dimmed", .{@as(usize, pane.body.nsel) + 1}); + try styled(arena, &text, &spans, try std.fmt.allocPrint(arena, " · the {d} from before shown, dimmed", .{@as(usize, pane.body.nsel) + 1}), .dim); + return .{ .text = text.items, .spans = spans.items, .cells = 1, .caret = caret }; } else if (behavior(pr.op) != null) { try pipeCount(p, arena, &text, &spans, pane, pr, line); } else try count(arena, &text, pane, pr); @@ -1282,7 +1288,8 @@ test "s asks in the tag's head: its key cell, the field, the plain word and the try std.testing.expectEqual(@as(u16, 1), pane.body.nsel); // No regex: the two from before, dimmed, and why. typeKeys(p, "("); - try std.testing.expect(has(try tagOf(p), " bad regular expression · the 2 from before shown, dimmed ")); + // Its reason in place of the hints (UX D14), what follows it dim. + try std.testing.expect(std.mem.endsWith(u8, try tagOf(p), " bad regular expression · the 2 from before shown, dimmed")); try std.testing.expectEqual(@as(u16, 1), pane.body.nsel); try std.testing.expect(selecting(p, pane).?.dim); // Esc: rest, the tag and the selection as they were. @@ -1353,7 +1360,7 @@ fn gutterAt(p: *Pardes, arena: std.mem.Allocator, row: u16) ![]const u8 { return s.at(x, p.bodyTop(pane, r) + row).grapheme(); } -test "/ searches the body as it is typed: the current place selected, the gutter marked, counted 3/7 · 5 lines; Enter folds /dirty/ 3/7 into the trail; n says where it went, round the end too; the first Esc clears the tints and dims the word, Look on it lights them again" { +test "/ searches the body as it is typed: the current place selected, `▸` in the key ink on its line alone (the others are the rail's ticks), the places on the hit ground, counted 3/7 · 5 lines; Enter folds /dirty/ 3/7 into the trail; n says where it went, round the end too; the first Esc clears the tints and dims the word, Look on it lights them again (UX D14)" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 200, .rows = 30 }); defer p.deinit(); var frame = std.heap.ArenaAllocator.init(std.testing.allocator); @@ -1364,10 +1371,20 @@ test "/ searches the body as it is typed: the current place selected, the gutter typeKeys(p, "/dirty"); try std.testing.expect(has(try tagOf(p), " / dirty = Look /dirty/ 3/7 · 5 lines ⏎ land · M-⏎ as a list")); try std.testing.expectEqual(@as(?usize, 2), pane.places.current); - try std.testing.expectEqualStrings("▪", try gutterAt(p, frame.allocator(), 0)); + try std.testing.expectEqualStrings(" ", try gutterAt(p, frame.allocator(), 0)); try std.testing.expectEqualStrings(" ", try gutterAt(p, frame.allocator(), 1)); try std.testing.expectEqualStrings("▸", try gutterAt(p, frame.allocator(), 2)); - try std.testing.expectEqualStrings("▪", try gutterAt(p, frame.allocator(), 7)); + try std.testing.expectEqualStrings(" ", try gutterAt(p, frame.allocator(), 7)); + { + const s = try p.render(frame.allocator()); + const r = p.view().rects[0]; + const roles = &p.chromeTheme().roles; + const x = r.x + config.GUTTER + File.gutterWidth(pane); + const y = p.bodyTop(pane, r); + try std.testing.expectEqual(pardes.Color{ .rgb = roles.key }, s.at(x - 1 - File.laneCells(pane) - pane.layers.heat, y + 2).style.fg); + // Line 1's place (`dirty` at its start) on the hit ground. + try std.testing.expectEqual(pardes.Color{ .rgb = roles.hit }, s.at(x, y).style.bg); + } p.update(.{ .key = .{ .cp = Key.enter } }); try std.testing.expectEqual(TagState.Kind.rest, p.view().tag_state.kind); try std.testing.expect(std.mem.startsWith(u8, try tagOf(p), "/dirty/ 3/7 › /test.txt ")); |
