-
-
Notifications
You must be signed in to change notification settings - Fork 237
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
Adds --columns for Print using custom width #13 #164
Conversation
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.
Fixes previous pull request by running cargo fmt
.
I have a pull request ready for terminal width, but it requires adding the |
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 very much. Works great!
Does this have any impact on performance? (see e.g. #66 (comment) on how to perform hexyl
benchmarks using hyperfine
)
No, I'll do that now. I couldn't find a benchmark harness before, thank you for pointing me to it. |
We should probably add a script with a few useful benchmarks, true. For this PR (or in general), I would suggest to use something like: #!/bin/bash
dd if=/dev/urandom bs=1M count=1 of=/tmp/data
hyperfine \
--warmup 3 \
--shell=none \
--output=pipe \
--export-markdown=result-pipe.md \
'hexyl /tmp/data'
hyperfine \
--warmup 3 \
--shell=none \
--output=inherit \
--export-markdown=result-inherit.md \
'hexyl /tmp/data'
rm /tmp/data Here, we use |
You can also create two binaries, hyperfine \
--warmup 3 \
--shell=none \
--output=pipe \
--parameter-list version master,feature
--export-markdown=result-pipe.md \
'./hexyl-{version} /tmp/data' to see the direct comparison. |
These are my results using 1 MB of It seems as though for the default width of two columns the new version is slightly slower, but within noise for the benchmark. With more columns it's much faster, but that of course makes sense since it's writing fewer lines. |
Co-authored-by: David Peter <[email protected]>
One more thing; I've implemented |
I've added the terminal width setting, so this should completely close #13. |
I wanted to remark this in my first review but didn't want to be overly annoying 😄. In my personal experience: trying to use size-limited (unsigned) integers (u8, u16, i8, i16) in places which are not size- or performance critical is almost always a mistake. It's usually meant as a (premature) optimization. But the reality is that it (1) leads to more errors due to overflows (2) leads to more complicated code due to more explicit casts between 8-bit, 16-bit and 32-bit numbers and (3) doesn't even necessarily generate faster code (because if they are not closely packed, we can't really make use of them) or smaller data structs (due to alignment mismatches). So personally, for a single parameter, I would never mind trying to go for a small integer type and simply go with a 32-bit integer, or even |
Feel free to bump the min. supported Rust version if that causes problems. |
Concerning the newly added options: Would it be possible to scratch Also, I think
Does it? I believe the issue also asks for custom widths that would not be multiples of 16. Like if you have some data structure with elements that are 14 byte long. Then you might want to specify |
Thank you for saying this! I am quite new to Rust so I appreciate the advice. Making it a |
src/lib.rs
Outdated
@@ -164,6 +166,7 @@ impl<'a, Writer: Write> Printer<'a, Writer> { | |||
show_position_panel: bool, | |||
border_style: BorderStyle, | |||
use_squeeze: bool, | |||
columns: u8, |
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 a breaking change for hexyl
-as-a-library. This whole new
method is really unfortunate. There are too many arguments even before this PR. We should really use a builder-pattern instead.
But that's not really the problem of your PR.
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.
I would be willing to work on implementing a builder pattern if you're committed to pushing a breaking change anyway.
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.
I have a commit ready for a builder pattern. It uses a new PrinterBuilder
struct, so it can technically be implemented in a non-breaking way, although that's probably undesirable. It's quite out of scope for this pull request, so I'll submit a new one once this one is approved.
Of course.
I was only going off of the original issue's suggestions. The use case for
Ah, I wasn't aware that was in the scope of the original issue. That would probably require a more significant rewrite. |
That's okay. Let's focus on |
Ok, I think I misunderstood the initial issue. The custom number of columns refers to the individual columns, whereas my pull request focuses on customizing the number of panels. With that in mind, I think I should rename A future change that customizes columns per panel would therefore be able to slot into this change better. |
Another option would be to leave the option name as is, but change the meaning. And then for this PR, we only allow |
I think it would be more ergonomic here to have the two options, columns-per-panel and number-of-panels. In my mind, the idea behind variable number columns is to have the panel size itself adjust. With the other option, the panel size would always be 8 bytes, and a future ability to have e.g. It would be better to set |
You are right. Let's change the command line option name then 👍🏼 |
@sharkdp I think we can declare this PR complete? I don't see any other roadblocks. |
That would be great! If we do that, I would make that a breaking change, i.e. remove the old
Yes. Looks great. Two things: the inline comment regarding the short options. And it would be great if you could add a CHANGELOG entry in the "unreleased" section. The format for entries is:
where |
Thank you! |
This pull request fixes #13 partially by adding the
--columns
option to manually set the number of columns. The default is 2 as with previous behavior.Some notes:
-w
not-c
as that option is already reserved for--bytes
cargo test