Skip to content
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

df: fix incorrect whitespace between columns #3386

Merged
merged 1 commit into from
Apr 18, 2022

Conversation

cakebaker
Copy link
Contributor

@cakebaker cakebaker commented Apr 11, 2022

The main idea behind this PR is to introduce a Table struct to print a table. The print process now consists of two steps: 1) calculate the widths of the columns and 2) print the data.

Header and DisplayRow (which has been renamed to RowFormatter (I'm not sure about this name, I struggled to find a name for it)) no longer do any output, they simply prepare the strings used by the table.

Fixes #3194.

@cakebaker cakebaker force-pushed the ticket_3194 branch 2 times, most recently from c0ed20a to 73e472b Compare April 12, 2022 08:11
@tertsdiepraam
Copy link
Member

Super cool! It'd be interesting to find similar cases in other utils and put this functionality in uucore (after this PR of course). There are plenty of utils that have some table-like format (ls and wc come to mind).

src/uu/df/src/table.rs Outdated Show resolved Hide resolved
"c "
]
);
assert_eq!(actual, vec!["File", "a ", "b ", "c "]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is certainly an improvement but it doesn't quite match the behavior of GNU. The last column in the table does not have trailing spaces.

This is certainly an improvement so I'm okay with merging this as-is, but just bringing it up as another opportunity to improve the output of df.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I think you misread the snippet above. It contains a single column with a header and three values. And the trailing spaces are there because those values are shorter than the header.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I understand. When I said "the last column" I should have said "the last and only column in this test case". What I meant is that in GNU df there are no trailing spaces in the rightmost column of the output table:

$ touch a && df --output=file a | tr " " "_"
File
a

But in this branch there are trailing spaces:

$ touch a && ./target/debug/df --output=file a | tr " " "_"
File
a___

I'm okay with it, I just wanted to mention it as a follow-up improvement for a future pull request.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation, that makes sense.

@sylvestre
Copy link
Contributor

Could you please fix the conflict? thanks

Copy link
Member

@tertsdiepraam tertsdiepraam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two small nits/questions, but looks good!

src/uu/df/src/columns.rs Outdated Show resolved Hide resolved
src/uu/df/src/table.rs Show resolved Hide resolved
@tertsdiepraam
Copy link
Member

Excellent work!

@tertsdiepraam tertsdiepraam merged commit ae24ca4 into uutils:main Apr 18, 2022
@cakebaker cakebaker deleted the ticket_3194 branch April 18, 2022 09:33
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.

df: incorrect whitespace between columns in output table
4 participants