k9
k9 copied to clipboard
[WIP] Preliminary prototype for collapsed output
Usecase: Difference between two structs.
Assertion: assert_equal
Current Output:
Collapsed Output:
Method: String Iteration
Implementation:
- Computed the index of each occurrence with reference to (
-
or+
).// [4, 5, 16, 17, 20, 21]
- I have a
cur_index
and apeek_index
. - If the difference between
cur_index
andpeek_index
is<= 5
, I'll have those index and the intermediate values in the final collapsed output else I have a...
.// [4, 5, 16, 17, 18, 19, 20, 21]
might wanna have some more context around the changes and some hints around how much you skipped:
A {
a: "Kelly"
... 20 lines hidden
b: "blah blah"
- c: 1
+ c: 2
d: 4
... 20 lines hidden
}
also. for the algorithm you probably want to do it at the same time you're constructing by keeping the unchanged_count
counter as you're iterating through the diff, so you do everything in one pass.
you might need some lookahead for that
Yeah! I'm planning to do those things as well. As I said, this is a prelim first implementation prototype. I'll do that and let you know. :D Thanks!!
Sure. I'll optimize the approach. So, can I proceed with the lookahead approach and extend it? I'll reply to this thread with the outcome of this ASAP. :D
also, we should probably have some threshold. if i'ts lass than 30 lines we don't collapse anything
Yeah!
Update:
I found a way to collapse the output with single iteration.(Sorry about the colors, Need to find a way to put em back :P)
Currently working on adding context to the diff. :))
Ok, I integrated colored_diff
with my logic for collapsing large output. It's so far so good.
What'll I do next?
- Going to write a lot of test cases.
- If all good, Implement into the library as a feature and submit for review
Here are some of the results:
Struct diff
Vector diff
Thanks, @aaronabramov :D
you might want some padding/context around changed lines!
right now you have
- 20
+ 3
... 10 lines collapsed
you probably want
- 20
+ 3
4 // unchanged line
5 // unchanged line
... 10 lines collapsed
also need to find a good way to distinguish ... 10 lines collapsed
from the acutual content. they're both grayed out right now :)
Noted! :D
PR: https://github.com/aaronabramov/k9/pull/61