mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-20 23:44:59 +02:00
Fix sorting of features in UI
This commit is contained in:
@@ -133,29 +133,33 @@ func (self *face_panel) draw_font_features(_ loop.ScreenSize, start_y int, previ
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
formatted := make([]string, 0, len(preview.Features))
|
formatted := make([]string, 0, len(preview.Features))
|
||||||
|
sort_keys := make(map[string]string)
|
||||||
for feat_tag, data := range preview.Features {
|
for feat_tag, data := range preview.Features {
|
||||||
var text string
|
var text, sort_key string
|
||||||
|
|
||||||
if preview.Applied_features[feat_tag] != "" {
|
if preview.Applied_features[feat_tag] != "" {
|
||||||
text = preview.Applied_features[feat_tag]
|
text = preview.Applied_features[feat_tag]
|
||||||
|
sort_key = text
|
||||||
|
if sort_key[0] == '-' || sort_key[1] == '+' {
|
||||||
|
sort_key = sort_key[1:]
|
||||||
|
}
|
||||||
text = strings.Replace(text, "+", lp.SprintStyled("fg=green", "+"), 1)
|
text = strings.Replace(text, "+", lp.SprintStyled("fg=green", "+"), 1)
|
||||||
text = strings.Replace(text, "-", lp.SprintStyled("fg=red", "-"), 1)
|
text = strings.Replace(text, "-", lp.SprintStyled("fg=red", "-"), 1)
|
||||||
text = strings.Replace(text, "=", lp.SprintStyled("fg=cyan", "="), 1)
|
text = strings.Replace(text, "=", lp.SprintStyled("fg=cyan", "="), 1)
|
||||||
if data.Name != "" {
|
if data.Name != "" {
|
||||||
text = fmt.Sprintf("%s: %s", data.Name, text)
|
text = data.Name + ": " + text
|
||||||
|
sort_key = data.Name
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
text = utils.IfElse(data.Name == "", feat_tag, data.Name)
|
text = utils.IfElse(data.Name == "", feat_tag, data.Name)
|
||||||
|
sort_key = text
|
||||||
text = lp.SprintStyled("dim", text)
|
text = lp.SprintStyled("dim", text)
|
||||||
}
|
}
|
||||||
formatted = append(formatted, tui.InternalHyperlink(text, "feature:"+feat_tag))
|
f := tui.InternalHyperlink(text, "feature:"+feat_tag)
|
||||||
|
sort_keys[f] = strings.ToLower(sort_key)
|
||||||
|
formatted = append(formatted, f)
|
||||||
}
|
}
|
||||||
utils.SortWithKey(formatted, func(a string) string {
|
utils.SortWithKey(formatted, func(a string) string { return sort_keys[a] })
|
||||||
ans := strings.ToLower(wcswidth.StripEscapeCodes(a))
|
|
||||||
if ans[0] == '-' || ans[0] == '+' {
|
|
||||||
ans = ans[1:]
|
|
||||||
}
|
|
||||||
return ans
|
|
||||||
})
|
|
||||||
line := lp.SprintStyled(control_name_style, `Features`) + ": " + strings.Join(formatted, ", ")
|
line := lp.SprintStyled(control_name_style, `Features`) + ": " + strings.Join(formatted, ", ")
|
||||||
y = self.render_lines(start_y, ``, line)
|
y = self.render_lines(start_y, ``, line)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"kitty/tools/tui"
|
||||||
"kitty/tools/tui/loop"
|
"kitty/tools/tui/loop"
|
||||||
"kitty/tools/tui/readline"
|
"kitty/tools/tui/readline"
|
||||||
"kitty/tools/utils"
|
"kitty/tools/utils"
|
||||||
@@ -49,6 +50,15 @@ func (self *if_panel) draw_screen() (err error) {
|
|||||||
}
|
}
|
||||||
lines = append(lines, "")
|
lines = append(lines, "")
|
||||||
cursor_y := self.render_lines(2, lines...)
|
cursor_y := self.render_lines(2, lines...)
|
||||||
|
if len(self.feature_data.Params) > 0 {
|
||||||
|
lp.MoveCursorTo(1, cursor_y+3)
|
||||||
|
num := 1
|
||||||
|
strings.Join(utils.Map(func(x string) string {
|
||||||
|
ans := tui.InternalHyperlink(x, fmt.Sprintf("fval:%d", num))
|
||||||
|
num++
|
||||||
|
return ans
|
||||||
|
}, self.feature_data.Params), ", ")
|
||||||
|
}
|
||||||
lp.MoveCursorTo(1, cursor_y+1)
|
lp.MoveCursorTo(1, cursor_y+1)
|
||||||
lp.ClearToEndOfLine()
|
lp.ClearToEndOfLine()
|
||||||
self.rl.RedrawNonAtomic()
|
self.rl.RedrawNonAtomic()
|
||||||
@@ -67,7 +77,17 @@ func (self *if_panel) on_wakeup() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *if_panel) on_click(id string) (err error) {
|
func (self *if_panel) on_click(id string) (err error) {
|
||||||
return
|
scheme, val, _ := strings.Cut(id, ":")
|
||||||
|
if scheme != "fval" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
v, _ := strconv.ParseUint(val, 10, 64)
|
||||||
|
|
||||||
|
if err = self.handler.face_pane.change_feature_value(self.feat_tag, uint(v), false); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
self.handler.current_pane = &self.handler.face_pane
|
||||||
|
return self.handler.draw_screen()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *if_panel) on_key_event(event *loop.KeyEvent) (err error) {
|
func (self *if_panel) on_key_event(event *loop.KeyEvent) (err error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user