sharkdp / hexyl

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

Incorrect output when reading from terminal #196

Closed Aaron-Rumpler closed 11 months ago

Aaron-Rumpler commented 1 year ago

Hexyl is giving incorrect output in some cases when reading terminal input. I've seen it when the input has multiple newlines at the end. The input of Test[Enter][Enter][Enter][Enter][CTRL-D] is one such case:

❯ hexyl
Test

┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐
│00000000│ 54 65 73 74 0a 0a 00 00 ┊ 00 00 00 00 00 00 00 00 │Test__⋄⋄┊⋄⋄⋄⋄⋄⋄⋄⋄│
│00000010│ 0a 0a 73 74 0a 0a 00 00 ┊ 00 00 00 00 00 00 00 00 │__st__⋄⋄┊⋄⋄⋄⋄⋄⋄⋄⋄│
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘

I've been able to track it back to 15e8abfc9afe95a221c9c9a265cf3fb58fed0470 through 5f82942f98fc69af8f76701715053aee2451d62c, with it being introduced in that set of changes.

Aaron-Rumpler commented 1 year ago

I should probably mention I tested this on macOS 13.4 and tried from both Bash and ZSH in both iTerm2 and Terminal. Neither hexdump or commits before 15e8abfc9afe95a221c9c9a265cf3fb58fed0470 exhibit the issue.

sharifhsn commented 1 year ago

I can reproduce this issue on Linux. I'll take a look at it today, thanks for raising an issue!