diff kitten: Show the number of matches in the status bar when doing a search
This commit is contained in:
parent
cd6a46730a
commit
1022d8a0ee
@ -304,11 +304,14 @@ class DiffHandler(Handler):
|
|||||||
self.write(self.message)
|
self.write(self.message)
|
||||||
else:
|
else:
|
||||||
scroll_frac = styled('{:.0%}'.format(self.scroll_pos / (self.max_scroll_pos or 1)), fg=self.opts.margin_fg)
|
scroll_frac = styled('{:.0%}'.format(self.scroll_pos / (self.max_scroll_pos or 1)), fg=self.opts.margin_fg)
|
||||||
counts = '{}{}{}'.format(
|
if self.current_search is None:
|
||||||
styled(str(self.added_count), fg=self.opts.highlight_added_bg),
|
counts = '{}{}{}'.format(
|
||||||
styled(',', fg=self.opts.margin_fg),
|
styled(str(self.added_count), fg=self.opts.highlight_added_bg),
|
||||||
styled(str(self.removed_count), fg=self.opts.highlight_removed_bg)
|
styled(',', fg=self.opts.margin_fg),
|
||||||
)
|
styled(str(self.removed_count), fg=self.opts.highlight_removed_bg)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
counts = '[{} matches]'.format(len(self.current_search))
|
||||||
suffix = counts + ' ' + scroll_frac
|
suffix = counts + ' ' + scroll_frac
|
||||||
prefix = styled(':', fg=self.opts.margin_fg)
|
prefix = styled(':', fg=self.opts.margin_fg)
|
||||||
filler = self.screen_size.cols - wcswidth(prefix) - wcswidth(suffix)
|
filler = self.screen_size.cols - wcswidth(prefix) - wcswidth(suffix)
|
||||||
|
|||||||
@ -17,6 +17,7 @@ class Search:
|
|||||||
|
|
||||||
def __init__(self, opts, query, is_regex, is_backward):
|
def __init__(self, opts, query, is_regex, is_backward):
|
||||||
self.matches = {}
|
self.matches = {}
|
||||||
|
self.count = 0
|
||||||
self.style = styled('|', fg=opts.search_fg, bg=opts.search_bg).split('|', 1)[0]
|
self.style = styled('|', fg=opts.search_fg, bg=opts.search_bg).split('|', 1)[0]
|
||||||
if not is_regex:
|
if not is_regex:
|
||||||
query = re.escape(query)
|
query = re.escape(query)
|
||||||
@ -27,6 +28,7 @@ class Search:
|
|||||||
|
|
||||||
def __call__(self, diff_lines, margin_size, cols):
|
def __call__(self, diff_lines, margin_size, cols):
|
||||||
self.matches = {}
|
self.matches = {}
|
||||||
|
self.count = 0
|
||||||
half_width = cols // 2
|
half_width = cols // 2
|
||||||
strip_pat = re.compile('\033[[].*?m')
|
strip_pat = re.compile('\033[[].*?m')
|
||||||
right_offset = half_width + 1 + margin_size
|
right_offset = half_width + 1 + margin_size
|
||||||
@ -40,6 +42,7 @@ class Search:
|
|||||||
for m in find(which):
|
for m in find(which):
|
||||||
before = which[:m.start()]
|
before = which[:m.start()]
|
||||||
matches.append((wcswidth(before) + offset, m.group()))
|
matches.append((wcswidth(before) + offset, m.group()))
|
||||||
|
self.count += 1
|
||||||
|
|
||||||
add(left, margin_size)
|
add(left, margin_size)
|
||||||
add(right, right_offset)
|
add(right, right_offset)
|
||||||
@ -51,7 +54,7 @@ class Search:
|
|||||||
return i in self.matches
|
return i in self.matches
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self.matches)
|
return self.count
|
||||||
|
|
||||||
def highlight_line(self, write, line_num):
|
def highlight_line(self, write, line_num):
|
||||||
highlights = self.matches.get(line_num)
|
highlights = self.matches.get(line_num)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user