From 41f5dd0730666710c84158a81ed0b1dec9043fa7 Mon Sep 17 00:00:00 2001 From: Anton Lydike Date: Thu, 22 Apr 2021 12:48:46 +0200 Subject: [PATCH] better ascii dumps --- riscemu/helpers.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/riscemu/helpers.py b/riscemu/helpers.py index ecd8019..922f860 100644 --- a/riscemu/helpers.py +++ b/riscemu/helpers.py @@ -78,8 +78,8 @@ def highlight_in_list(items, hi_ind): return " ".join([apply_highlight(item, i, hi_ind) for i, item in enumerate(items)]) -def format_bytes(bytes, fmt, group=1, highlight=-1): - chunks = create_chunks(bytes, group) +def format_bytes(byte_arr: bytearray, fmt: str, group: int = 1, highlight: int = -1): + chunks = create_chunks(byte_arr, group) if fmt == 'hex': return highlight_in_list(['0x{}'.format(ch.hex()) for ch in chunks], highlight) if fmt == 'int': @@ -90,5 +90,5 @@ def format_bytes(bytes, fmt, group=1, highlight=-1): return highlight_in_list([('{:0' + spc + 'd}').format(int_from_bytes(ch, unsigned=True)) for ch in chunks], highlight) if fmt == 'ascii': - spc = str(4 * group) - return highlight_in_list([('{:>' + spc + '}').format(ch.decode('ascii')) for ch in chunks], highlight) + print("printing ascii", "".join(chr(b) for b in byte_arr)) + return "".join(repr(chr(b))[1:-1] for b in byte_arr)