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
|
|
|
|
2008-04-20 23:10:25 -04:00
|
|
|
self.string = s
|
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
|
2009-02-05 10:21:24 -05:00
|
|
|
def draw(self, cwin, y, x, x2=None):
|
2008-04-25 10:20:40 -04:00
|
|
|
try:
|
2009-02-05 10:21:24 -05:00
|
|
|
if x2:
|
|
|
|
s = '%-*s' % (x2 - x, self.string)
|
|
|
|
else:
|
|
|
|
s = self.string
|
2009-06-09 23:37:43 -04:00
|
|
|
s2 = s.encode('utf-8')
|
|
|
|
cwin.addstr(self.y + y, self.x + x, s2, self.attrs)
|
2009-04-20 15:36:42 -04:00
|
|
|
except Exception, e:
|
|
|
|
raise
|
|
|
|
#v = (self.y, y, self.x, x, self.string, self.attrs, str(e))
|
|
|
|
#raise Exception, "cwin.addstr(%d + %d, %d + %d, %r, %r) failed:\n%s" % v
|