New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alternative diff output #263
Comments
@morgante Not sure I'll be able to help too much on this one as it might be a bit more heft than I can handle at this point. Here's what I've been able to find so far regarding this issue though. From what I've found Delta works by parsing the output of a stream. If we choose to get things working with other pagers such as Delta then we need to (or at least ned to have the option to) output contents the same as git diff filename.txt | delta Starting with the output of diffs, we can compare our output to that of git. diff --git a/package.json b/package.json
index 2b3133b..af4a1f8 100644
--- a/package.json
+++ b/package.json
@@ -1,5 +1,5 @@
{
- "name": "@getgrit/gritql",
+ "name": "DELETE_ME",
"version": "0.2.2",
"description": "Core GritQL engine and CLI",
"author": "", For readability we need at least the following
Let's compare this with our current output
It's fine to keep the message at the end of the diff. It doesn't start with Now, taking a look at match outputs as a grep format, Delta expects an output formatted like { "type": "begin", "data": { "path": { "text": "package.json" } } },
{
"type": "context",
"data": {
"path": { "text": "package.json" },
"lines": { "text": "{\n" },
"line_number": 1,
"absolute_offset": 0,
"submatches": []
}
},
{
"type": "match",
"data": {
"path": { "text": "package.json" },
"lines": { "text": " \"name\": \"DELETE_ME\",\n" },
"line_number": 2,
"absolute_offset": 2,
"submatches": [
{ "match": { "text": "DELETE_ME" }, "start": 11, "end": 20 }
]
}
},
// ...more match/context blocks
{
"type": "end",
"data": {
"path": { "text": "grep-example.txt" },
"binary_offset": null,
"stats": {
"elapsed": { "secs": 0, "nanos": 1656401, "human": "0.001656s" },
"searches": 1,
"searches_with_match": 1,
"bytes_searched": 1260,
"bytes_printed": 1736,
"matched_lines": 1,
"matches": 2
}
}
},
// ...more start/end blocks with match/context blocks between
{
"data": {
"elapsed_total": { "human": "2.397146s", "nanos": 397145746, "secs": 2 },
"stats": {
"bytes_printed": 2477,
"bytes_searched": 1710,
"elapsed": { "human": "0.003502s", "nanos": 3502102, "secs": 0 },
"matched_lines": 2,
"matches": 3,
"searches": 2,
"searches_with_match": 2
}
},
"type": "summary"
} From messing with this output, it seems the only thing we can omit is the following
ApproachesThere a many ways we could approach this, and we might want to discuss the most appropriate method to do this. We would need to update the formatter to match
Caveats
|
Thanks for investigating this! Overall, I think I like the option of starting with an Once that's implemented, we could consider an
Do you mean that |
Yeah what I mean is that we can't mix diffs and grep outputs together. Each type would have to be processed by delta separately. |
Some users like to customize their
git diff
output.In theory,
grit apply
is very similar and we should be able to hook into a pluggable diff output format. Ex. ripgrep seems to work with delta here: https://dandavison.github.io/delta/grep.htmlThe text was updated successfully, but these errors were encountered: