From 91bf82171a3fc7f052f7f18885b0aea2c345d572 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 18 Feb 2017 00:12:39 +0300 Subject: [PATCH] editorext: Add CharColorViewer widget. Viewer with color support, (echo line may consist of spans of different colors). --- picotui/editorext.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/picotui/editorext.py b/picotui/editorext.py index 982d51d..e0178da 100644 --- a/picotui/editorext.py +++ b/picotui/editorext.py @@ -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