Commit f8b180dd authored by Yannick Kirschhoffer's avatar Yannick Kirschhoffer

Provide extra attributes to darken the white color as the grey is too dark.

parent c3f4fb06
from typing import Tuple
from typing import Tuple, List
import termcolor
......@@ -18,10 +18,11 @@ class Boundary:
class RasterCell:
def __init__(self, character: str = ' ', origin: object = None, color: str = None):
def __init__(self, character: str = ' ', origin: object = None, color: str = None, attrs: List[str] = None):
self.character = character
self.origin = origin
self.color = color
self.attrs = attrs
def __eq__(self, other):
return self.__dict__ == other.__dict__
......@@ -32,19 +33,20 @@ class Raster:
self._cells = []
self._default = RasterCell()
def write(self, x: int, y: int, text, origin: object = None, color: str = None):
def write(self, x: int, y: int, text, origin: object = None, color: str = None, attrs: List[str] = None):
if type(text) is Raster:
rastersize_x, rastersize_y = text.size()
for ry in range(rastersize_y):
for rx in range(rastersize_x):
cell = text.get(rx, ry)
self.write(x + rx, y + ry, origin=cell.origin, color=cell.color, text=cell.character)
self.write(x + rx, y + ry, origin=cell.origin, color=cell.color, attrs=cell.attrs,
text=cell.character)
else:
self._expand(x + len(text), y + 1)
for i in range(len(text)):
self._cells[y][x + i] = RasterCell(character=text[i], origin=origin, color=color)
self._cells[y][x + i] = RasterCell(character=text[i], origin=origin, color=color, attrs=attrs)
def draw_line(self, src_x, src_y, dst_x, dst_y):
med_x = int((src_x + dst_x) / 2)
......@@ -109,7 +111,7 @@ class Raster:
for line in self._cells:
for c in line:
if color and c.color:
text += termcolor.colored(c.character, c.color)
text += termcolor.colored(c.character, c.color, attrs=c.attrs)
else:
text += c.character
......
......@@ -76,17 +76,17 @@ class Border(Widget):
r = Raster()
for y in range(cmp_h + 2):
r.write(0, y, '|', origin=self, color='grey')
r.write(width + 1, y, '|', origin=self, color='grey')
r.write(0, y, '|', origin=self, color='white', attrs=['dark'])
r.write(width + 1, y, '|', origin=self, color='white', attrs=['dark'])
for x in range(width + 2):
r.write(x, 0, '-', origin=self, color='grey')
r.write(x, cmp_h + 1, '-', origin=self, color='grey')
r.write(x, 0, '-', origin=self, color='white', attrs=['dark'])
r.write(x, cmp_h + 1, '-', origin=self, color='white', attrs=['dark'])
r.write(0, 0, '+', origin=self, color='grey')
r.write(width + 1, 0, '+', origin=self, color='grey')
r.write(0, cmp_h + 1, '+', origin=self, color='grey')
r.write(width + 1, cmp_h + 1, '+', origin=self, color='grey')
r.write(0, 0, '+', origin=self, color='white', attrs=['dark'])
r.write(width + 1, 0, '+', origin=self, color='white', attrs=['dark'])
r.write(0, cmp_h + 1, '+', origin=self, color='white', attrs=['dark'])
r.write(width + 1, cmp_h + 1, '+', origin=self, color='white', attrs=['dark'])
if len(self._title) > 0:
r.write(2, 0, ' ' + self._title + ' ', origin=self, color='white')
......@@ -148,9 +148,10 @@ class HBox(Widget):
class Paragraph(Widget):
def __init__(self, lines: List[str], color: str = None):
def __init__(self, lines: List[str], color: str = None, attrs: List[str] = None):
self._lines = lines
self._color = color
self._attrs = attrs
def preferred_size(self) -> Size:
return Size(max([len(l) for l in self._lines]), len(self._lines))
......@@ -159,7 +160,7 @@ class Paragraph(Widget):
r = Raster()
for l in self._lines:
r.write(0, r.size()[1], l, origin=self, color=self._color)
r.write(0, r.size()[1], l, origin=self, color=self._color, attrs=self._attrs)
return r
......
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