Show a spinner while scanning/scoring is in progress

This commit is contained in:
Kovid Goyal
2025-07-12 08:34:15 +05:30
parent fef57bd4c2
commit 80ce6946f7
2 changed files with 14 additions and 4 deletions

View File

@@ -206,6 +206,7 @@ type Handler struct {
err_chan chan error err_chan chan error
shortcut_tracker config.ShortcutTracker shortcut_tracker config.ShortcutTracker
msg_printer *message.Printer msg_printer *message.Printer
spinner *tui.Spinner
} }
func (h *Handler) draw_screen() (err error) { func (h *Handler) draw_screen() (err error) {
@@ -736,7 +737,7 @@ func main(_ *cli.Command, opts *Options, args []string) (rc int, err error) {
return 1, err return 1, err
} }
lp.MouseTrackingMode(loop.FULL_MOUSE_TRACKING) lp.MouseTrackingMode(loop.FULL_MOUSE_TRACKING)
handler := Handler{lp: lp, err_chan: make(chan error, 8), msg_printer: message.NewPrinter(utils.LanguageTag())} handler := Handler{lp: lp, err_chan: make(chan error, 8), msg_printer: message.NewPrinter(utils.LanguageTag()), spinner: tui.NewSpinner("dots")}
handler.rl = readline.New(lp, readline.RlInit{ handler.rl = readline.New(lp, readline.RlInit{
Prompt: "> ", ContinuationPrompt: ". ", Completer: handler.complete_save_prompt, Prompt: "> ", ContinuationPrompt: ". ", Completer: handler.complete_save_prompt,
}) })

View File

@@ -242,7 +242,7 @@ func (h *Handler) draw_list_of_results(matches *SortedResults, y, height int) (n
return len(columns), num_shown return len(columns), num_shown
} }
func (h *Handler) draw_num_of_matches(num_shown, y int) { func (h *Handler) draw_num_of_matches(num_shown, y int, in_progress bool) {
m := "" m := ""
switch h.state.last_render.num_matches { switch h.state.last_render.num_matches {
case 0: case 0:
@@ -251,7 +251,13 @@ func (h *Handler) draw_num_of_matches(num_shown, y int) {
m = fmt.Sprintf(" %d of %s matches ", min(num_shown, h.state.last_render.num_matches), h.msg_printer.Sprint(h.state.last_render.num_matches)) m = fmt.Sprintf(" %d of %s matches ", min(num_shown, h.state.last_render.num_matches), h.msg_printer.Sprint(h.state.last_render.num_matches))
} }
w := int(math.Ceil(float64(wcswidth.Stringwidth(m)) / 2.0)) w := int(math.Ceil(float64(wcswidth.Stringwidth(m)) / 2.0))
h.lp.MoveCursorTo(h.screen_size.width-w-2, y) spinner := ""
spinner_width := 0
if in_progress {
spinner = h.spinner.Tick()
spinner_width = 1 + wcswidth.Stringwidth(spinner)
}
h.lp.MoveCursorTo(h.screen_size.width-w-spinner_width-2, y)
st := loop.SizedText{Subscale_denominator: 2, Subscale_numerator: 1, Vertical_alignment: 2, Width: 1} st := loop.SizedText{Subscale_denominator: 2, Subscale_numerator: 1, Vertical_alignment: 2, Width: 1}
graphemes := wcswidth.SplitIntoGraphemes(m) graphemes := wcswidth.SplitIntoGraphemes(m)
for len(graphemes) > 0 { for len(graphemes) > 0 {
@@ -263,6 +269,9 @@ func (h *Handler) draw_num_of_matches(num_shown, y int) {
} }
h.lp.DrawSizedText(s, st) h.lp.DrawSizedText(s, st)
} }
if spinner != "" {
h.lp.QueueWriteString(spinner)
}
} }
func (h *Handler) draw_results(y, bottom_margin int, matches *SortedResults, in_progress bool) (height int) { func (h *Handler) draw_results(y, bottom_margin int, matches *SortedResults, in_progress bool) (height int) {
@@ -285,7 +294,7 @@ func (h *Handler) draw_results(y, bottom_margin int, matches *SortedResults, in_
} }
h.state.last_render.num_matches = num h.state.last_render.num_matches = num
h.state.last_render.num_shown = num_shown h.state.last_render.num_shown = num_shown
h.draw_num_of_matches(h.state.last_render.num_of_slots*num_cols, y+height-2) h.draw_num_of_matches(h.state.last_render.num_of_slots*num_cols, y+height-2, in_progress)
return return
} }