mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-18 14:34:52 +02:00
Load font variable data on demand
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
# License: GPL v3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
from typing import Any, BinaryIO, Dict, List, Optional, Sequence
|
||||
from typing import IO, Any, Dict, List, Optional, Sequence
|
||||
|
||||
from kitty.constants import is_macos
|
||||
|
||||
@@ -14,23 +14,21 @@ else:
|
||||
from .fontconfig import list_fonts, prune_family_group
|
||||
|
||||
|
||||
def create_family_groups(monospaced: bool = True, add_variable_data: bool = False) -> Dict[str, List[ListedFont]]:
|
||||
def create_family_groups(monospaced: bool = True) -> Dict[str, List[ListedFont]]:
|
||||
g: Dict[str, List[ListedFont]] = {}
|
||||
for f in list_fonts():
|
||||
if not monospaced or f['is_monospace']:
|
||||
g.setdefault(f['family'], []).append(f)
|
||||
if add_variable_data and f['is_variable']:
|
||||
f['variable_data'] = get_variable_data_for_descriptor(f['descriptor']) # type: ignore
|
||||
return {k: prune_family_group(v) for k, v in g.items()}
|
||||
|
||||
|
||||
def as_json(indent: Optional[int] = None) -> str:
|
||||
import json
|
||||
groups = create_family_groups(add_variable_data=True)
|
||||
groups = create_family_groups()
|
||||
return json.dumps(groups, indent=indent)
|
||||
|
||||
|
||||
def handle_io(from_kitten: BinaryIO, to_kitten: BinaryIO) -> None:
|
||||
def handle_io(from_kitten: IO[bytes], to_kitten: IO[bytes]) -> None:
|
||||
import json
|
||||
global exception_in_io_handler
|
||||
|
||||
@@ -39,12 +37,15 @@ def handle_io(from_kitten: BinaryIO, to_kitten: BinaryIO) -> None:
|
||||
to_kitten.write(b'\n')
|
||||
to_kitten.flush()
|
||||
|
||||
send_to_kitten(create_family_groups(add_variable_data=True))
|
||||
send_to_kitten(create_family_groups())
|
||||
for line in from_kitten:
|
||||
cmd = json.loads(line)
|
||||
action = cmd['action']
|
||||
if action == 'ping':
|
||||
send_to_kitten({'action': 'pong'})
|
||||
if action == 'read_variable_data':
|
||||
ans = []
|
||||
for descriptor in cmd['descriptors']:
|
||||
ans.append(get_variable_data_for_descriptor(descriptor))
|
||||
send_to_kitten(ans)
|
||||
|
||||
|
||||
def main(argv: Sequence[str]) -> None:
|
||||
@@ -59,6 +60,7 @@ def main(argv: Sequence[str]) -> None:
|
||||
if os.environ.get('KITTY_STDIO_FORWARDED'):
|
||||
pass_fds.append(int(os.environ['KITTY_STDIO_FORWARDED']))
|
||||
p = subprocess.Popen([kitten_exe(), '__list_fonts__'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, pass_fds=pass_fds)
|
||||
assert p.stdout is not None and p.stdin is not None
|
||||
try:
|
||||
handle_io(p.stdout, p.stdin)
|
||||
except Exception:
|
||||
|
||||
Reference in New Issue
Block a user