-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix(ptx): Align text wrapping behavior with GNU in traditional mode #8820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
GNU testsuite comparison: |
CodSpeed Performance ReportMerging #8820 will not alter performanceComparing Summary
Footnotes
|
src/uu/ptx/src/ptx.rs
Outdated
| context_regex: String, | ||
| line_width: usize, | ||
| gap_size: usize, | ||
| max_ref_len: usize, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason for adding max_ref_len as a property of Config? It's used in a single place in write_traditional_output and it looks like you could use a local var instead. Maybe I'm missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review and good question!
The reason I added max_ref_len as a Config property is that I’m preparing for the upcoming GNU-extension mode — I plan to use this max_ref_len in the code where I implement the GNU-extension logic later. I wanted to set it up in advance to keep the code structure consistent once that mode is added.
But I’m not entirely sure if this is the right approach. Should I instead remove max_ref_len from Config for now, and just use a local variable in write_traditional_output until the GNU-extension mode is actually implemented? I’d appreciate your thoughts on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your feedback—I have changed it to use a local variable as you suggested.
|
sorry but why did you add screenshots ? they duplicate the information no? |
No worries at all—great point! I added the screenshots mainly because I thought visualizing the output (like the aligned text or diff results) would make the context more intuitive and easier to follow at a glance, especially for showing formatting details that might feel abstract in plain text. |
…nd add related test In traditional mode (-G) with references enabled, `uutils/ptx` failed to wrap long lines in the same way as the GNU `ptx` reference implementation. This was due to the layout algorithm operating on an incorrectly large line width, as the space for the reference column was not being subtracted from the total width budget. This commit implements the correct line width adjustment by subtracting the reference width. This aligns the wrapping behavior and makes the output identical to GNU `ptx` for the tested cases.
0dc061f to
4b11638
Compare
|
GNU testsuite comparison: |
|
Thanks! |
Summary
This PR fixes a layout bug in
ptx's traditional mode (-G). When references are enabled, the available line width was not being correctly adjusted, causing text wrapping to be inconsistent with the GNUptxreference implementation.The Bug
In traditional mode with references (
-G -A), GNUptxperforms text wrapping on long lines. Theuutilsimplementation failed to replicate this behavior because it was not correctly reducing the available line width to account for the space occupied by the reference column.This resulted in an overly large layout budget, which prevented wrapping and produced output that was inconsistent with GNU
ptx.Changes Made
config.line_widthwhen references are enabled in traditional mode. This provides the correct layout budget to the text chunking algorithm.GNU (Correct edition)
Before fix
After fix