diff --git a/kitty/main.py b/kitty/main.py index e46e4fb80..5f4c7c959 100644 --- a/kitty/main.py +++ b/kitty/main.py @@ -98,6 +98,11 @@ def option_parser(): default=None, help=_('Replay previously dumped commands') ) + a( + '--dump-bytes', + help=_('Path to file in which to store the raw bytes received from the' + ' child process. Useful for debugging.') + ) a( '--debug-gl', action='store_true', diff --git a/kitty/parser.c b/kitty/parser.c index 53ac0c6fe..dbf03ae2c 100644 --- a/kitty/parser.c +++ b/kitty/parser.c @@ -753,6 +753,11 @@ FNAME(read_bytes)(PyObject UNUSED *self, PyObject *args) { /* PyObject_Print(Py_BuildValue("y#", screen->read_buf, len), stderr, 0); */ break; } +#ifdef DUMP_COMMANDS + if (len > 0) { + Py_XDECREF(PyObject_CallFunction(dump_callback, "sy#", "bytes", screen->read_buf, len)); PyErr_Clear(); + } +#endif _parse_bytes(screen, screen->read_buf, len, dump_callback); if(len > 0) { Py_RETURN_TRUE; } Py_RETURN_FALSE; diff --git a/kitty/window.py b/kitty/window.py index ef2f1b6c4..c49d9c8bb 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -39,7 +39,9 @@ class Window: self.child_fd = child.child_fd self.start_visual_bell_at = None self.screen = Screen(self, 24, 80, opts.scrollback_lines) - self.read_bytes = partial(read_bytes_dump, self.dump_commands) if args.dump_commands else read_bytes + self.read_bytes = partial(read_bytes_dump, self.dump_commands) if args.dump_commands or args.dump_bytes else read_bytes + if args.dump_bytes: + self.dump_bytes_to = open(args.dump_bytes, 'ab') self.draw_dump_buf = [] self.write_buf = memoryview(b'') self.char_grid = CharGrid(self.screen, opts) @@ -347,6 +349,9 @@ class Window: self.draw_dump_buf = [] else: self.draw_dump_buf.append(a[1]) + elif a[0] == 'bytes': + self.dump_bytes_to.write(a[1]) + self.dump_bytes_to.flush() else: if self.draw_dump_buf: safe_print('draw', ''.join(self.draw_dump_buf))