improved highlighted-region support
--HG-- branch : pmacs2
This commit is contained in:
parent
f478082962
commit
210e00eb37
|
@ -514,9 +514,8 @@ class Application(object):
|
||||||
return
|
return
|
||||||
|
|
||||||
# highlighting
|
# highlighting
|
||||||
# each highlighted_range contains three things: [window, start_p, end_p]
|
def add_highlighted_range(self, hr):
|
||||||
def add_highlighted_range(self, w, p1, p2, fg='default', bg='default'):
|
self.highlighted_ranges.append(hr)
|
||||||
self.highlighted_ranges.append([w, p1, p2, fg, bg])
|
|
||||||
def clear_highlighted_ranges(self):
|
def clear_highlighted_ranges(self):
|
||||||
self.highlighted_ranges = []
|
self.highlighted_ranges = []
|
||||||
|
|
||||||
|
@ -655,7 +654,8 @@ class Application(object):
|
||||||
self._draw_slot(i)
|
self._draw_slot(i)
|
||||||
|
|
||||||
# highlighted regions
|
# 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:
|
if w is high_w and p2 >= w.first and p1 <= w.last:
|
||||||
count = 0
|
count = 0
|
||||||
x, y = w.first.xy()
|
x, y = w.first.xy()
|
||||||
|
|
|
@ -10,7 +10,8 @@ class DumpRegions(Method):
|
||||||
'''debug region highlighting'''
|
'''debug region highlighting'''
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
lines = []
|
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))
|
lines.append("%r %s %s" % (w, p1, p2))
|
||||||
output = "\n".join(lines)
|
output = "\n".join(lines)
|
||||||
w.application.data_buffer("region-dump", output, switch_to=True)
|
w.application.data_buffer("region-dump", output, switch_to=True)
|
||||||
|
|
22
render.py
22
render.py
|
@ -1,8 +1,27 @@
|
||||||
import color
|
import color
|
||||||
from point import Point
|
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):
|
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:
|
if attrs is None:
|
||||||
attrs = color.build('default', 'default')
|
attrs = color.build('default', 'default')
|
||||||
|
|
||||||
|
@ -10,7 +29,6 @@ class RenderString(object):
|
||||||
self.y = y
|
self.y = y
|
||||||
self.x = x
|
self.x = x
|
||||||
self.attrs = attrs
|
self.attrs = attrs
|
||||||
self.name = name
|
|
||||||
def draw(self, cwin, y, x):
|
def draw(self, cwin, y, x):
|
||||||
try:
|
try:
|
||||||
cwin.addstr(self.y + y, self.x + x, self.string, self.attrs)
|
cwin.addstr(self.y + y, self.x + x, self.string, self.attrs)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import re
|
import re
|
||||||
import regex
|
import regex
|
||||||
from point import Point
|
from point import Point
|
||||||
|
from render import HighlightRegion
|
||||||
|
|
||||||
bg_color = 'black'
|
bg_color = 'black'
|
||||||
selected_color = 'magenta'
|
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)
|
limit = Point(x - 1 + offset, y)
|
||||||
elif direction == 'previous':
|
elif direction == 'previous':
|
||||||
limit = Point(x + 1 - offset, y)
|
limit = Point(x + 1 - offset, y)
|
||||||
for stuff in app.highlighted_ranges:
|
for hr in app.highlighted_ranges:
|
||||||
(wz, p1, p2, fg, bg) = stuff
|
(wz, p1, p2, fg, bg) = hr
|
||||||
if p1 == c:
|
if p1 == c:
|
||||||
limit = Point(x + 1 + p2.x - p1.x - 2*offset + 1, y)
|
limit = Point(x + 1 + p2.x - p1.x - 2*offset + 1, y)
|
||||||
break
|
break
|
||||||
|
@ -81,7 +82,7 @@ def find(r, w, move=False, direction='next', start=None, end=None):
|
||||||
continue
|
continue
|
||||||
elif p2 > w.last:
|
elif p2 > w.last:
|
||||||
break
|
break
|
||||||
app.add_highlighted_range(w, p1, p2, fg, bg)
|
app.add_highlighted_range(HighlightRegion(w, p1, p2, fg, bg))
|
||||||
return newc
|
return newc
|
||||||
|
|
||||||
def find_previous(r, w, move=False, start=None, end=None):
|
def find_previous(r, w, move=False, start=None, end=None):
|
||||||
|
|
Loading…
Reference in New Issue