Merge branch 'copilot/add-dnd-command-support' of https://github.com/kovidgoyal/kitty

This commit is contained in:
Kovid Goyal 2026-05-17 21:31:36 +05:30
commit 4dd2f54683
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
2 changed files with 27 additions and 3 deletions

View file

@ -308,7 +308,7 @@ def fmt(x: Any) -> Any:
if isinstance(x, (bytes, memoryview)):
return str(x, 'utf-8', 'replace')
if isinstance(x, dict):
return json.dumps(x)
return json.dumps({k: fmt(v) for k, v in x.items()})
return x
safe_print(what, *map(fmt, a), flush=True)
# }}}

View file

@ -12,7 +12,7 @@
from contextlib import suppress
from typing import Any
from .fast_data_types import TEXT_SIZE_CODE
from .fast_data_types import DND_CODE, TEXT_SIZE_CODE
CSI = '\x1b['
OSC = '\x1b]'
@ -278,6 +278,30 @@ def clipboard_control(payload: str) -> None:
write(f'{OSC}{payload}\x07')
def dnd_command(payload: str) -> None:
c = json.loads(payload)
text = c.pop('', '')
t = c.pop('type', 'a')
if isinstance(t, (bytes, memoryview)):
t = str(t, 'utf-8', 'replace')
m = f't={t}'
if (more := c.pop('more', None)):
m += f':m={more}'
if (client_id := c.pop('client_id', None)):
m += f':i={client_id}'
if (operation := c.pop('operation', None)):
m += f':o={operation}'
if (cell_x := c.pop('cell_x', None)):
m += f':x={cell_x}'
if (cell_y := c.pop('cell_y', None)):
m += f':y={cell_y}'
if (pixel_x := c.pop('pixel_x', None)):
m += f':X={pixel_x}'
if (pixel_y := c.pop('pixel_y', None)):
m += f':Y={pixel_y}'
write(f'{OSC}{DND_CODE};{m};{text}\x1b\\')
def multicell_command(payload: str) -> None:
c = json.loads(payload)
text = c.pop('', '')
@ -306,7 +330,7 @@ def screen_multi_cursor(rest: str) -> None:
def replay(raw: str) -> None:
specials = frozenset({
'draw', 'set_title', 'set_icon', 'set_dynamic_color', 'set_color_table_color', 'select_graphic_rendition',
'process_cwd_notification', 'clipboard_control', 'shell_prompt_marking', 'multicell_command', 'screen_multi_cursor',
'process_cwd_notification', 'clipboard_control', 'shell_prompt_marking', 'multicell_command', 'screen_multi_cursor', 'dnd_command',
})
for line in raw.splitlines():
if line.strip() and not line.startswith('#'):