mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-10 22:24:24 +02:00
...
This commit is contained in:
@@ -2,6 +2,7 @@ package choose_fonts
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"kitty/tools/tui"
|
||||
"kitty/tools/tui/subseq"
|
||||
"kitty/tools/utils"
|
||||
"kitty/tools/wcswidth"
|
||||
@@ -21,6 +22,16 @@ func (self *FamilyList) Len() int {
|
||||
return len(self.families)
|
||||
}
|
||||
|
||||
func (self *FamilyList) Select(family string) bool {
|
||||
for idx, q := range self.families {
|
||||
if q == family {
|
||||
self.current_idx = idx
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *FamilyList) Next(delta int, allow_wrapping bool) bool {
|
||||
if len(self.display_strings) == 0 {
|
||||
return false
|
||||
@@ -84,6 +95,10 @@ func apply_search(families []string, expression string, marks ...string) (matche
|
||||
return
|
||||
}
|
||||
|
||||
func make_family_names_clickable(family string) string {
|
||||
return tui.InternalHyperlink(family, "family-chosen:"+family)
|
||||
}
|
||||
|
||||
func (self *FamilyList) UpdateFamilies(families []string) {
|
||||
self.families, self.all_families = families, families
|
||||
if self.current_search != "" {
|
||||
@@ -92,6 +107,7 @@ func (self *FamilyList) UpdateFamilies(families []string) {
|
||||
} else {
|
||||
self.display_strings = utils.Map(limit_lengths, families)
|
||||
}
|
||||
self.display_strings = utils.Map(make_family_names_clickable, self.display_strings)
|
||||
self.widths = utils.Map(wcswidth.Stringwidth, self.display_strings)
|
||||
self.max_width = utils.Max(0, self.widths...)
|
||||
self.current_idx = 0
|
||||
|
||||
@@ -137,7 +137,7 @@ func (h *handler) draw_listing_screen() (err error) {
|
||||
}
|
||||
lines = append(lines, line)
|
||||
}
|
||||
_, _, str := h.render_lines.InRectangle(lines, 0, 0, 0, num_rows, &h.mouse_state)
|
||||
_, _, str := h.render_lines.InRectangle(lines, 0, 0, 0, num_rows, &h.mouse_state, h.handle_click)
|
||||
h.lp.QueueWriteString(str)
|
||||
seps := strings.Repeat(SEPARATOR, num_rows)
|
||||
seps = strings.TrimSpace(seps)
|
||||
@@ -153,6 +153,25 @@ func (h *handler) draw_listing_screen() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (h *handler) handle_click(id string) error {
|
||||
which, data, found := strings.Cut(id, ":")
|
||||
if !found {
|
||||
return fmt.Errorf("Not a valid click id: %s", id)
|
||||
}
|
||||
switch which {
|
||||
case "family-chosen":
|
||||
if h.state == LISTING_FAMILIES {
|
||||
if h.family_list.Select(data) {
|
||||
h.draw_screen()
|
||||
} else {
|
||||
h.lp.Beep()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *handler) update_family_search() {
|
||||
text := h.rl.AllText()
|
||||
if h.family_list.UpdateSearch(text) {
|
||||
|
||||
Reference in New Issue
Block a user