Change hex dump output format to match hexdump -C

This commit is contained in:
dgelessus 2019-09-13 10:51:27 +02:00
parent b2fa5f8b0f
commit 194c886472
2 changed files with 4 additions and 3 deletions

View File

@ -130,7 +130,7 @@ Changelog
Version 1.2.1 (next version)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* Changed ``--format=dump`` output to collapse multiple subsequent identical lines into a single ``*``.
* Changed ``--format=dump`` output to match ``hexdump -C``'s format - spacing has been adjusted, and multiple subsequent identical lines are collapsed into a single ``*``.
Version 1.2.0
^^^^^^^^^^^^^

View File

@ -166,9 +166,10 @@ def _hexdump(data: bytes):
print("*")
asterisk_shown = True
else:
line_hex = " ".join(f"{byte:02x}" for byte in line)
line_hex_left = " ".join(f"{byte:02x}" for byte in line[:8])
line_hex_right = " ".join(f"{byte:02x}" for byte in line[8:])
line_char = line.decode(_TEXT_ENCODING).translate(_TRANSLATE_NONPRINTABLES)
print(f"{i:08x} {line_hex:<{16*2+15}} |{line_char}|")
print(f"{i:08x} {line_hex_left:<{8*2+7}} {line_hex_right:<{8*2+7}} |{line_char}|")
asterisk_shown = False
last_line = line