Create the side-by-side option (-y) feature for the diff command (Incomplete) #117
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Create the function, in the utils package, limited_string that allows you to truncate a string based on a delimiter (May break the encoding of the character where it was cut)
Create tests for limited_string function
Add support for -y and --side-by-side flags that enables diff output for side-by-side mode
Create implementation of the diff -y (SideBySide) command, base command for sdiff, using the crate diff as engine. Currently it does not fully represent GNU diff -y, some flags (|, (, ), , /) could not be developed due to the limitation of the engine we currently use (crate diff), which did not allow perform logic around it. Only the use of '<' and '>' were enabled.
Create tests for SideBySide implementation
TL;DR
A new limited_string function was added to the utils package, allowing strings to be truncated based on a delimiter (note: this may break character encoding at the cut point). Unit tests were created to ensure correct behavior of the function.
Support for the -y and --side-by-side flags was added to enable side-by-side diff output. The SideBySide implementation, serving as the base for the sdiff command, was developed using the diff crate as the comparison engine. Due to limitations of the crate, only the < and > markers are currently supported—other markers like |, (, ),\ and / could not be implemented.
Tests were also created to validate the behavior of the SideBySide mode.
Clarification
The main goal of the
limited_string
function is to simplify and standardize the process of truncating strings for everyone working on the project. The idea was to provide a utility that anyone could use without having to reimplement or worry too much about string manipulation logic. However, a known limitation of the current implementation is that it can break character encoding, especially when the cut happens mid-way through a multi-byte character (e.g., in UTF-8).I am open to suggestions on how to improve or safely handle encoding, whether by detecting boundaries or using a safer string-splitting strategy that respects character integrity.
Regarding the SideBySide implementation: I recognize that the output and edit script provided by the diff crate is limited. These limitations currently prevent us from supporting additional characters such as |, (, ), , or / that are used in GNU
diff -y
to more accurately reflect changes in lines.For this initial version, I think the use of < and >, are sufficient for a first pass of side-by-side comparison. Moving forward, I did like to open a follow-up issue where we can evaluate better strategies (possibly even considering another diff engine) to handle richer diff representations and support for the missing symbols.
Suggestions and ideas are very welcome!