From 27736af979829c04deacd63ea471768a507f7b98 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 10 Jul 2025 15:28:11 +0530 Subject: [PATCH] Add visible controls for scan settings --- kittens/choose_files/search-bar.go | 43 +++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/kittens/choose_files/search-bar.go b/kittens/choose_files/search-bar.go index d671a2099..401894ccd 100644 --- a/kittens/choose_files/search-bar.go +++ b/kittens/choose_files/search-bar.go @@ -2,9 +2,11 @@ package choose_files import ( "fmt" + "strconv" "strings" "github.com/kovidgoyal/kitty/tools/tui/loop" + "github.com/kovidgoyal/kitty/tools/utils" "github.com/kovidgoyal/kitty/tools/wcswidth" ) @@ -48,8 +50,47 @@ func (h *Handler) draw_search_text(available_width int) { const SEARCH_BAR_HEIGHT = 4 +func (h *Handler) draw_controls(y int) (max_width int) { + type entry struct { + text string + callback func() + width int + } + lines := make([]entry, 0, SEARCH_BAR_HEIGHT) + add_control := func(icon, text string, callback func()) { + line := icon + " " + text + width := wcswidth.Stringwidth(line) + max_width = max(max_width, width) + lines = append(lines, entry{line, callback, width}) + } + add_control(utils.IfElse(h.state.ShowHidden(), "", ""), utils.IfElse(h.state.ShowHidden(), "hide dotfiles", "show dotfiles"), func() { + h.state.show_hidden = !h.state.show_hidden + h.result_manager.set_show_hidden() + }) + add_control("󰑑", utils.IfElse(h.state.RespectIgnores(), "show ignored", "hide ignored"), func() { + h.state.respect_ignores = !h.state.respect_ignores + h.result_manager.set_respect_ignores() + }) + add_control(utils.IfElse(h.state.SortByLastModified(), "", ""), utils.IfElse(h.state.SortByLastModified(), "sort names", "sort dates"), func() { + h.state.sort_by_last_modified = !h.state.sort_by_last_modified + h.result_manager.set_sort_by_last_modified() + }) + x := h.screen_size.width - max_width + for i, e := range lines { + h.lp.MoveCursorTo(x+1, y+i+1) + h.lp.QueueWriteString(e.text) + cb := e.callback + h.state.mouse_state.AddCellRegion("rcontrol-"+strconv.Itoa(i), x, y+i, x+e.width, y+i, func(_ string) error { + cb() + h.state.redraw_needed = true + return nil + }).HoverStyle = "default fg=red" + } + return max_width + 1 +} + func (h *Handler) draw_search_bar(y int) { - left_margin, right_margin := 5, 5 + left_margin, right_margin := 0, h.draw_controls(y) h.lp.MoveCursorTo(1+left_margin, 1+y) available_width := h.screen_size.width - left_margin - right_margin h.draw_frame(available_width, SEARCH_BAR_HEIGHT)