2009-11-11 23:45:03 -05:00
|
|
|
import curses
|
2008-04-20 23:10:25 -04:00
|
|
|
import color
|
|
|
|
from point import Point
|
|
|
|
|
2008-05-03 16:22:12 -04:00
|
|
|
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
|
|
|
|
|
2008-04-20 23:10:25 -04:00
|
|
|
class RenderString(object):
|
2008-05-03 16:22:12 -04:00
|
|
|
def __init__(self, s, y=0, x=0, attrs=None):
|
2008-04-20 23:10:25 -04:00
|
|
|
if attrs is None:
|
|
|
|
attrs = color.build('default', 'default')
|
2008-05-03 15:41:06 -04:00
|
|
|
|
2010-07-03 23:08:15 -04:00
|
|
|
#self.string = s
|
|
|
|
self.string = s.replace('\t', ' ')
|
2008-05-03 15:41:06 -04:00
|
|
|
self.y = y
|
2008-04-20 23:10:25 -04:00
|
|
|
self.x = x
|
|
|
|
self.attrs = attrs
|
2010-04-27 01:14:41 -04:00
|
|
|
def width(self, w):
|
|
|
|
l = len(self.string)
|
|
|
|
return l
|
|
|
|
def draw(self, cwin, y, x):
|
2008-04-25 10:20:40 -04:00
|
|
|
try:
|
2010-04-27 01:14:41 -04:00
|
|
|
s = self.string.encode('utf-8')
|
2010-07-03 23:08:15 -04:00
|
|
|
assert '\t' not in s, repr(s)
|
2010-04-27 01:14:41 -04:00
|
|
|
cwin.addstr(self.y + y, x, s, self.attrs)
|
2009-11-11 23:45:03 -05:00
|
|
|
except curses.error:
|
2009-04-20 15:36:42 -04:00
|
|
|
raise
|