-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Conversation
c0ed20a
to
73e472b
Compare
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 ( |
"c " | ||
] | ||
); | ||
assert_eq!(actual, vec!["File", "a ", "b ", "c "]); |
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.
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
.
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.
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.
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.
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.
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 explanation, that makes sense.
Could you please fix the conflict? thanks |
e59f219
to
df78d86
Compare
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.
Two small nits/questions, but looks good!
Excellent work! |
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
andDisplayRow
(which has been renamed toRowFormatter
(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.