diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-30 15:39:20 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-01 00:12:17 -0300 |
| commit | c04df904f2fa686cbe5ce0c078a96260af7b08bd (patch) | |
| tree | ebb892b5b2f4c91505c241d1408fea1a1904a883 /test | |
| parent | b9eefda75ab9a63fc510de781d02b92fc04ad31d (diff) | |
| download | pardes-c04df904f2fa686cbe5ce0c078a96260af7b08bd.tar.gz pardes-c04df904f2fa686cbe5ce0c078a96260af7b08bd.zip | |
A diff reads as the code it changes: hunks in their file's language, added and removed rows tinted
A .diff or .patch pane, and a command pane whose output is a diff (`git
diff`, `git show`, `diff -u`; told by a `diff --git` line, or `---`/`+++`
with a `@@` under them, in its first rows), colour each hunk's code in the
language of the file its section names (`+++ b/<path>`, `--- a/<path>` for
a deleted file), with tree-sitter, as highlightLocations does for results.
src/diff.zig walks a unified diff by its `@@` counts, so a removed line
that reads `--- x` is no header. Each side of a hunk is parsed as one text
(context and removed lines the old side, context and added lines the new),
so a string or comment across lines colours as it does in the file; a side
no line takes its colours from is not parsed. A section's hunks share a
parse, in pieces of about 40 lines (a hunk past 80 is cut), only those in
view, and each piece's colours are kept by its bytes, so scrolling back and
a terminal's every repaint parse nothing again.
Added and removed lines carry a flag in their style byte; the painter tints
their rows to the pane's edge, a little way from the page toward the
theme's ANSI green or red, and draws the prefix in that hue pushed to read
on it. A file in no known language keeps the old line colours.
A command pane is read once its command has finished: its rows are copied
once (File.DiffOutput, dropped when the pane runs again), so no frame dumps
the scrollback, and painted over what git printed. A running command is
shown as it prints.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'test')
| -rw-r--r-- | test/snapshots/diffview.golden | 119 | ||||
| -rw-r--r-- | test/snapshots/diffview.snap | 27 |
2 files changed, 146 insertions, 0 deletions
diff --git a/test/snapshots/diffview.golden b/test/snapshots/diffview.golden new file mode 100644 index 00000000..2da9f6e3 --- /dev/null +++ b/test/snapshots/diffview.golden @@ -0,0 +1,119 @@ +== snap diff-pane grid=100x31 cursor=7,3 +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/diffview/cwd/change.diff Save Tty Collapse Del +| 1 diff --git a/src/shape.zig b/src/shape.zig +| 2 index 1111111..2222222 100644 +| 3 --- a/src/shape.zig +| 4 +++ b/src/shape.zig +| 5 @@ -1,10 +1,12 @@ +| 6 const std = @import("std"); +| 7 +| 8 pub const Shape = union(enum) { +| 9 circle: f32, +| 10 - square: u8 = 7, +| 11 + square: f32, +| 12 + triangle: struct { base: f32, height: f32 }, +| 13 +| 14 const note = +| 15 - \\areas +| 16 + \\areas, defer +| 17 + \\summed +| 18 ; +| 19 }; +| 20 +== style diff-colours grid=100x31 +|0: 0-99 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-2 d,#314738, 3-99 #becfc4,#314738, +|2: 0-1 d,#add38a, 2-2 d,#314738, 3-32 #becfc4,#314738, 33-44 #dfbce5,#314738, 45-99 #becfc4,#314738, +|3: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-99 #b9f480,#0d1410, +|4: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-99 #b9f480,#0d1410, +|5: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-99 #b9f480,#0d1410, +|6: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-99 #b9f480,#0d1410, +|7: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-99 #c9a7ed,#0d1410, +|8: 0-0 d,#608269, 1-4 d,#0d1410, 5-7 #59675c,#0d1410, 8-19 #e5eee5,#0d1410, 20-26 #c9a7ed,#0d1410, 27-27 #e5eee5,#0d1410, 28-32 #b8d88a,#0d1410, 33-99 #e5eee5,#0d1410, +|9: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#0d1410, +|10: 0-0 d,#608269, 1-4 d,#0d1410, 5-7 #59675c,#0d1410, 8-25 #e5eee5,#0d1410, 26-30 #c9a7ed,#0d1410, 31-31 #e5eee5,#0d1410, 32-35 #c9a7ed,#0d1410, 36-99 #e5eee5,#0d1410, +|11: 0-0 d,#608269, 1-4 d,#0d1410, 5-11 #59675c,#0d1410, 12-99 #e5eee5,#0d1410, +|12: 0-0 d,#608269, 1-3 d,#0d1410, 4-6 #59675c,#0d1410, 7-7 #f1a39b,#302b25,b 8-11 #f1a39b,#302b25, 12-24 #e5eee5,#302b25, 25-25 #f8c082,#302b25, 26-99 #e5eee5,#302b25, +|13: 0-0 d,#608269, 1-3 d,#0d1410, 4-6 #59675c,#0d1410, 7-7 #b6ce94,#263025,b 8-11 #b6ce94,#263025, 12-99 #e5eee5,#263025, +|14: 0-0 d,#608269, 1-3 d,#0d1410, 4-6 #59675c,#0d1410, 7-7 #b6ce94,#263025,b 8-11 #b6ce94,#263025, 12-21 #e5eee5,#263025, 22-28 #c9a7ed,#263025, 29-99 #e5eee5,#263025, +|15: 0-0 d,#608269, 1-3 d,#0d1410, 4-99 #59675c,#0d1410, +|16: 0-0 d,#608269, 1-3 d,#0d1410, 4-11 #59675c,#0d1410, 12-99 #e5eee5,#0d1410, +|17: 0-0 d,#608269, 1-3 d,#0d1410, 4-6 #59675c,#0d1410, 7-7 #f1a39b,#302b25,b 8-15 #f1a39b,#302b25, 16-99 #b8d88a,#302b25, +|18: 0-0 d,#608269, 1-3 d,#0d1410, 4-6 #59675c,#0d1410, 7-7 #b6ce94,#263025,b 8-15 #b6ce94,#263025, 16-99 #b8d88a,#263025, +|19: 0-0 d,#608269, 1-3 d,#0d1410, 4-6 #59675c,#0d1410, 7-7 #b6ce94,#263025,b 8-15 #b6ce94,#263025, 16-99 #b8d88a,#263025, +|20: 0-0 d,#608269, 1-3 d,#0d1410, 4-11 #59675c,#0d1410, 12-99 #e5eee5,#0d1410, +|21: 0-0 d,#608269, 1-3 d,#0d1410, 4-7 #59675c,#0d1410, 8-99 #e5eee5,#0d1410, +|22: 0-0 d,#608269, 1-3 d,#0d1410, 4-99 #59675c,#0d1410, +|23: 0-0 d,#608269, 1-99 d,#0d1410, +|24: 0-0 d,#608269, 1-99 d,#0d1410, +|25: 0-0 d,#608269, 1-99 d,#0d1410, +|26: 0-0 d,#608269, 1-99 d,#0d1410, +|27: 0-0 d,#608269, 1-99 d,#0d1410, +|28: 0-0 d,#608269, 1-99 d,#0d1410, +|29: 0-0 d,#608269, 1-99 d,#0d1410, +|30: 0-0 d,#608269, 1-99 d,#0d1410, +== snap command-pane grid=100x31 cursor=7,3 +|Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit +| New Tty Find Grep Joincol Delcol +| /tmp/pardes-snap/diffview/cwd/cmds.txt Save Tty Collapse Del +| 1 cat change.diff Exec +| 2 +| +| +| +| +| +| +| +| +| +| +| +| +| /tmp/pardes-snap/diffview/cwd (cat change.diff) exit 0 Kill Save Collapse Del +| circle: f32, +| - square: u8 = 7, +| + square: f32, +| + triangle: struct { base: f32, height: f32 }, +| +| const note = +| - \\areas +| + \\areas, defer +| + \\summed +| ; +| }; +| exit 0 +== style command-colours grid=100x31 +|0: 0-99 #b2c3b8,#1d2824, +|1: 0-1 d,#887455, 2-2 d,#314738, 3-99 #becfc4,#314738, +|2: 0-1 d,#add38a, 2-2 d,#314738, 3-32 #becfc4,#314738, 33-41 #dfbce5,#314738, 42-99 #becfc4,#314738, +|3: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-93 #e5eee5,#0d1410, 94-94 #e5eee5,#1d2824, 95-99 #b2c3b8,#1d2824, +|4: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#0d1410, +|5: 0-0 d,#608269, 1-99 d,#0d1410, +|6: 0-0 d,#608269, 1-99 d,#0d1410, +|7: 0-0 d,#608269, 1-99 d,#0d1410, +|8: 0-0 d,#608269, 1-99 d,#0d1410, +|9: 0-0 d,#608269, 1-99 d,#0d1410, +|10: 0-0 d,#608269, 1-99 d,#0d1410, +|11: 0-0 d,#608269, 1-99 d,#0d1410, +|12: 0-0 d,#608269, 1-99 d,#0d1410, +|13: 0-0 d,#608269, 1-99 d,#0d1410, +|14: 0-0 d,#608269, 1-99 d,#0d1410, +|15: 0-0 d,#608269, 1-99 d,#0d1410, +|16: 0-0 d,#608269, 1-99 d,#0d1410, +|17: 0-1 d,#496656, 2-2 d,#1d2824, 3-99 #b2c3b8,#1d2824, +|18: 0-0 d,#152019, 1-6 d,#0d1410, 7-99 #e5eee5,#0d1410, +|19: 0-0 d,#152019, 1-1 d,#0d1410, 2-2 #f1a39b,#302b25,b 3-6 #f1a39b,#302b25, 7-19 #e5eee5,#302b25, 20-20 #f8c082,#302b25, 21-99 #e5eee5,#302b25, +|20: 0-0 d,#152019, 1-1 d,#0d1410, 2-2 #b6ce94,#263025,b 3-6 #b6ce94,#263025, 7-99 #e5eee5,#263025, +|21: 0-0 d,#152019, 1-1 d,#0d1410, 2-2 #b6ce94,#263025,b 3-6 #b6ce94,#263025, 7-16 #e5eee5,#263025, 17-23 #c9a7ed,#263025, 24-99 #e5eee5,#263025, +|22: 0-0 d,#152019, 1-99 d,#0d1410, +|23: 0-0 d,#608269, 1-6 d,#0d1410, 7-99 #e5eee5,#0d1410, +|24: 0-0 d,#608269, 1-1 d,#0d1410, 2-2 #f1a39b,#302b25,b 3-10 #f1a39b,#302b25, 11-99 #b8d88a,#302b25, +|25: 0-0 d,#608269, 1-1 d,#0d1410, 2-2 #b6ce94,#263025,b 3-10 #b6ce94,#263025, 11-99 #b8d88a,#263025, +|26: 0-0 d,#608269, 1-1 d,#0d1410, 2-2 #b6ce94,#263025,b 3-10 #b6ce94,#263025, 11-99 #b8d88a,#263025, +|27: 0-0 d,#608269, 1-6 d,#0d1410, 7-99 #e5eee5,#0d1410, +|28: 0-0 d,#608269, 1-2 d,#0d1410, 3-99 #e5eee5,#0d1410, +|29: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410, +|30: 0-0 d,#152019, 1-99 d,#0d1410, diff --git a/test/snapshots/diffview.snap b/test/snapshots/diffview.snap new file mode 100644 index 00000000..b5900db9 --- /dev/null +++ b/test/snapshots/diffview.snap @@ -0,0 +1,27 @@ +# A diff pane, for reviewing a change: each hunk's code coloured as Zig (a +# multi-line string over three lines, `defer` inside it no keyword), added and +# removed rows tinted to the pane's edge with their prefix in the tint's hue, +# headers muted. +dirmk .git +dirmk src +file src/shape.zig const std = @import("std");\n\npub const Shape = union(enum) {\n circle: f32,\n square: f32,\n triangle: struct { base: f32, height: f32 },\n\n const note =\n \\\\areas, defer\n \\\\summed\n ;\n};\n +file change.diff diff --git a/src/shape.zig b/src/shape.zig\nindex 1111111..2222222 100644\n--- a/src/shape.zig\n+++ b/src/shape.zig\n@@ -1,10 +1,12 @@\n const std = @import("std");\n \n pub const Shape = union(enum) {\n circle: f32,\n- square: u8 = 7,\n+ square: f32,\n+ triangle: struct { base: f32, height: f32 },\n \n const note =\n- \\\\areas\n+ \\\\areas, defer\n+ \\\\summed\n ;\n };\n +start 31 100 change.diff +wait 8000 Newcol Joincol +stable 700 20000 +snap diff-pane +snapstyle diff-colours +# The same diff printed by a command (`git diff`, here `cat`) into a command +# pane: its output is told for a diff and coloured the same, over the colours +# the program printed. +file cmds.txt cat change.diff\n +start 31 100 cmds.txt +wait 8000 cmds.txt +stable 700 20000 +press middle 7 4 +drag middle 22 4 +release middle 22 4 +wait 10000 exit 0 +stable 700 15000 +snap command-pane +snapstyle command-colours |
