mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-02 12:44:01 +02:00
Work on listing available styles for a family
This commit is contained in:
@@ -6,6 +6,7 @@ from kitty.typing import CoreTextFont, FontConfigPattern
|
||||
|
||||
class ListedFont(TypedDict):
|
||||
family: str
|
||||
style: str
|
||||
full_name: str
|
||||
postscript_name: str
|
||||
is_monospace: bool
|
||||
|
||||
@@ -47,7 +47,7 @@ def list_fonts() -> Generator[ListedFont, None, None]:
|
||||
if not fn:
|
||||
fn = f'{f} {fd["style"]}'.strip()
|
||||
yield {'family': f, 'full_name': fn, 'postscript_name': fd['postscript_name'] or '', 'is_monospace': fd['monospace'],
|
||||
'is_variable': fd['variable'], 'descriptor': fd}
|
||||
'is_variable': fd['variable'], 'descriptor': fd, 'style': fd['style']}
|
||||
|
||||
|
||||
def create_scorer(bold: bool = False, italic: bool = False, monospaced: bool = True, prefer_variable: bool = False) -> Scorer:
|
||||
|
||||
@@ -61,6 +61,7 @@ def list_fonts(only_variable: bool = False) -> Generator[ListedFont, None, None]
|
||||
yield {
|
||||
'family': f, 'full_name': fn, 'postscript_name': str(fd.get('postscript_name', '')),
|
||||
'is_monospace': is_mono, 'descriptor': fd, 'is_variable': fd.get('variable', False),
|
||||
'style': fd['style'],
|
||||
}
|
||||
|
||||
|
||||
|
||||
35
tools/cmd/list_fonts/styles.go
Normal file
35
tools/cmd/list_fonts/styles.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package list_fonts
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"kitty/tools/utils"
|
||||
)
|
||||
|
||||
var _ = fmt.Print
|
||||
|
||||
func styles_in_family(family string, fonts []ListedFont) (ans []string, is_variable bool) {
|
||||
has_style_attribute_data := false
|
||||
for _, f := range fonts {
|
||||
vd := variable_data_for(f)
|
||||
if len(vd.Design_axes) > 0 {
|
||||
has_style_attribute_data = true
|
||||
break
|
||||
}
|
||||
}
|
||||
ans = make([]string, 0)
|
||||
seen := utils.NewSet[string]()
|
||||
add := func(x string) {
|
||||
if !seen.Has(x) {
|
||||
seen.Add(x)
|
||||
ans = append(ans, x)
|
||||
}
|
||||
}
|
||||
if has_style_attribute_data {
|
||||
} else {
|
||||
for _, f := range fonts {
|
||||
add(f.Style)
|
||||
}
|
||||
}
|
||||
debugprintln(111111111, family, has_style_attribute_data, ans)
|
||||
return
|
||||
}
|
||||
@@ -45,6 +45,7 @@ type MultiAxisStyle struct {
|
||||
|
||||
type ListedFont struct {
|
||||
Family string `json:"family"`
|
||||
Style string `json:"style"`
|
||||
Fullname string `json:"full_name"`
|
||||
Postscript_name string `json:"postscript_name"`
|
||||
Is_monospace bool `json:"is_monospace"`
|
||||
|
||||
@@ -83,6 +83,7 @@ func (h *handler) draw_family_summary(start_x int, sz loop.ScreenSize) (err erro
|
||||
return fmt.Errorf("The family: %s has no fonts", family)
|
||||
}
|
||||
if has_variable_data_for_font(fonts[0]) {
|
||||
styles_in_family(family, fonts)
|
||||
} else {
|
||||
lines = append(lines, "Reading font data, please wait…")
|
||||
key := fonts[0].cache_key()
|
||||
@@ -261,11 +262,9 @@ func (h *handler) on_wakeup() (err error) {
|
||||
case SCANNING_FAMILIES:
|
||||
h.state = LISTING_FAMILIES
|
||||
h.family_list.UpdateFamilies(utils.StableSortWithKey(maps.Keys(h.fonts), strings.ToLower))
|
||||
return h.draw_screen()
|
||||
case LISTING_FAMILIES:
|
||||
return h.draw_screen()
|
||||
}
|
||||
return
|
||||
return h.draw_screen()
|
||||
}
|
||||
|
||||
func (h *handler) on_key_event(event *loop.KeyEvent) (err error) {
|
||||
|
||||
Reference in New Issue
Block a user