diff --git a/application.py b/application.py index 62472f5..ca6d349 100755 --- a/application.py +++ b/application.py @@ -514,9 +514,8 @@ class Application(object): return # highlighting - # each highlighted_range contains three things: [window, start_p, end_p] - def add_highlighted_range(self, w, p1, p2, fg='default', bg='default'): - self.highlighted_ranges.append([w, p1, p2, fg, bg]) + def add_highlighted_range(self, hr): + self.highlighted_ranges.append(hr) def clear_highlighted_ranges(self): self.highlighted_ranges = [] @@ -655,7 +654,8 @@ class Application(object): self._draw_slot(i) # highlighted regions - for (high_w, p1, p2, fg, bg) in self.highlighted_ranges: + for hr in self.highlighted_ranges: + (high_w, p1, p2, fg, bg) = hr if w is high_w and p2 >= w.first and p1 <= w.last: count = 0 x, y = w.first.xy() diff --git a/method/introspect.py b/method/introspect.py index 394a7b1..2605355 100644 --- a/method/introspect.py +++ b/method/introspect.py @@ -10,7 +10,8 @@ class DumpRegions(Method): '''debug region highlighting''' def _execute(self, w, **vargs): lines = [] - for (w, p1, p2) in w.application.highlighted_ranges: + for hr in w.application.highlighted_ranges: + (w, p1, p2, fg, bg) = hr lines.append("%r %s %s" % (w, p1, p2)) output = "\n".join(lines) w.application.data_buffer("region-dump", output, switch_to=True) diff --git a/render.py b/render.py index 28aa0e9..61e8b6a 100644 --- a/render.py +++ b/render.py @@ -1,8 +1,27 @@ 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, name=""): + def __init__(self, s, y=0, x=0, attrs=None): if attrs is None: attrs = color.build('default', 'default') @@ -10,7 +29,6 @@ class RenderString(object): self.y = y self.x = x self.attrs = attrs - self.name = name def draw(self, cwin, y, x): try: cwin.addstr(self.y + y, self.x + x, self.string, self.attrs) diff --git a/searchutil.py b/searchutil.py index 147b7d9..79851bc 100644 --- a/searchutil.py +++ b/searchutil.py @@ -1,6 +1,7 @@ import re import regex from point import Point +from render import HighlightRegion bg_color = 'black' selected_color = 'magenta' @@ -54,8 +55,8 @@ def find(r, w, move=False, direction='next', start=None, end=None): limit = Point(x - 1 + offset, y) elif direction == 'previous': limit = Point(x + 1 - offset, y) - for stuff in app.highlighted_ranges: - (wz, p1, p2, fg, bg) = stuff + for hr in app.highlighted_ranges: + (wz, p1, p2, fg, bg) = hr if p1 == c: limit = Point(x + 1 + p2.x - p1.x - 2*offset + 1, y) break @@ -81,7 +82,7 @@ def find(r, w, move=False, direction='next', start=None, end=None): continue elif p2 > w.last: break - app.add_highlighted_range(w, p1, p2, fg, bg) + app.add_highlighted_range(HighlightRegion(w, p1, p2, fg, bg)) return newc def find_previous(r, w, move=False, start=None, end=None):