Skip to content

Commit 6877a91

Browse files
authored
Pretty diff design.
1 parent cf1346f commit 6877a91

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/SimpleDiff.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ public function compare(string $left, string $right, bool $strict = false): Diff
1717
$return = [];
1818
$from = explode("\n", $left);
1919
$to = explode("\n", $right);
20+
$padLength = strlen((string) max(count($from), count($to)));
2021
$changedLines = [];
2122

2223
for ($i = 0; isset($from[$i]); $i++) {
2324
$original = $from[$i] ?? '';
2425
$target = $to[$i] ?? '';
25-
$lineNumber = str_pad(($i + 1) . ':', 6, ' ') . ' ';
26+
$lineNumber = str_pad((string) ($i + 1), $padLength, ' ', STR_PAD_LEFT) . '| ';
2627
if ($original === $target) {
27-
$return[] = $lineNumber . ' ' . $original;
28+
$return[] = ' ' . $lineNumber . $original;
2829
} else {
2930
$return[] = '- ' . $lineNumber . $this->prettyRender($original);
3031
$return[] = '+ ' . $lineNumber . $this->prettyRender($target);

0 commit comments

Comments
 (0)