mirror of
https://github.com/kovidgoyal/kitty.git
synced 2024-11-13 12:09:35 +03:00
Dont construct memoryview when not needed in non dump code path
This commit is contained in:
parent
dcde461c02
commit
8a83014f51
@ -85,9 +85,9 @@ def cmd_for_report(report_name: str, keymap: KeymapType, type_map: Dict[str, Any
|
||||
|
||||
fmt = f'{flag_fmt} {uint_fmt} {int_fmt}'
|
||||
if payload_allowed:
|
||||
ans = [f'REPORT_VA_COMMAND("s {{{fmt} sI}} y#", "{report_name}",']
|
||||
ans = [f'REPORT_VA_COMMAND("K s {{{fmt} sI}} y#", self->window_id, "{report_name}", ']
|
||||
else:
|
||||
ans = [f'REPORT_VA_COMMAND("s {{{fmt}}}", "{report_name}",']
|
||||
ans = [f'REPORT_VA_COMMAND("K s {{{fmt}}}", self->window_id, "{report_name}", ']
|
||||
ans.append(',\n '.join((flag_attrs, uint_attrs, int_attrs)))
|
||||
if payload_allowed:
|
||||
ans.append(', "payload_sz", g.payload_sz, payload, g.payload_sz')
|
||||
|
31
kitty/parse-graphics-command.h
generated
31
kitty/parse-graphics-command.h
generated
@ -351,21 +351,22 @@ static inline void parse_graphics_code(PS *self, const uint8_t *parser_buf,
|
||||
}
|
||||
|
||||
REPORT_VA_COMMAND(
|
||||
"K s {sc sc sc sc sI sI sI sI sI sI sI sI sI sI sI sI sI sI sI sI sI sI sI "
|
||||
"sI sI sI si si si sI} y#", self->window_id, "graphics_command",
|
||||
"action", g.action, "delete_action", g.delete_action,
|
||||
"transmission_type", g.transmission_type, "compressed", g.compressed,
|
||||
"format", (unsigned int)g.format, "more", (unsigned int)g.more, "id",
|
||||
(unsigned int)g.id, "image_number", (unsigned int)g.image_number,
|
||||
"placement_id", (unsigned int)g.placement_id, "quiet",
|
||||
(unsigned int)g.quiet, "width", (unsigned int)g.width, "height",
|
||||
(unsigned int)g.height, "x_offset", (unsigned int)g.x_offset, "y_offset",
|
||||
(unsigned int)g.y_offset, "data_height", (unsigned int)g.data_height,
|
||||
"data_width", (unsigned int)g.data_width, "data_sz",
|
||||
(unsigned int)g.data_sz, "data_offset", (unsigned int)g.data_offset,
|
||||
"num_cells", (unsigned int)g.num_cells, "num_lines",
|
||||
(unsigned int)g.num_lines, "cell_x_offset", (unsigned int)g.cell_x_offset,
|
||||
"cell_y_offset", (unsigned int)g.cell_y_offset, "cursor_movement",
|
||||
"K s {sc sc sc sc sI sI sI sI sI sI sI sI sI sI sI sI sI sI sI sI sI sI "
|
||||
"sI sI sI sI si si si sI} y#",
|
||||
self->window_id, "graphics_command", "action", g.action, "delete_action",
|
||||
g.delete_action, "transmission_type", g.transmission_type, "compressed",
|
||||
g.compressed, "format", (unsigned int)g.format, "more",
|
||||
(unsigned int)g.more, "id", (unsigned int)g.id, "image_number",
|
||||
(unsigned int)g.image_number, "placement_id",
|
||||
(unsigned int)g.placement_id, "quiet", (unsigned int)g.quiet, "width",
|
||||
(unsigned int)g.width, "height", (unsigned int)g.height, "x_offset",
|
||||
(unsigned int)g.x_offset, "y_offset", (unsigned int)g.y_offset,
|
||||
"data_height", (unsigned int)g.data_height, "data_width",
|
||||
(unsigned int)g.data_width, "data_sz", (unsigned int)g.data_sz,
|
||||
"data_offset", (unsigned int)g.data_offset, "num_cells",
|
||||
(unsigned int)g.num_cells, "num_lines", (unsigned int)g.num_lines,
|
||||
"cell_x_offset", (unsigned int)g.cell_x_offset, "cell_y_offset",
|
||||
(unsigned int)g.cell_y_offset, "cursor_movement",
|
||||
(unsigned int)g.cursor_movement, "unicode_placement",
|
||||
(unsigned int)g.unicode_placement, "parent_id", (unsigned int)g.parent_id,
|
||||
"parent_placement_id", (unsigned int)g.parent_placement_id, "z_index",
|
||||
|
@ -6,7 +6,6 @@
|
||||
*/
|
||||
|
||||
// TODO: Test clipboard kitten with 52 and 5522
|
||||
// TODO: Test shell integration with secondary prompts
|
||||
// TODO: Test screen_request_capabilities
|
||||
|
||||
#include "vt-parser.h"
|
||||
@ -421,9 +420,10 @@ dispatch_osc(PS *self) {
|
||||
#define DISPATCH_OSC_WITH_CODE(name) REPORT_OSC2(name, code, mv); name(self->screen, code, mv);
|
||||
#define DISPATCH_OSC(name) REPORT_OSC(name, mv); name(self->screen, mv);
|
||||
#define START_DISPATCH {\
|
||||
PyObject *mv = PyMemoryView_FromMemory((char*)self->parser_buf + i, limit - i, PyBUF_READ); \
|
||||
RAII_PyObject(mv, PyMemoryView_FromMemory((char*)self->parser_buf + i, limit - i, PyBUF_READ)); \
|
||||
if (mv) {
|
||||
#define END_DISPATCH Py_CLEAR(mv); } PyErr_Clear(); break; }
|
||||
#define END_DISPATCH_WITHOUT_BREAK }; PyErr_Clear(); }
|
||||
#define END_DISPATCH }; PyErr_Clear(); break; }
|
||||
|
||||
const unsigned int limit = self->parser_buf_pos;
|
||||
int code=0;
|
||||
@ -462,10 +462,13 @@ dispatch_osc(PS *self) {
|
||||
END_DISPATCH
|
||||
case 6:
|
||||
case 7:
|
||||
#ifdef DUMP_COMMANDS
|
||||
START_DISPATCH
|
||||
REPORT_OSC2(process_cwd_notification, code, mv);
|
||||
END_DISPATCH_WITHOUT_BREAK
|
||||
#endif
|
||||
process_cwd_notification(self->screen, code, (char*)self->parser_buf + i, limit-i);
|
||||
END_DISPATCH
|
||||
break;
|
||||
case 8:
|
||||
dispatch_hyperlink(self, i, limit-i);
|
||||
break;
|
||||
@ -496,13 +499,16 @@ dispatch_osc(PS *self) {
|
||||
if (code == -52) continue_osc_52(self);
|
||||
END_DISPATCH
|
||||
case 133:
|
||||
#ifdef DUMP_COMMANDS
|
||||
START_DISPATCH
|
||||
REPORT_OSC2(shell_prompt_marking, code, mv);
|
||||
if (limit - 1 > 0) {
|
||||
END_DISPATCH_WITHOUT_BREAK
|
||||
#endif
|
||||
if (limit > i) {
|
||||
self->parser_buf[limit] = 0; // safe to do as we have 8 extra bytes after PARSER_BUF_SZ
|
||||
shell_prompt_marking(self->screen, (char*)self->parser_buf + i);
|
||||
}
|
||||
END_DISPATCH
|
||||
break;
|
||||
case FILE_TRANSFER_CODE:
|
||||
START_DISPATCH
|
||||
DISPATCH_OSC(file_transmission);
|
||||
|
@ -79,6 +79,11 @@ class TestParser(BaseTest):
|
||||
self.ae(str(s.line(3)), 'ßxyz1')
|
||||
pb('ニチ ', 'ニチ ')
|
||||
self.ae(str(s.line(4)), 'ニチ ')
|
||||
s.reset()
|
||||
self.assertFalse(str(s.line(1)) + str(s.line(2)) + str(s.line(3)))
|
||||
c1_controls = '\x84\x85\x88\x8d\x8e\x8f\x90\x96\x97\x98\x9a\x9b\x9c\x9d\x9e\x9f'
|
||||
pb(c1_controls, c1_controls)
|
||||
self.assertFalse(str(s.line(1)) + str(s.line(2)) + str(s.line(3)))
|
||||
|
||||
def test_esc_codes(self):
|
||||
s = self.create_screen()
|
||||
|
Loading…
Reference in New Issue
Block a user