diff options
| -rw-r--r-- | examples/simple | 2 | ||||
| -rwxr-xr-x | src/__main__.py | 30 | 
2 files changed, 30 insertions, 2 deletions
diff --git a/examples/simple b/examples/simple index f14d6d2..0f9fc31 100644 --- a/examples/simple +++ b/examples/simple @@ -6,5 +6,5 @@ OUTPUT, HEIGHT, YPOS, TOP = 0, 24, 24, True  def redraw():      bar.clear() -    bar.draw_coloured_text(0, 10, 0, 2, '°°°² \033[31;47m|T|\033[49mE|\033[mS\033[38;2;128;16;255m|T|\033[0m ²°°°\nTEST') +    bar.draw_coloured_text(0, 10, 0, 2, '°°°² \033[31;47m|T|\033[49mE|\033[mS\033[38;2;128;16;255m|T|\033[0m ²°°°\nTEST ─│┌┐└┘├┤┬┴┼╱╲╳') diff --git a/src/__main__.py b/src/__main__.py index e5d5e33..ab65f47 100755 --- a/src/__main__.py +++ b/src/__main__.py @@ -152,7 +152,35 @@ class Bar:          @param  y:int     The Y position of the bottom of the text          @param  text:str  The text to draw          ''' -        draw_text(bar.window, bar.gc, x, y, text) +        special = '─│┌┐└┘├┤┬┴┼╱╲╳\0' +        buf = '' +        w = self.text_width('X') +        h = self.font_height +        y_ = y - self.font_height +        for c in text + '\0': +            if c in special: +                if not buf == '': +                    self.window.draw_text(self.gc, x, y, buf) +                    x += self.text_width(buf) +                    buf = '' +                if not c == '\0': +                    segs = [] +                    if c in '─┼┬┴':  segs.append((0, 1,  2, 1)) +                    if c in '│┼├┤':  segs.append((1, 0,  1, 2)) +                    if c in '├┌└':   segs.append((1, 1,  2, 1)) +                    if c in '┤┐┘':   segs.append((0, 1,  1, 1)) +                    if c in '┬┌┐':   segs.append((1, 1,  1, 2)) +                    if c in '┴└┘':   segs.append((1, 0,  1, 1)) +                    if c in '╱╳':    segs.append((0, 2,  2, 0)) +                    if c in '╲╳':    segs.append((0, 0,  2, 2)) +                    segs_ = [] +                    for seg in segs: +                        (x1, y1, x2, y2) = [c / 2 for c in seg] +                        segs_.append((int(x1 * w) + x, int(y1 * h) + y_, int(x2 * w) + x, int(y2 * h) + y_)) +                    self.window.poly_segment(self.gc, segs_) +                    x += w +            else: +                buf += c      def draw_coloured_text(self, x, y, ascent, descent, text):          '''  | 
