Allow custom rendering of unified diff lines - #2871
Merged
Merged
Conversation
Signed-off-by: HarshPopat23 <musichk61@gmail.com>
HarshPopat23
force-pushed
the
feat/diff-line-writer
branch
from
September 24, 2026 05:25
5f713c4 to
ea22bb7
Compare
🤖 Augment PR SummarySummary: This PR adds per-line customization hooks for unified-diff rendering. Changes:
Technical Notes: The callback is appended to the options aggregate to retain existing source initialization patterns while allowing consumers to apply their own styling policy. 🤖 Was this summary useful? React with 👍 or 👎 |
Contributor
Author
|
PTAL: @jviotti , |
jviotti
approved these changes
Sep 24, 2026
jviotti
left a comment
Member
There was a problem hiding this comment.
Looks great to me! I'll merge and let me upgrade it myself on the CLI in a little bit, as I'm managing other upgrades
Member
Member
|
@HarshPopat23 Upgrade done! Feel free to rebase your other PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add an optional
line_writercallback tosourcemeta::core::Diff::FormatOptionsallowing consumers to customize the rendering of individual unified-diff lines.Background
This enables consumers (such as the JSON Schema CLI's
fmt --checkcommand) to style unified diff lines (e.g. coloring deleted lines red, inserted lines green, hunk headers cyan, etc.) while keeping the Core diff engine decoupled from terminal detection, ANSI escape sequences, and color policy.Details
sourcemeta::core::Diff::FormatOptions::LineTypeenum class:HeaderOriginal(prefix = "--- ",content = <original_label>)HeaderModified(prefix = "+++ ",content = <modified_label>)Hunk(prefix = "@@ ",content = "-<orig> +<mod> @@")Context(prefix = " ",content = <line>)Delete(prefix = "-",content = <line>)Insert(prefix = "+",content = <line>)NoNewline(prefix = "\\ ",content = "No newline at end of file")LineWritercallback type:std::function<void(std::ostream &stream, LineType type, std::string_view prefix, std::string_view content)>.prefix = "@@ ",content = "-<orig> +<mod> @@").\n.line_writertoDiff::FormatOptionspreserves aggregate initialization and designated initializer source compatibility for existing callers.test/diff/diff_line_myers_test.cc.