This commit is contained in:
Kovid Goyal
2024-05-14 22:44:06 +05:30
parent 9cdc1674cf
commit 4ab8c16184

View File

@@ -1,8 +1,12 @@
from enum import Enum, IntEnum, auto
from typing import Callable, Dict, List, Literal, NamedTuple, Tuple, TypedDict, Union
from typing import TYPE_CHECKING, Callable, Dict, List, Literal, NamedTuple, Tuple, TypedDict, Union
from kitty.types import run_once
from kitty.typing import CoreTextFont, FontConfigPattern
if TYPE_CHECKING:
import re
class ListedFont(TypedDict):
family: str
@@ -162,6 +166,11 @@ Descriptor = Union[FontConfigPattern, CoreTextFont]
Scorer = Callable[[Descriptor], Score]
def family_name_to_key(family: str) -> str:
@run_once
def fnname_pat() -> 're.Pattern[str]':
import re
return re.sub(r'\s+', ' ', family.lower())
return re.compile(r'\s+')
def family_name_to_key(family: str) -> str:
return fnname_pat().sub(' ', family).strip().lower()