mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-15 04:54:14 +02:00
Render font feature list in UI
This commit is contained in:
@@ -127,6 +127,7 @@ def render_face_sample(font: Descriptor, opts: Options, dpi_x: float, dpi_y: flo
|
||||
'style': font['style'],
|
||||
'psname': face.postscript_name(),
|
||||
'features': get_features(face.get_features()),
|
||||
'applied_features': face.applied_features(),
|
||||
}
|
||||
if is_variable(font):
|
||||
ns = get_named_style(face)
|
||||
|
||||
@@ -125,6 +125,37 @@ func (self *face_panel) draw_family_style_select(_ loop.ScreenSize, start_y int,
|
||||
return y, nil
|
||||
}
|
||||
|
||||
func (self *face_panel) draw_font_features(_ loop.ScreenSize, start_y int, preview RenderedSampleTransmit) (y int, err error) {
|
||||
lp := self.handler.lp
|
||||
y = start_y
|
||||
if len(preview.Features) == 0 {
|
||||
return
|
||||
}
|
||||
formatted := make([]string, 0, len(preview.Features))
|
||||
for feat_tag, data := range preview.Features {
|
||||
var text string
|
||||
if preview.Applied_features[feat_tag] != "" {
|
||||
text = preview.Applied_features[feat_tag]
|
||||
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=cyan", "="), 1)
|
||||
if data.Name != "" {
|
||||
text = fmt.Sprintf("%s: %s", data.Name, text)
|
||||
}
|
||||
} else {
|
||||
text = utils.IfElse(data.Name == "", feat_tag, data.Name)
|
||||
text = lp.SprintStyled("dim", text)
|
||||
}
|
||||
formatted = append(formatted, tui.InternalHyperlink(text, "feature:"+feat_tag))
|
||||
}
|
||||
utils.SortWithKey(formatted, func(a string) string {
|
||||
return strings.ToLower(wcswidth.StripEscapeCodes(a))
|
||||
})
|
||||
line := lp.SprintStyled(control_name_style, `Features`) + ": " + strings.Join(formatted, ", ")
|
||||
y = self.render_lines(start_y, ``, line)
|
||||
return
|
||||
}
|
||||
|
||||
func (self *handler) draw_preview_header(x int) {
|
||||
sz, _ := self.lp.ScreenSize()
|
||||
width := int(sz.WidthCells) - x
|
||||
@@ -197,6 +228,9 @@ func (self *face_panel) draw_screen() (err error) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if y, err = self.draw_font_features(sz, y, preview); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if int(sz.HeightCells)-y >= num_lines+2 {
|
||||
y += 1
|
||||
|
||||
@@ -100,6 +100,7 @@ type RenderedSampleTransmit struct {
|
||||
Style string `json:"style"`
|
||||
Psname string `json:"psname"`
|
||||
Features map[string]FeatureData `json:"features"`
|
||||
Applied_features map[string]string `json:"applied_features"`
|
||||
Variable_named_style NamedStyle `json:"variable_named_style"`
|
||||
Variable_axis_map map[string]float64 `json:"variable_axis_map"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user