Commit a5893bef authored by Yannick Kirschhoffer's avatar Yannick Kirschhoffer

Implementation of color management in raster module.

parent 774d3da1
from typing import Tuple
import termcolor
class Boundary:
def __init__(self, x: int, y: int, w: int, h: int):
......@@ -107,7 +109,10 @@ class Raster:
for line in self._cells:
for c in line:
text += c.character
if self._color and c.color:
text += termcolor.colored(c.character, c.color)
else:
text += c.character
text += '\n'
......
......@@ -103,13 +103,21 @@ class RasterTests(unittest.TestCase):
r = Raster(color=False)
r.write(0, 0, 'Red', color='red')
r.write(0, 1, 'Green', color='green')
print(str(r))
self.assertEqual(
'Red\n'
'Green\n'
, str(r)
)
def test_color_enabled(self):
r = Raster(color=True)
r.write(0, 0, 'Red', color='red')
r.write(0, 1, 'Green', color='green')
print(str(r))
print(repr(str(r)))
self.assertEqual(
'\x1b[31mR\x1b[0m\x1b[31me\x1b[0m\x1b[31md\x1b[0m\n\x1b[32mG\x1b[0m\x1b[32mr\x1b[0m\x1b[32me\x1b[0m\x1b[32me\x1b[0m\x1b[32mn\x1b[0m\n'
, str(r)
)
if __name__ == '__main__':
......
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