sharkdp / hexyl

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

hexyl -C does the inverse of hexdump -C #187

Closed mrincredibleu closed 1 year ago

mrincredibleu commented 1 year ago

hexyl -C does not show a character panel to the right of the hex output while hexdump -C does.

$ echo "hello world" | /usr/bin/hexdump -C
00000000  68 65 6c 6c 6f 20 77 6f  72 6c 64 0a              |hello world.|
0000000c
$ echo "hello world" | hexyl -C
┌────────┬─────────────────────────┬─────────────────────────┐
│00000000│ 68 65 6c 6c 6f 20 77 6f ┊ 72 6c 64 0a             │
└────────┴─────────────────────────┴─────────────────────────┘

Conversely, when using the commands without any flags, hexyldoes show a character panel to the right of the hex output while hexdump does not (This I do understand, since arguably a hex viewer is most useful to a human user with a character panel, therefore showing a character panel should be the default behaviour).

$ echo "hello world" | /usr/bin/hexdump
o0000000 6568 6c6c 206f 6f77 6c72 0a64
000000c
$ echo "hello world" | hexyl
┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐
│00000000│ 68 65 6c 6c 6f 20 77 6f ┊ 72 6c 64 0a             │hello wo┊rld_    │
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘

This behaviour is confusing when hexdump is used as an alias to hexyl (alias hexdump='hexyl --color auto') in an interactive shell. I understand that aliasing hexdump to hexyl may not be smart in all usecases, especially when flags are used with the hexdump alias that are not implemented by hexyl. I personally only really use hexdump -C and would like hexyl -C to do the same thing.

For my own purposes I could implement hexdump as a shell function that inverts the presence of the -C flag before passing its function arguments on to hexyl, but I would prefer to avoid this kind of complexity.

Proposed solution: Change hexyl -C or hexyl --characters to show a character panel and show no character panel with hexyl --no-characters. The behaviour of hexyl with no flags could be inverted to show no character panel as well, in order to match the behaviour of hexdump, though this is a matter of opinion.

$ hexyl --version
hexyl 0.12.0
sharkdp commented 1 year ago

Thank you for reporting this.

Proposed solution: Change hexyl -C or hexyl --characters to show a character panel and show no character panel with hexyl --no-characters.

Agreed. Let's do this.

The behaviour of hexyl with no flags could be inverted to show no character panel as well, in order to match the behaviour of hexdump, though this is a matter of opinion.

I'd rather leave the current default. But with the proposed feature above, you could set alias hexdump="hexyl --no-characters" and then use -C to override it when needed (later options override earlier ones).