sebastianbergmann/diff

Diff lines decorator

soullivaneuh opened this issue · 4 comments

The idea is to create a DiffLinesDecorator interface that will be called here:

diff/src/Differ.php

Lines 106 to 112 in 13edfd8

if ($diff[$i][1] === 1 /* ADDED */) {
$buffer .= '+' . $diff[$i][0] . "\n";
} elseif ($diff[$i][1] === 2 /* REMOVED */) {
$buffer .= '-' . $diff[$i][0] . "\n";
} elseif ($this->showNonDiffLines === true) {
$buffer .= ' ' . $diff[$i][0] . "\n";
}

This will permit users to easily customize the diff rendering, like I did here: https://travis-ci.org/sonata-project/dev-kit/builds/127322216#L246

What do you think? I could work on a PR for that.

Hi!

I've recently worked on a fork to allow things like that: https://github.com/nochso/diff
Essentially you pass a Diff object to a renderer. There are basic templates/renderers for HTML, Text and colored POSIX/CLI output.

@nochso Interesting, but why not proposing PR instead of a new package?

The fork and its public API have changed too much. I've mostly kept the original diff/LCS implementation intact, but everything surrounding it has changed.

So I doubt Sebastian would accept that as a simple PR. However I'm open to merging it for a BC-breaking 2.0 release. @sebastianbergmann, what do you think? Are you interested in merging my changes for a 2.0 release or should it live as a separate library?

Anyway, for now I haven't shared or tagged the fork. I'll gladly tag it unless you find some glaring issue so feel free to try it and report back. Right now you'll have to composer require nochso/diff:dev-master

Edit: I've also removed the Parser as it seems out of scope to me.

I would like to keep this component as simple as possible. Therefore, I am afraid that I have to reject this idea. Sorry.