pmacs3/render.py

44 lines
1.2 KiB
Python
Raw Normal View History

import curses
import color
from point import Point
class HighlightRegion(object):
def __init__(self, w, p1, p2, fg='default', bg='default', match=None, name='lit'):
self.window = w
self.p1 = p1
self.p2 = p2
self.fg = fg
self.bg = bg
self.match = match
self.name = name
def __len__(self):
return 5
def __getitem__(self, i):
if i == 0: return self.window
elif i == 1: return self.p1
elif i == 2: return self.p2
elif i == 3: return self.fg
elif i == 4: return self.bg
else: raise IndexError
class RenderString(object):
def __init__(self, s, y=0, x=0, attrs=None):
if attrs is None:
attrs = color.build('default', 'default')
#self.string = s
self.string = s.replace('\t', ' ')
self.y = y
self.x = x
self.attrs = attrs
def width(self, w):
l = len(self.string)
return l
def draw(self, cwin, y, x):
try:
s = self.string.encode('utf-8')
assert '\t' not in s, repr(s)
cwin.addstr(self.y + y, x, s, self.attrs)
except curses.error:
raise