mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-06 01:05:48 +02:00
Wire up the backend
This commit is contained in:
30
kittens/choose_fonts/backend.py
Normal file
30
kittens/choose_fonts/backend.py
Normal file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env python
|
||||
# License: GPLv3 Copyright: 2024, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
import json
|
||||
import sys
|
||||
from typing import Any
|
||||
|
||||
from kitty.fonts.common import get_variable_data_for_descriptor
|
||||
from kitty.fonts.list import create_family_groups
|
||||
|
||||
|
||||
def send_to_kitten(x: Any) -> None:
|
||||
sys.stdout.buffer.write(json.dumps(x).encode())
|
||||
sys.stdout.buffer.write(b'\n')
|
||||
sys.stdout.buffer.flush()
|
||||
|
||||
|
||||
def main() -> None:
|
||||
for line in sys.stdin.buffer:
|
||||
cmd = json.loads(line)
|
||||
action = cmd.get('action', '')
|
||||
if action == 'list_monospaced_fonts':
|
||||
send_to_kitten(create_family_groups())
|
||||
elif action == 'read_variable_data':
|
||||
ans = []
|
||||
for descriptor in cmd['descriptors']:
|
||||
ans.append(get_variable_data_for_descriptor(descriptor))
|
||||
send_to_kitten(ans)
|
||||
else:
|
||||
raise SystemExit(f'Unknown action: {action}')
|
||||
@@ -178,7 +178,7 @@ func (h *handler) handle_listing_key_event(event *loop.KeyEvent) (err error) {
|
||||
h.update_family_search()
|
||||
h.draw_screen()
|
||||
} else {
|
||||
h.lp.Quit(1)
|
||||
return fmt.Errorf("canceled by user")
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -241,7 +241,7 @@ func (h *handler) initialize() {
|
||||
h.draw_screen()
|
||||
initialize_variable_data_cache()
|
||||
go func() {
|
||||
h.set_worker_error(kitty_font_backend.query("list_all_fonts", nil, &h.fonts))
|
||||
h.set_worker_error(kitty_font_backend.query("list_monospaced_fonts", nil, &h.fonts))
|
||||
h.lp.WakeupMainThread()
|
||||
}()
|
||||
}
|
||||
@@ -290,8 +290,7 @@ func (h *handler) on_mouse_event(event *loop.MouseEvent) (err error) {
|
||||
func (h *handler) on_key_event(event *loop.KeyEvent) (err error) {
|
||||
if event.MatchesPressOrRepeat("ctrl+c") {
|
||||
event.Handled = true
|
||||
h.lp.Quit(1)
|
||||
return nil
|
||||
return fmt.Errorf("canceled by user")
|
||||
}
|
||||
switch h.state {
|
||||
case LISTING_FAMILIES:
|
||||
|
||||
Reference in New Issue
Block a user