Skip to content

Fix Issue #1014 and Improve Header Underline Styling#1185

Open
rly0nheart wants to merge 3 commits intolsd-rs:mainfrom
rly0nheart:fix/1014
Open

Fix Issue #1014 and Improve Header Underline Styling#1185
rly0nheart wants to merge 3 commits intolsd-rs:mainfrom
rly0nheart:fix/1014

Conversation

@rly0nheart
Copy link


TODO

  • Use cargo fmt
  • Add necessary tests
  • Update README (if applicable)
  • Update config sample file in doc/samples (if applicable)
  • Update icon sample file in doc/samples (if applicable)
  • Update color sample file in doc/samples (if applicable)
  • Update man page at lsd/doc/lsd.md (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:

Screenshot From 2026-01-26 03-29-07

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() in src/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 its Alignment enum.

After:

Screenshot From 2026-01-26 03-22-51

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:

cells.push(Cell {
    width: get_visible_width(&block, flags.hyperlink == HyperlinkOption::Always),
    contents: block,
    alignment: Alignment::Left
});

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_1014 to make sure this doesn't regress.

Files Changed

Testing

All 437 tests pass (392 unit + 45 integration).

@rly0nheart rly0nheart requested a review from zwpaper as a code owner January 26, 2026 02:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant