add color support to over.core.misc.hexdump
This commit is contained in:
parent
67f8840539
commit
9f162f8928
1 changed files with 8 additions and 2 deletions
10
core/misc.py
10
core/misc.py
|
@ -8,6 +8,8 @@ import math
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from . import text
|
||||||
|
|
||||||
# --------------------------------------------------
|
# --------------------------------------------------
|
||||||
|
|
||||||
def import_module(path):
|
def import_module(path):
|
||||||
|
@ -88,7 +90,7 @@ def debugger():
|
||||||
|
|
||||||
# --------------------------------------------------
|
# --------------------------------------------------
|
||||||
|
|
||||||
def hexdump(data, indent=0, offset=16, show_header=True, show_offsets=True, show_ascii=True, output=sys.stdout):
|
def hexdump(data, indent=0, offset=16, show_header=True, show_offsets=True, show_ascii=True, use_colors=True, output=sys.stdout):
|
||||||
"""
|
"""
|
||||||
Writes a hex dump of 'data' to 'output'.
|
Writes a hex dump of 'data' to 'output'.
|
||||||
|
|
||||||
|
@ -145,10 +147,14 @@ def hexdump(data, indent=0, offset=16, show_header=True, show_offsets=True, show
|
||||||
elif i == len(data):
|
elif i == len(data):
|
||||||
hex_bytes.extend([' '] * (offset - local_i))
|
hex_bytes.extend([' '] * (offset - local_i))
|
||||||
|
|
||||||
|
if use_colors: output_io.write(text.render("§B"))
|
||||||
output_io.write(' '.join(hex_bytes))
|
output_io.write(' '.join(hex_bytes))
|
||||||
|
if use_colors: output_io.write(text.render("§/"))
|
||||||
|
|
||||||
if show_ascii:
|
if show_ascii:
|
||||||
output_io.write(' |' + ''.join(ascii_bytes) + '|')
|
output_io.write(text.render(" |§B") if use_colors else " |")
|
||||||
|
output_io.write(''.join(ascii_bytes))
|
||||||
|
output_io.write(text.render("§/|") if use_colors else "|")
|
||||||
|
|
||||||
output_io.write('\n')
|
output_io.write('\n')
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue