--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:
This stays consistent with current behavior -- the final display offset retains its concept as "--skip + --display-offset".
This adds an error case for the display offset underflowing when added to the unsigned --skip offset:
hexyl --display-offset=-21 --skip 20 .\some_file
Error: invalid value when applying `--display-offset` to `--skip`
Caused by:
base (20) - offset (21) < 0
Bonus: the error case where offset addition overflows now has a nice diagnostic:
TODO
If --skip is not specified, it is an error, as before:
Error: failed to parse `--display-offset` arg "-1" as byte count
Caused by:
negative offset specified, but only positive offsets (counts) are accepted in this context
Resolves #112.
PR checklist:
[ ] Get deets from PR OP into commit messages for history's sake.
--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.xxd
desired, made an offset of--skip
in #119.--skip
.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:--skip
.--skip
is specified; underflow results in an error.More detailed overview of the design and rationale:
This stays consistent with current behavior -- the final display offset retains its concept as "
--skip
+--display-offset
".This adds an error case for the display offset underflowing when added to the unsigned
--skip
offset:Bonus: the error case where offset addition overflows now has a nice diagnostic:
If
--skip
is not specified, it is an error, as before:Resolves #112.
PR checklist: