improved highlighted-region support

--HG--
branch : pmacs2
This commit is contained in:
moculus 2008-05-03 20:22:12 +00:00
parent f478082962
commit 210e00eb37
4 changed files with 30 additions and 10 deletions

View File

@ -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()

View File

@ -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)

View File

@ -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)

View File

@ -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):