[feat] Support justify alignment #168
Merged
+186
−77
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.
This PR adds the justify alignment feature (#167). The solution is to calculate the number array of adding spaces, which has a length that is equal to the number of continuous space sequences and has a sum is equal to the available width. To be prettier, the array should be a non-decreasing one, and the difference between the maximum and minimum value is not greater than 1.
Example with total width = 10:
The issue is when the string is too short (e.g., the last line of a paragraph), I propose to fallback to left align if we have to add more than 03 spaces in one place (instead of calculating more information about the surrounding lines). So:
Here is the demo from moonMission file with justify the last column:
