mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-27 18:51:41 +02:00
Add visible controls for scan settings
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user