pmacs3/render.py

43 lines
1.3 KiB
Python
Raw Normal View History

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.y = y
self.x = x
self.attrs = attrs
def draw(self, cwin, y, x, x2=None):
try:
if x2:
s = '%-*s' % (x2 - x, self.string)
else:
s = self.string
cwin.addstr(self.y + y, self.x + x, s, self.attrs)
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