Skip to content

df: fix incorrect whitespace between columns#3386

Merged
tertsdiepraam merged 1 commit intouutils:mainfrom
cakebaker:ticket_3194
Apr 18, 2022
Merged

df: fix incorrect whitespace between columns#3386
tertsdiepraam merged 1 commit intouutils:mainfrom
cakebaker:ticket_3194

Conversation

@cakebaker
Copy link
Copy Markdown
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
Copy Markdown
Collaborator

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).

Comment thread src/uu/df/src/table.rs Outdated
Comment thread tests/by-util/test_df.rs Outdated
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

Could you please fix the conflict? thanks

@cakebaker cakebaker force-pushed the ticket_3194 branch 2 times, most recently from e59f219 to df78d86 Compare April 15, 2022 07:14
Copy link
Copy Markdown
Collaborator

@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!

Comment thread src/uu/df/src/columns.rs Outdated
Comment thread src/uu/df/src/table.rs Outdated
@tertsdiepraam
Copy link
Copy Markdown
Collaborator

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