From a4193a1b029df2f5368d32f103de9bd3354f4f17 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 30 Oct 2023 08:27:03 +0530 Subject: [PATCH] Fix dumping of bytes/commands --- kitty/boss.py | 1 + kitty/client.py | 23 ++++++++++++++++++++++- kitty/vt-parser.c | 10 ++++++++-- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/kitty/boss.py b/kitty/boss.py index 032932423..023d32d4b 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -247,6 +247,7 @@ class DumpCommands: # {{{ if self.draw_dump_buf: safe_print('draw', ''.join(self.draw_dump_buf)) self.draw_dump_buf = [] + a = tuple(str(x, 'utf-8', 'replace') if isinstance(x, memoryview) else x for x in a) safe_print(*a) # }}} diff --git a/kitty/client.py b/kitty/client.py index e61b98da0..f280fcfa4 100644 --- a/kitty/client.py +++ b/kitty/client.py @@ -158,6 +158,22 @@ def screen_cursor_down(count: int) -> None: write(f'{CSI}{count}B') +def screen_report_key_encoding_flags() -> None: + write(f'{CSI}?u') + + +def screen_set_key_encoding_flags(flags: int, how: int) -> None: + write(f'{CSI}={flags};{how}u') + + +def screen_push_key_encoding_flags(flags: int) -> None: + write(f'{CSI}>{flags}u') + + +def screen_pop_key_encoding_flags(flags: int) -> None: + write(f'{CSI}<{flags}u') + + def screen_carriage_return() -> None: write('\r') @@ -214,10 +230,15 @@ def write_osc(code: int, string: str = '') -> None: write(f'{OSC}{code}\x07') -set_dynamic_color = set_color_table_color = process_cwd_notification = write_osc +set_color_table_color = process_cwd_notification = write_osc clipboard_control_pending: str = '' +def set_dynamic_color(payload: str) -> None: + code, data = payload.partition(' ')[::2] + write_osc(int(code), data) + + def shell_prompt_marking(payload: str) -> None: write_osc(133, payload) diff --git a/kitty/vt-parser.c b/kitty/vt-parser.c index b612dd3f6..9f8df82b1 100644 --- a/kitty/vt-parser.c +++ b/kitty/vt-parser.c @@ -1,11 +1,10 @@ /* - * bytes-parser.c + * vt-parser.c * Copyright (C) 2023 Kovid Goyal * * Distributed under terms of the GPL3 license. */ -// TODO: Fix dump_commands for OSC and DCS commands that used to take strings but now take memoryview // TODO: Test clipboard kitten with 52 and 5522 // TODO: Test shell integration with secondary prompts // TODO: Test screen_request_capabilities @@ -1593,6 +1592,13 @@ do_parse_vt(PS *self) { static void run_worker(Screen *screen, PyObject *dump_callback, monotonic_t now) { PS *self = (PS*)screen->vt_parser->state; +#ifdef DUMP_COMMANDS + if (screen->read_buf_sz && dump_callback) { + RAII_PyObject(mv, PyMemoryView_FromMemory((char*)screen->read_buf, screen->read_buf_sz, PyBUF_READ)); + PyObject *ret = PyObject_CallFunction(dump_callback, "sO", "bytes", mv); + if (ret) { Py_DECREF(ret); } else { PyErr_Clear(); } + } +#endif self->input_data = screen->read_buf; self->input_sz = screen->read_buf_sz; self->input_pos = 0; self->dump_callback = dump_callback; self->now = now; self->screen = screen; do_parse_vt(self);