Skip to content
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

Argument --display-offset overrides position in sidebar, not offsets it. #115

Closed
eth-p opened this issue Oct 27, 2020 · 5 comments · Fixed by #119
Closed

Argument --display-offset overrides position in sidebar, not offsets it. #115

eth-p opened this issue Oct 27, 2020 · 5 comments · Fixed by #119
Labels
bug Something isn't working

Comments

@eth-p
Copy link

eth-p commented Oct 27, 2020

According to the help text, --display-offset should add to the file position sidebar's offset:

    -o, --display-offset <N>    Add N bytes to the displayed file position. The N argument
                                can also include a unit (see `--length` for details)
                                A negative value is valid and calculates an offset
                                relative to the end of the file.

In practice, this is actually not the case. Rather than adding the offset, it sets the offset. That means that when using --display-offset in conjunction with --skip, the usual interactions between --skip and the position are negated entirely. For example:

$ dd if=/dev/urandom bs=16 count=32 2>/dev/null | hexyl --skip=0xFF --display-offset=0x100
┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐
│00000100│ 81 6a 17 0d 78 16 6a 92 ┊ 5c 0e 99 8a bf 50 11 ea │×j•_x•j×┊\•×××P•×│
│00000110│ c4 a8 b8 90 00 93 09 b1 ┊ 6f ee e0 f2 25 2c 44 03 │××××0×_×┊o×××%,D•│
│00000120│ b3 ef 49 d4 00 ca 25 2f ┊ 0d fc e1 8b 85 7d cd 2d │××I×0×%/┊_××××}×-│
│00000130│ 28 2d f2 49 a2 90 d7 5a ┊ 3e 6b 5f ed bf 17 fd ea │(-×I×××Z┊>k_×ו××│
│00000140│ a7 ed 18 93 32 4c e6 e9 ┊ db d8 71 00 52 8b 1e 67 │×ו×2L××┊××q0Rוg│
│00000150│ c3 ba d0 42 2d 5d 37 94 ┊ 5f 25 4e a2 bb 36 f9 c2 │×××B-]7×┊_%N××6××│
│00000160│ cc 77 c4 7e ab 46 a9 01 ┊ dd 06 b9 1b f6 ca 76 9d │×w×~×Fו┊וו××v×│
│00000170│ 46 9c 1c 3b f2 a3 71 4d ┊ 19 51 1d 9a ec b1 c5 37 │Fו;××qM┊•Q•××××7│
│00000180│ 2d c0 0e b0 7b ae cb 33 ┊ a9 e0 08 fb 16 8c 77 a8 │-ו×{××3┊×וו×w×│
│00000190│ 71 2b e9 f1 db 70 5d 42 ┊ de eb 17 82 96 df 9b cb │q+×××p]B┊×ו×××××│
│000001a0│ 20 c4 9f 93 c3 10 ed 23 ┊ 1d c3 aa e0 f1 ef 52 aa │ ×××ו×#┊•×××××R×│
│000001b0│ 01 1c e6 99 b4 84 73 88 ┊ 74 1d d0 53 1c 99 9b c3 │••××××s×┊t•×S•×××│
│000001c0│ 7b e2 5c 63 d9 6e 6f e8 ┊ 36 1b 8f b9 a1 25 54 14 │{×\c×no×┊6•×××%T•│
│000001d0│ 9a 25 41 d4 95 0a 04 71 ┊ bf 9c 11 ab 28 64 5a b2 │×%A××_•q┊×ו×(dZ×│
│000001e0│ 69 13 ff b1 aa ad 67 85 ┊ c9 8d aa 91 6f c7 05 be │i•××××g×┊××××oו×│
│000001f0│ bd 63 14 26 ae 1e 7f 42 ┊ 7a b1 6c b9 b1 c8 4b e9 │×c•&ו•B┊z×l×××K×│
│00000200│ a6                      ┊                         │×       ┊        │
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘

With those arguments, it should have started at 1FF instead of 100.


Note: I'm doing a class assignment regarding creating tests (from scratch) for an open-source command line program, and I chose hexyl for it. You might have a couple more of these on the way, depending on what the assignment brings to light :)

@sharkdp
Copy link
Owner

sharkdp commented Oct 29, 2020

FYI @tommilligan: only if you are interested.. since you implemented --display-offset. Also FYI @ErichDonGubler since you implemented --skip.

@sharkdp sharkdp added the bug Something isn't working label Oct 29, 2020
@ErichDonGubler
Copy link
Contributor

ErichDonGubler commented Oct 30, 2020

Disclaimer: I'm interested in resolving this. Right now, I'm just going to triage things, but I hope to have a solution after I finish researching and put in my vote for my elections as a US resident.

To me, the implemented behavior is desirable, and it's the documentation that should be re-aligned with current behavior -- this looks like docs I missed updating in my PR for --skip. I can go into more detail (and should, since it would be good for a commit message fixing it), but being on mobile doesn't lend well to my long-windedness ATM. :)

@tommilligan
Copy link
Contributor

I think you could argue this both ways if we were implementing the first hex viewer - however, the behaviour pointed out by @eth-p is the behaviour implemented by xxd and I think it's desirable the two should align.

Example: xxd and hexyl run with the same flags, showing different address output:

$ cat LICENSE-MIT | head -n1 | hexyl -s 0x10 -o 0x20
┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐
│00000020│ 72 65 62 79 20 67 72 61 ┊ 6e 74 65 64 2c 20 66 72 │reby gra┊nted, fr│
│00000030│ 65 65 20 6f 66 20 63 68 ┊ 61 72 67 65 2c 20 74 6f │ee of ch┊arge, to│
│00000040│ 20 61 6e 79 20 70 65 72 ┊ 73 6f 6e 20 6f 62 74 61 │ any per┊son obta│
│00000050│ 69 6e 69 6e 67 20 61 20 ┊ 63 6f 70 79 0a          │ining a ┊copy_   │
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘

$ cat LICENSE-MIT | head -n1 | xxd -s 0x10 -o 0x20
00000030: 7265 6279 2067 7261 6e74 6564 2c20 6672  reby granted, fr
00000040: 6565 206f 6620 6368 6172 6765 2c20 746f  ee of charge, to
00000050: 2061 6e79 2070 6572 736f 6e20 6f62 7461   any person obta
00000060: 696e 696e 6720 6120 636f 7079 0a         ining a copy.

@tommilligan
Copy link
Contributor

Opened #119

@sharkdp
Copy link
Owner

sharkdp commented Oct 31, 2020

I think you could argue this both ways if we were implementing the first hex viewer - however, the behaviour pointed out by @eth-p is the behaviour implemented by xxd and I think it's desirable the two should align.

I agree 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants