Fix Issue #1014 and Improve Header Underline Styling#1185
Open
rly0nheart wants to merge 3 commits intolsd-rs:mainfrom
Open
Fix Issue #1014 and Improve Header Underline Styling#1185rly0nheart wants to merge 3 commits intolsd-rs:mainfrom
rly0nheart wants to merge 3 commits intolsd-rs:mainfrom
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
TODO
cargo fmtdoc/samples(if applicable)doc/samples(if applicable)doc/samples(if applicable)Description
So I've been working on a similar ls utility myself and I've been taking a lot of inspiration from this project and eza. While poking around the code, I noticed a couple of things that I thought I could 'fix'.
Header Underline Fix
The main thing was the header underlines in long format (
lsd -l --header). Previously, the underlines would stretch across the entire column width with padding, which looked kind of off when you had varying column widths. I thought it made sense for the underline to stay within the bounds of the actual header text, that way, it looks visually even.Before:
Before the initial header underline change, I updated term_grid to 0.2.0, and ran into errors relating to a missing alignment specification, this led me to change the header alignment so text columns (like Name, User, Group) are left-aligned and numeric columns (like Size, Date, INode, Links) are right-aligned. This made it easier to fix the header underline 'problem'.
The fix was in
add_header()insrc/display.rs, so instead of manually padding headers and then underlining the whole thing, I now just underline the header text and let term_grid handle the alignment via itsAlignmentenum.After:
Note
If the wide header underline is intentional, then you should just ignore this bit :)
Issue #1014 Fix
After I made that change, I thought it would be nice to fix an issue from lsd, so I noticed issue #1014.
The root cause was that term_grid 0.2 doesn't automatically strip ANSI escape codes when calculating cell widths. The fix is actually already in the code, when creating cells, we use
get_visible_width()which properly calculates the visible width excluding ANSI codes:This way term_grid gets the correct width (e.g., 6 for "f1.txt") instead of the full string length including escape codes (e.g., 22 for "\x1b[38;5;184mf1.txt\x1b[39m").
Added a test
test_grid_layout_with_colors_issue_1014to make sure this doesn't regress.Files Changed
src/display.rs- Header alignment fix and issue File list is totally vertical if the list doesn't fit into one line unless run with-a#1014 testsrc/flags/blocks.rs- Addedis_numeric()method to determine column alignmentCargo.toml- Updated term_grid to 0.2.0, and once_cell to 1.21Testing
All 437 tests pass (392 unit + 45 integration).