mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-26 02:02:14 +02:00
More work on porting themes
This commit is contained in:
@@ -6,6 +6,8 @@ import (
|
||||
"fmt"
|
||||
|
||||
"kitty/tools/themes"
|
||||
"kitty/tools/utils"
|
||||
"kitty/tools/wcswidth"
|
||||
)
|
||||
|
||||
var _ = fmt.Print
|
||||
@@ -40,10 +42,58 @@ func (self *ThemesList) Next(delta int, allow_wrapping bool) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func limit_lengths(text string) string {
|
||||
t, x := wcswidth.TruncateToVisualLengthWithWidth(text, 31)
|
||||
if x >= len(text) {
|
||||
return text
|
||||
}
|
||||
return t + "…"
|
||||
}
|
||||
|
||||
func (self *ThemesList) UpdateThemes(themes *themes.Themes) {
|
||||
self.themes, self.all_themes = themes, themes
|
||||
if self.current_search != "" {
|
||||
self.themes = self.all_themes.Copy()
|
||||
self.display_strings = utils.Map(limit_lengths, self.themes.ApplySearch(self.current_search))
|
||||
} else {
|
||||
self.display_strings = utils.Map(limit_lengths, self.themes.Names())
|
||||
}
|
||||
self.widths = utils.Map(wcswidth.Stringwidth, self.display_strings)
|
||||
self.max_width = utils.Max(0, self.widths...)
|
||||
self.current_idx = 0
|
||||
}
|
||||
|
||||
func (self *ThemesList) UpdateSearch(query string) bool {
|
||||
if query == self.current_search || self.all_themes == nil {
|
||||
return false
|
||||
}
|
||||
self.current_search = query
|
||||
self.UpdateThemes(self.all_themes)
|
||||
return true
|
||||
}
|
||||
|
||||
type Line struct {
|
||||
text string
|
||||
width int
|
||||
is_current bool
|
||||
}
|
||||
|
||||
func (self *ThemesList) Lines(num_rows int) []Line {
|
||||
if num_rows < 1 {
|
||||
return nil
|
||||
}
|
||||
ans := make([]Line, 0, len(self.display_strings))
|
||||
before_num := utils.Min(self.current_idx, num_rows-1)
|
||||
start := self.current_idx - before_num
|
||||
for i := start; i < utils.Min(start+num_rows, len(self.display_strings)); i++ {
|
||||
ans = append(ans, Line{self.display_strings[i], self.widths[i], i == self.current_idx})
|
||||
}
|
||||
return ans
|
||||
}
|
||||
|
||||
func (self *ThemesList) CurrentTheme() *themes.Theme {
|
||||
if self.themes == nil {
|
||||
return nil
|
||||
}
|
||||
return self.themes.At(self.current_idx)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user