More work on rendering results
This commit is contained in:
parent
af1075c3f6
commit
14043be919
1 changed files with 12 additions and 10 deletions
|
|
@ -99,23 +99,26 @@ func icon_for(x os.DirEntry) string {
|
||||||
return "XX"
|
return "XX"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) draw_column_of_matches(matches []ResultItem, x, available_width int, has_extra_matches bool) {
|
func (h *Handler) draw_column_of_matches(matches []ResultItem, x, available_width, num_extra_matches int) {
|
||||||
for i, m := range matches {
|
for i, m := range matches {
|
||||||
h.lp.QueueWriteString("\r")
|
h.lp.QueueWriteString("\r")
|
||||||
h.lp.MoveCursorHorizontally(x)
|
h.lp.MoveCursorHorizontally(x)
|
||||||
|
icon := icon_for(m.dir_entry)
|
||||||
text := ""
|
text := ""
|
||||||
if has_extra_matches && i == len(matches)-1 {
|
tlen := 0
|
||||||
text = "…"
|
if num_extra_matches > 0 && i == len(matches)-1 {
|
||||||
|
icon = "… "
|
||||||
|
text = fmt.Sprintf("%d more matches", num_extra_matches)
|
||||||
} else {
|
} else {
|
||||||
text = m.text
|
text = m.text
|
||||||
tlen := len(text)
|
tlen = len(text)
|
||||||
if wcswidth.Stringwidth(text) > available_width-3 {
|
if wcswidth.Stringwidth(text) > available_width-3 {
|
||||||
text = wcswidth.TruncateToVisualLength(text, available_width-4) + "…"
|
text = wcswidth.TruncateToVisualLength(text, available_width-4) + "…"
|
||||||
tlen = len(text) - 1
|
tlen = len(text) - 1
|
||||||
}
|
}
|
||||||
h.lp.QueueWriteString(icon_for(m.dir_entry) + " ")
|
|
||||||
h.render_match_with_positions(text, tlen, m.positions, 1)
|
|
||||||
}
|
}
|
||||||
|
h.lp.QueueWriteString(icon + " ")
|
||||||
|
h.render_match_with_positions(text, tlen, m.positions, 1)
|
||||||
h.lp.MoveCursorVertically(1)
|
h.lp.MoveCursorVertically(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -141,8 +144,7 @@ func (h *Handler) draw_list_of_results(matches []ResultItem, y, height int) {
|
||||||
chunk := matches[:min(len(matches), height)]
|
chunk := matches[:min(len(matches), height)]
|
||||||
matches = matches[len(chunk):]
|
matches = matches[len(chunk):]
|
||||||
h.lp.MoveCursorTo(x, y)
|
h.lp.MoveCursorTo(x, y)
|
||||||
has_extra_matches := is_last && len(matches) > 0
|
h.draw_column_of_matches(chunk, x, col_width-1, utils.IfElse(is_last, len(matches), 0))
|
||||||
h.draw_column_of_matches(chunk, x, col_width-1, has_extra_matches)
|
|
||||||
x += col_width
|
x += col_width
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -161,11 +163,11 @@ func (h *Handler) draw_results(y, bottom_margin int, matches []ResultItem, in_pr
|
||||||
default:
|
default:
|
||||||
switch h.state.SearchText() {
|
switch h.state.SearchText() {
|
||||||
case "":
|
case "":
|
||||||
h.draw_list_of_results(matches, y, height-y)
|
h.draw_list_of_results(matches, y, height-2)
|
||||||
default:
|
default:
|
||||||
h.draw_matching_result(matches[0])
|
h.draw_matching_result(matches[0])
|
||||||
y += 2
|
y += 2
|
||||||
h.draw_list_of_results(matches[1:], y, height-y)
|
h.draw_list_of_results(matches[1:], y, height-4)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue