From 77a161bf15cf58dec4afaba3808fc9b108be5956 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 9 Jan 2017 08:07:18 +0530 Subject: [PATCH] Add the powerline block arrow symbols to the set of box drawing characters Fixes #14 This is slightly hackish since those symbols are not defined in the unicode spec (they are in the private use area) so it is conceivable that there exist some applications that would break, however, I know of no such applications, if any show up in the future, a config option to control this can be added. --- kitty/fonts/box_drawing.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/kitty/fonts/box_drawing.py b/kitty/fonts/box_drawing.py index 7baa7be85..a2a085f89 100644 --- a/kitty/fonts/box_drawing.py +++ b/kitty/fonts/box_drawing.py @@ -118,6 +118,31 @@ def cross(*s, a=1, b=1, c=1, d=1): half_vline(*s, level=d, which='bottom') +def line_equation(x1, y1, x2, y2): + m = (y2 - y1) / (x2 - x1) + c = y1 - m * x1 + + def y(x): + return m * x + c + + return y + + +def triangle(buf, width, height, left=True): + ay1, by1, y2 = 0, height - 1, height // 2 + if left: + x1, x2 = 0, width - 1 + else: + x1, x2 = width - 1, 0 + uppery = line_equation(x1, ay1, x2, y2) + lowery = line_equation(x1, by1, x2, y2) + xlimits = [(uppery(x), lowery(x)) for x in range(width)] + for y in range(height): + offset = y * width + for x, (upper, lower) in zip(range(width), xlimits): + buf[x + offset] = 255 if upper <= y <= lower else 0 + + box_chars = { '─': [hline], '━': [p(hline, level=3)], @@ -147,6 +172,8 @@ def cross(*s, a=1, b=1, c=1, d=1): '╽': [half_vline, p(half_vline, level=3, which='bottom')], '╾': [p(half_hline, level=3), p(half_hline, which='right')], '╿': [p(half_vline, level=3), p(half_vline, which='bottom')], + '': [triangle], + '': [p(triangle, left=False)], } t, f = 1, 3