diff --git a/kittens/themes/list.go b/kittens/themes/list.go index 3a2629333..9b0791268 100644 --- a/kittens/themes/list.go +++ b/kittens/themes/list.go @@ -43,8 +43,8 @@ func (self *ThemesList) Next(delta int, allow_wrapping bool) bool { } func limit_lengths(text string) string { - t, x := wcswidth.TruncateToVisualLengthWithWidth(text, 31) - if x >= len(text) { + t, _ := wcswidth.TruncateToVisualLengthWithWidth(text, 31) + if len(t) >= len(text) { return text } return t + "…" diff --git a/tools/cmd/list_fonts/family_list.go b/tools/cmd/list_fonts/family_list.go index f925644af..658780377 100644 --- a/tools/cmd/list_fonts/family_list.go +++ b/tools/cmd/list_fonts/family_list.go @@ -37,8 +37,8 @@ func (self *FamilyList) Next(delta int, allow_wrapping bool) bool { } func limit_lengths(text string) string { - t, x := wcswidth.TruncateToVisualLengthWithWidth(text, 31) - if x >= len(text) { + t, _ := wcswidth.TruncateToVisualLengthWithWidth(text, 31) + if len(t) >= len(text) { return text } return t + "…" @@ -83,9 +83,9 @@ func apply_search(families []string, expression string, marks ...string) []strin } func (self *FamilyList) UpdateFamilies(families []string) { - self.families, self.families = families, families + self.families, self.all_families = families, families if self.current_search != "" { - self.display_strings = utils.Map(limit_lengths, apply_search(self.families, self.current_search)) + self.display_strings = utils.Map(limit_lengths, apply_search(self.all_families, self.current_search)) } else { self.display_strings = utils.Map(limit_lengths, families) } diff --git a/tools/cmd/list_fonts/ui.go b/tools/cmd/list_fonts/ui.go index a4d55e053..72d744fcf 100644 --- a/tools/cmd/list_fonts/ui.go +++ b/tools/cmd/list_fonts/ui.go @@ -21,19 +21,19 @@ const ( ) type handler struct { - lp *loop.Loop - fonts map[string][]ListedFont - all_font_families []string - state State + lp *loop.Loop + fonts map[string][]ListedFont + state State // Listing - current_font_families []string - rl *readline.Readline + rl *readline.Readline + family_list FamilyList } // Listing families {{{ func (h *handler) draw_search_bar() { h.lp.SetCursorVisible(true) + h.lp.SetCursorShape(loop.BAR_CURSOR, true) sz, err := h.lp.ScreenSize() if err != nil { return @@ -43,19 +43,55 @@ func (h *handler) draw_search_bar() { h.rl.RedrawNonAtomic() } +const SEPARATOR = "║" + +func (h *handler) draw_family_summary() (err error) { + // TODO: Implement me + return +} + func (h *handler) draw_listing_screen() (err error) { sz, err := h.lp.ScreenSize() if err != nil { return err } - _ = sz + num_rows := max(0, int(sz.HeightCells)-1) + mw := h.family_list.max_width + 1 + green_fg, _, _ := strings.Cut(h.lp.SprintStyled("fg=green", "|"), "|") + for _, l := range h.family_list.Lines(num_rows) { + line := l.text + if l.is_current { + line = strings.ReplaceAll(line, MARK_AFTER, green_fg) + h.lp.PrintStyled("fg=green", ">") + h.lp.PrintStyled("fg=green bold", line) + } else { + h.lp.PrintStyled("fg=green", " ") + h.lp.QueueWriteString(line) + } + h.lp.MoveCursorHorizontally(mw - l.width) + h.lp.Println(SEPARATOR) + num_rows-- + } + for ; num_rows > 0; num_rows-- { + h.lp.MoveCursorHorizontally(mw + 1) + h.lp.Println(SEPARATOR) + } + if h.family_list.Len() > 0 { + if err = h.draw_family_summary(); err != nil { + return err + } + } h.draw_search_bar() return } func (h *handler) update_family_search() { text := h.rl.AllText() - _ = text + if h.family_list.UpdateSearch(text) { + h.draw_screen() + } else { + h.draw_search_bar() + } } func (h *handler) handle_listing_key_event(event *loop.KeyEvent) (err error) { @@ -81,7 +117,7 @@ func (h *handler) handle_listing_text(text string, from_key_event bool, in_brack if err = h.rl.OnText(text, from_key_event, in_bracketed_paste); err != nil { return err } - h.draw_screen() + h.update_family_search() return } @@ -90,14 +126,14 @@ func (h *handler) handle_listing_text(text string, from_key_event bool, in_brack // Events {{{ func (h *handler) initialize() { h.lp.SetCursorVisible(false) - h.all_font_families = utils.StableSortWithKey(maps.Keys(h.fonts), strings.ToLower) - h.current_font_families = h.all_font_families + h.family_list.UpdateFamilies(utils.StableSortWithKey(maps.Keys(h.fonts), strings.ToLower)) h.rl = readline.New(h.lp, readline.RlInit{DontMarkPrompts: true, Prompt: "Family: "}) h.draw_screen() } func (h *handler) finalize() { h.lp.SetCursorVisible(true) + h.lp.SetCursorShape(loop.BLOCK_CURSOR, true) } func (h *handler) draw_screen() (err error) {