From a0527773322ef6c8324dc57bfeb33118bd5f62cb Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 4 Mar 2014 00:18:45 +0100 Subject: reduce filker MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- TODO | 2 -- examples/moderate | 2 +- src/__main__.py | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index dfed92a..d4b4fde 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,3 @@ -Reduce filker - List of plugins to implement: iostat [-x] [-d] [-N] -zk [-p | ...] diff --git a/examples/moderate b/examples/moderate index 3c14fe3..d47c704 100644 --- a/examples/moderate +++ b/examples/moderate @@ -232,8 +232,8 @@ semaphore = threading.Semaphore() def redraw(): if semaphore.acquire(blocking = False): values = pattern % tuple([f() for f in functions]) - bar.clear() #print(values.replace('\0', ' ' * 8)) + bar.partial_clear(0, bar.width, 10, 0, 2, values) bar.draw_coloured_splitted_text(0, bar.width, 10, 0, 2, values) semaphore.release() return True diff --git a/src/__main__.py b/src/__main__.py index 5c9f831..1196341 100755 --- a/src/__main__.py +++ b/src/__main__.py @@ -349,6 +349,45 @@ class Bar: ''' self.gc.change(font = font) + def partial_clear(self, x, width, y, ascent, descent, text): + ''' + Fill the panel with its background colour on areas that are not + about to be over painted with text and reset the colour and font + + @param x:int The left position of the text + @param width:int The width of the print area + @param y:int The Y position of the bottom of the text + @param ascent:int Extra height above the text on each line + @param descent:int Extra height under the text on each line + @param text:str The text to draw, '\0' is column delimiter inside each line + ''' + line_height, areas = ascent + self.font_height + descent, [] + y -= self.font_height - ascent + + for line in text.split('\n'): + if '\0' not in line: + x_ = Bar.coloured_length(line) + areas.append((x + x_, y, width - x_, line_height)) + else: + areas_ = [] + parts = line.split('\0') + i, n = 0, len(parts) - 1 + for part in parts: + w = Bar.coloured_length(part) * self.font_width + x_ = int((width - w) * i / n) + areas_.append((x_, x_ + w)) + i += 1 + x1 = areas_[0][1] + for x2, x3 in areas_[1:]: + areas.append((x + x1, y, x2 - x1, line_height)) + x1 = x3 + y += line_height + + self.change_colour(self.background) + self.window.poly_fill_rectangle(self.gc, areas) + self.change_colour(self.foreground) + self.change_font(self.font) + def clear(self): ''' Fill the panel with its background colour and reset the colour and font -- cgit v1.2.3-70-g09d2