Skip to content

Commit

Permalink
editorext: Add CharColorViewer widget.
Browse files Browse the repository at this point in the history
Viewer with color support, (echo line may consist of spans
of different colors).
  • Loading branch information
pfalcon committed Feb 17, 2017
1 parent 576cb3f commit 91bf821
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions picotui/editorext.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,29 @@ def set_line_colors(self, default_color, color_list={}):
self.is_dict_color = isinstance(color_list, dict)


# Viewer with color support, (echo line may consist of spans
# of different colors)
class CharColorViewer(Viewer):

def show_line(self, l, i):
# TODO: handle self.margin, self.width
length = 0
for span in l:
if isinstance(span, tuple):
span, c = span
else:
c = self.def_c
self.attr_color(c)
self.wr(span)
length += len(span)
self.attr_color(self.def_c)
self.clear_num_pos(self.width - length)
self.attr_reset()

def set_def_color(self, default_color):
self.def_c = default_color


class EditorExt(Editor):

screen_width = 80
Expand Down

0 comments on commit 91bf821

Please sign in to comment.