sharkdp / hexyl

A command-line hex viewer
Apache License 2.0
8.92k stars 227 forks source link

Allow negative values for `--display-offset` #145

Closed ErichDonGubler closed 1 year ago

ErichDonGubler commented 2 years ago

--display-offset has had an odd relationship with negated inputs over its lifetime. Historical behaviors (and the addition being proposed here) might be easiest to understand in a tabular format.

When Behavior summary Negative offset behavior
First implemented in #72. Absolute position, positive values only. Disallowed.
Refined to allow negatives in #99. Absolute position, including then-new semantics for negatives. Allowed, end offset backwards from EOF (and so only usable on files), prompting #112 for poor diagnostics at the time.
Actual compatibility with xxd desired, made an offset of --skip in #119. Relative offset based on --skip. Disallowed.

This PR proposes to make negative values for --display-offset meaningful again by allowing them again when --skip is specified, adding a negative value to --skip if provided. To use the same format as above:

When Behavior summary Negative offset behavior
This PR. Relative offset based on --skip. Allowed when --skip is specified; underflow results in an error.

More detailed overview of the design and rationale:

Resolves #112.


PR checklist:

sharkdp commented 2 years ago

Sounds great. Thank you very much for looking into this.

sharkdp commented 1 year ago

I'm closing this due to inactivity. Please feel free to comment in case it should be re-opened.