From bb79a275693f67394b285aa9570e239c67b94476 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 22 May 2025 22:40:34 +0530 Subject: [PATCH] Render match --- kittens/choose_files/results.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/kittens/choose_files/results.go b/kittens/choose_files/results.go index 9bcbe169e..920b05b11 100644 --- a/kittens/choose_files/results.go +++ b/kittens/choose_files/results.go @@ -54,11 +54,25 @@ func (h *Handler) draw_no_matches_message(in_progress bool) { } +const matching_position_style = "fg=green" + func (h *Handler) draw_matching_result(r ResultItem) { + icon := icon_for(r.abspath, r.dir_entry) + h.lp.MoveCursorHorizontally(1) + p, s, _ := strings.Cut(h.lp.SprintStyled(matching_position_style, " "), " ") + h.lp.QueueWriteString(p) + h.lp.DrawSizedText(icon, loop.SizedText{Scale: 2}) + h.lp.QueueWriteString(s) + text := r.text + available_width := (h.screen_size.width - 6) / 2 + if wcswidth.Stringwidth(text) > available_width { + text = wcswidth.TruncateToVisualLength(text, available_width-2) + "…" + } + h.render_match_with_positions(text, len(r.text), r.positions, 2) } func (h *Handler) render_match_with_positions(text string, stop_at int, positions []int, scale int) { - prefix, suffix, _ := strings.Cut(h.lp.SprintStyled("fg=green", " "), " ") + prefix, suffix, _ := strings.Cut(h.lp.SprintStyled(matching_position_style, " "), " ") write_chunk := func(text string, emphasize bool) { if text == "" { return