sahilm/yamldiff

Print lines that are the same?

Closed this issue · 6 comments

Hello!
Thanks for the tool! It proved to more or less be a lifesaver for a thing I'm working on. However, wanted to ask...
I'm not familiar with Go myself, whatsoever, so how hard would it be to make so that the tool works like a GitHub-style diff? (i.e., not only displays lines that are different with a + or a -, but also displays lines that are the same)
If you could do that, I would be extremely thankful! Provided it's not as hard as I think it may be.

You're looking for something like

diff --git a/main.go b/main.go
index ea7fb6c..2542513 100644
--- a/main.go
+++ b/main.go
@@ -101,6 +101,8 @@ func computeDiff(formatter aurora.Aurora, a interface{}, b interface{}) string {
                        diffs = append(diffs, formatter.Bold(formatter.Green(s)).String())
                case strings.HasPrefix(s, "-"):
                        diffs = append(diffs, formatter.Bold(formatter.Red(s)).String())
+               default:
+                       diffs = append(diffs, s)
                }
        }
        return strings.Join(diffs, "\n")

Sorry for getting back after a million years. I'll work on this in a day or two.

Eh, don't sweat it. I've found a different thing.

Just curious. What's the different thing you found?

https://github.com/rtfpessoa/diff2html
I'm developing something. Way back when I wrote this thought I could perhaps use yamldiff's output to process it and create an HTML diff output, but then turns out someone else has already done all of that before me.