aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-02-28 21:40:08 +0100
committerMattias Andrée <maandree@operamail.com>2014-02-28 21:40:08 +0100
commitccb3b39a4dd8c5f667bf37c6f4a79a7e8da53bda (patch)
tree3625f45d82c0d3c05fcf292f3cdd200391e1c5f4
parentcleaner (diff)
downloadxpybar-ccb3b39a4dd8c5f667bf37c6f4a79a7e8da53bda.tar.gz
xpybar-ccb3b39a4dd8c5f667bf37c6f4a79a7e8da53bda.tar.bz2
xpybar-ccb3b39a4dd8c5f667bf37c6f4a79a7e8da53bda.tar.xz
fix special chars
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--examples/test2
-rwxr-xr-xsrc/__main__.py37
2 files changed, 20 insertions, 19 deletions
diff --git a/examples/test b/examples/test
index 44b2366..55d3981 100644
--- a/examples/test
+++ b/examples/test
@@ -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 ²°°°\n└┘ TEST ─│┌┐└┘├┤┬┴┼╱╲╳ ←↓→↑X')
diff --git a/src/__main__.py b/src/__main__.py
index bf86ddf..f381294 100755
--- a/src/__main__.py
+++ b/src/__main__.py
@@ -144,18 +144,19 @@ class Bar:
'''
return self.font.query_text_extents(text).overall_width
- def draw_text(self, x, y, text):
+ def draw_text(self, x, y, descent, text):
'''
Draw a text
- @param x:int The left position of the text
- @param y:int The Y position of the bottom of the text
- @param text:str The text to draw
+ @param x:int The left position of the text
+ @param y:int The Y position of the bottom of the text
+ @param descent:int Extra height under the text on each line
+ @param text:str The text to draw
'''
special = '─│┌┐└┘├┤┬┴┼╱╲╳←↓→↑\0'
buf = ''
w = self.text_width('X') - 1
- h = self.font_height - 1
+ h = self.font_height + descent - 1
y_ = y - self.font_height
for c in text + '\0':
if c in special:
@@ -174,21 +175,21 @@ class Bar:
if c in '╱╳': segs.append((0, 2, 2, 0))
if c in '╲╳': segs.append((0, 0, 2, 2))
if c in '←':
- segs.append((0, 1, 2, 1))
- segs.append((1, 0.5, 0, 1))
- segs.append((1, 1.5, 0, 1))
+ segs.append((0, 1, 1.9, 1))
+ segs.append((1, 0.6, 0, 1))
+ segs.append((1, 1.4, 0, 1))
elif c in '→':
- segs.append((0, 1, 2, 1))
- segs.append((1.2, 0.5, 2, 1))
- segs.append((1.2, 1.5, 2, 1))
+ segs.append((0, 1, 1.9, 1))
+ segs.append((1.1, 0.6, 1.9, 1))
+ segs.append((1.1, 1.4, 1.9, 1))
elif c in '↑':
- segs.append((1, 0, 1, 2))
- segs.append((0.3, 0.5, 1, 0))
- segs.append((1.7, 0.5, 1, 0))
+ segs.append((1, 0.4, 1, 1.8))
+ segs.append((0.3, 0.9, 1, 0.4))
+ segs.append((1.7, 0.9, 1, 0.4))
elif c in '↓':
- segs.append((1, 0, 1, 2))
- segs.append((0.3, 1.7, 1, 2))
- segs.append((1.7, 1.7, 1, 2))
+ segs.append((1, 0.4, 1, 1.8))
+ segs.append((0.3, 1.3, 1, 1.8))
+ segs.append((1.7, 1.3, 1, 1.8))
segs_ = []
for seg in segs:
(x1, y1, x2, y2) = [c / 2 for c in seg]
@@ -263,7 +264,7 @@ class Bar:
w = self.text_width(buf)
self.window.fill_rectangle(self.gc, x, y - h, w, line_height)
self.gc.change(foreground = fc, background = bc)
- self.draw_text(x, y + ascent, buf)
+ self.draw_text(x, y + ascent, descent, buf)
x += w
buf = ''
if c == '\n':