diff --git a/mode/__init__.py b/mode/__init__.py index cae8a09..3c15e44 100644 --- a/mode/__init__.py +++ b/mode/__init__.py @@ -238,7 +238,7 @@ class Fundamental(Handler): c = "\\" if w.hiddenindicator(y): bg = "green" - return [RenderString(c, 0, color.build(fg, bg))] + return [RenderString(s=c, attrs=color.build(fg, bg))] def get_lmargin(self, w, y, x, ended=False, cont=False): lm = self.lmargin if ended: @@ -248,7 +248,7 @@ class Fundamental(Handler): s = ('% *d' % (lm - 1, y + 1))[-lm:] + ' ' else: s = ' ' * lm - return [RenderString(s, 0, color.build('default', 'default', 'bold'))] + return [RenderString(s=s, attrs=color.build('default', 'default', 'bold'))] # get mode name def name(self): diff --git a/mode/hex.py b/mode/hex.py index df774ef..35b7dda 100644 --- a/mode/hex.py +++ b/mode/hex.py @@ -319,7 +319,7 @@ class Hex(mode.Fundamental): else: addr = self.get_address(y, x) s = '0x%08x ' % addr - return (RenderString(s, 0, self.ccyan),) + return (RenderString(s, attrs=self.ccyan),) def get_rmargin(self, w, y, x, ended=False, cont=False): if ended: @@ -331,17 +331,17 @@ class Hex(mode.Fundamental): i = self.window.buffer.cursorx_to_datax(cy, cx) if i is None: - rmargins = (RenderString(s, 0, self.cgreen),) + rmargins = (RenderString(s, attrs=self.cgreen),) elif i < len(s): - rmargins = (RenderString(s[0:i], 0, self.cgreen), - RenderString(s[i], i, self.ccursor), - RenderString(s[i+1:], i + 1, self.cgreen)) + rmargins = (RenderString(s[0:i], attrs=self.cgreen), + RenderString(s[i], x=i, attrs=self.ccursor), + RenderString(s[i+1:], x=i + 1, attrs=self.cgreen)) else: - rmargins= (RenderString(s[0:i], 0, self.cgreen), - RenderString(s[i], i, self.cgreen)) + rmargins= (RenderString(s[0:i], attrs=self.cgreen), + RenderString(s[i], x=i, attrs=self.cgreen)) return rmargins else: - return (RenderString(s, 0, self.cgreen),) + return (RenderString(s, attrs=self.cgreen),) def read_data(self, cy, ix, size): b = self.window.buffer diff --git a/render.py b/render.py index a4f9af1..28aa0e9 100644 --- a/render.py +++ b/render.py @@ -2,15 +2,18 @@ import color from point import Point class RenderString(object): - def __init__(self, s, x=0, attrs=None): + def __init__(self, s, y=0, x=0, attrs=None, name=""): if attrs is None: attrs = color.build('default', 'default') + self.string = s + self.y = y self.x = x self.attrs = attrs + self.name = name def draw(self, cwin, y, x): try: - cwin.addstr(y, self.x + x, self.string, self.attrs) + cwin.addstr(self.y + y, self.x + x, self.string, self.attrs) except: #return raise Exception, "cwin.addstr(%d, %d + %d, %r, %r) failed" % \ diff --git a/window.py b/window.py index 767856c..4d724fd 100644 --- a/window.py +++ b/window.py @@ -684,21 +684,25 @@ class Window(object): def render_line_raw(self, y, width): if y >= len(self.buffer.lines): - return [[RenderString('~', 0, color.build('red', 'default'))]] + r = RenderString(s='~', attrs=color.build('red', 'default')) + return [(r,)] x = 0 line = self.buffer.lines[y] lines = [] if line: while x < len(line): - lines.append(tuple([RenderString(line[x:x + width], 0)])) + r = RenderString(s=line[x:x + width]) + lines.append((r,)) x += width else: - lines.append(tuple([RenderString('', 0)])) + r = RenderString(s='') + lines.append((r,)) return lines def render_line_lit(self, y, width): if y >= len(self.buffer.lines): - return [[RenderString('~', 0, color.build('red', 'default'))]] + r = RenderString(s='~', attrs=color.build('red', 'default')) + return [(r,)] modename = self.mode.name() highlighter = self.buffer.highlights[modename] @@ -722,7 +726,7 @@ class Window(object): # for debugging things like lexing/relexing/etc. if token._debug: - attr = color.build('blue', 'green') + attr = color.build('blue', 'green', 'bold') elif token.color: attr = color.build(*token.color) else: @@ -730,7 +734,8 @@ class Window(object): # ok, so add a region with data, position, and color info x_offset = max(token.x - x, 0) - line.append(RenderString(s[:width - x_offset], x_offset, attr)) + r = RenderString(s=s[:width - x_offset], x=x_offset, attrs=attr) + line.append(r) # see if the token is wrapping, or if we move on to the next one if x_offset + len(s) > width: