forked from chrisboulton/php-diff
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #64 - maxLineMarkerWidth only calculated for input format plain.
- Calculation of maxLineMarkerWidth independent of input format. - Second parameter of string repeat function minimizes to 0. - Code cleanup.
- Loading branch information
DigiLive
authored and
DigiLive
committed
Oct 13, 2020
1 parent
836b128
commit c5f6d72
Showing
2 changed files
with
53 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,12 +13,12 @@ | |
* | ||
* PHP version 7.2 or greater | ||
* | ||
* @package jblond\Diff\Renderer\Text | ||
* @author Ferry Cools <[email protected]> | ||
* @package jblond\Diff\Renderer\Text | ||
* @author Ferry Cools <[email protected]> | ||
* @copyright (c) 2020 Ferry Cools | ||
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php | ||
* @version 2.2.1 | ||
* @link https://github.com/JBlond/php-diff | ||
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php | ||
* @version 2.2.1 | ||
* @link https://github.com/JBlond/php-diff | ||
*/ | ||
class InlineCli extends MainRenderer implements SubRendererInterface | ||
{ | ||
|
@@ -31,7 +31,7 @@ class InlineCli extends MainRenderer implements SubRendererInterface | |
/** | ||
* InlineCli constructor. | ||
* | ||
* @param array $options Custom defined options for the inline diff renderer. | ||
* @param array $options Custom defined options for the inline diff renderer. | ||
* | ||
* @see Inline::$subOptions | ||
*/ | ||
|
@@ -67,7 +67,7 @@ public function generateDiffHeader(): string | |
/** | ||
* Generate a string representation of the start of a block. | ||
* | ||
* @param array $changes Contains the op-codes about the changes between two blocks of lines. | ||
* @param array $changes Contains the op-codes about the changes between two blocks of lines. | ||
* | ||
* @return string Start of the diff view. | ||
*/ | ||
|
@@ -89,14 +89,17 @@ public function generateSkippedLines(): string | |
/** | ||
* Generate a string representation lines without differences between the two versions. | ||
* | ||
* @param array $changes Contains the op-codes about the changes between two blocks of lines. | ||
* @param array $changes Contains the op-codes about the changes between two blocks of lines. | ||
* | ||
* @return string Text with no difference. | ||
*/ | ||
public function generateLinesEqual(array $changes): string | ||
{ | ||
$returnValue = ''; | ||
$padding = str_repeat(' ', $this->maxLineMarkerWidth - strlen($this->options['equalityMarkers'][0])); | ||
$padding = str_repeat( | ||
' ', | ||
max($this->maxLineMarkerWidth - strlen($this->options['equalityMarkers'][0]), 0) | ||
); | ||
|
||
foreach ($changes['base']['lines'] as $line) { | ||
$returnValue .= $this->options['equalityMarkers'][0] . $padding . '|' . $line . "\n"; | ||
|
@@ -108,15 +111,18 @@ public function generateLinesEqual(array $changes): string | |
/** | ||
* Generate a string representation of lines that are added to the 2nd version. | ||
* | ||
* @param array $changes Contains the op-codes about the changes between two blocks of text. | ||
* @param array $changes Contains the op-codes about the changes between two blocks of text. | ||
* | ||
* @return string Added text. | ||
*/ | ||
public function generateLinesInsert(array $changes): string | ||
{ | ||
$colorize = new CliColors(); | ||
$returnValue = ''; | ||
$padding = str_repeat(' ', $this->maxLineMarkerWidth - strlen($this->options['insertMarkers'][0])); | ||
$padding = str_repeat( | ||
' ', | ||
max($this->maxLineMarkerWidth - strlen($this->options['insertMarkers'][0]), 0) | ||
); | ||
|
||
foreach ($changes['changed']['lines'] as $line) { | ||
if ($this->options['cliColor']) { | ||
|
@@ -132,15 +138,18 @@ public function generateLinesInsert(array $changes): string | |
/** | ||
* Generate a string representation of lines that are removed from the 2nd version. | ||
* | ||
* @param array $changes Contains the op-codes about the changes between two blocks of text. | ||
* @param array $changes Contains the op-codes about the changes between two blocks of text. | ||
* | ||
* @return string Removed text. | ||
*/ | ||
public function generateLinesDelete(array $changes): string | ||
{ | ||
$colorize = new CliColors(); | ||
$returnValue = ''; | ||
$padding = str_repeat(' ', $this->maxLineMarkerWidth - strlen($this->options['deleteMarkers'][0])); | ||
$padding = str_repeat( | ||
' ', | ||
max($this->maxLineMarkerWidth - strlen($this->options['deleteMarkers'][0]), 0) | ||
); | ||
|
||
foreach ($changes['base']['lines'] as $line) { | ||
if ($this->options['cliColor']) { | ||
|
@@ -156,7 +165,7 @@ public function generateLinesDelete(array $changes): string | |
/** | ||
* Generate a string representation of lines that are partially modified. | ||
* | ||
* @param array $changes Contains the op-codes about the changes between two blocks of text. | ||
* @param array $changes Contains the op-codes about the changes between two blocks of text. | ||
* | ||
* @return string Modified text. | ||
*/ | ||
|
@@ -179,10 +188,10 @@ public function generateLinesReplace(array $changes): string | |
/** | ||
* Merge the changes between two lines together and mark these changes. | ||
* | ||
* @param array $baseLines Lines of version 1. | ||
* @param array $changedLines Lines of version 2. | ||
* @param array|null[] $deleteColors Fore- and background colors of part that is removed from the 2nd version. | ||
* @param array|null[] $insertColors Fore- and background colors of part that is added to the 2nd version. | ||
* @param array $baseLines Lines of version 1. | ||
* @param array $changedLines Lines of version 2. | ||
* @param array|null[] $deleteColors Fore- and background colors of part that is removed from the 2nd version. | ||
* @param array|null[] $insertColors Fore- and background colors of part that is added to the 2nd version. | ||
* | ||
* Option $deleteColors and $insertColors only have affect when this class's cliColors option is set to true. | ||
* | ||
|
@@ -194,7 +203,11 @@ private function mergeChanges( | |
array $deleteColors = [null, null], | ||
array $insertColors = [null, null] | ||
): array { | ||
$padding = str_repeat(' ', $this->maxLineMarkerWidth - strlen($this->options['equalityMarkers'][1])); | ||
$padding = str_repeat( | ||
' ', | ||
max($this->maxLineMarkerWidth - strlen($this->options['equalityMarkers'][1]), 0) | ||
); | ||
|
||
if ($this->options['cliColor']) { | ||
$colorize = new CliColors(); | ||
} | ||
|
@@ -233,7 +246,7 @@ private function mergeChanges( | |
/** | ||
* Generate a string representation of the end of a block. | ||
* | ||
* @param array $changes Contains the op-codes about the changes between two blocks of text. | ||
* @param array $changes Contains the op-codes about the changes between two blocks of text. | ||
* | ||
* @return string End of the block | ||
*/ | ||
|