Commit 7f078368 by nzy

Fix Print Grid

parent 7182bd82
...@@ -14,7 +14,7 @@ colors = ["#000000", "#0000FF", "#FF0000", "#008000", "#FFFF00", ...@@ -14,7 +14,7 @@ colors = ["#000000", "#0000FF", "#FF0000", "#008000", "#FFFF00",
"#808080", "#FFC0CB", "#FFA500", "#008080", "#800000"] "#808080", "#FFC0CB", "#FFA500", "#008080", "#800000"]
def array_to_str(matrix): def array_to_str(matrix):
if np.issubdtype(matrix.dtype, np.integer): try:
text = Text() text = Text()
if matrix.ndim == 2: if matrix.ndim == 2:
for row in list(matrix): for row in list(matrix):
...@@ -24,8 +24,10 @@ def array_to_str(matrix): ...@@ -24,8 +24,10 @@ def array_to_str(matrix):
elif matrix.ndim == 1: elif matrix.ndim == 1:
for pixel in list(matrix): for pixel in list(matrix):
text.append("⬛", style=colors[pixel]) text.append("⬛", style=colors[pixel])
else:
raise NotImplementedError
return text return text
else: except Exception:
return Text(str(matrix)) return Text(str(matrix))
def rich_dumps(obj): def rich_dumps(obj):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment