From 1ef895e246b5302f323deba391959d9c5f13e4a3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 3 Jul 2021 12:07:46 +0530 Subject: [PATCH] When dumping commands dump stop_pending_mode at the correct place --- kitty/parser.c | 10 ++++++++-- kitty/screen.h | 1 + kitty_tests/parser.py | 20 ++++++++++---------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/kitty/parser.c b/kitty/parser.c index 14cfab091..056c2fc84 100644 --- a/kitty/parser.c +++ b/kitty/parser.c @@ -1382,7 +1382,7 @@ pending_dcs(Screen *screen, PyObject *dump_callback DUMP_UNUSED) { REPORT_COMMAND(screen_start_pending_mode); screen->pending_mode.activated_at = monotonic(); } else { - REPORT_COMMAND(screen_stop_pending_mode); + screen->pending_mode.stop_escape_code_type = DCS; screen->pending_mode.activated_at = 0; } } else pending_escape_code(screen, DCS, ST); @@ -1395,8 +1395,8 @@ pending_csi(Screen *screen, PyObject *dump_callback DUMP_UNUSED) { REPORT_COMMAND(screen_set_mode, 2026, 1); screen->pending_mode.activated_at = monotonic(); } else { - REPORT_COMMAND(screen_reset_mode, 2026, 1); screen->pending_mode.activated_at = 0; + screen->pending_mode.stop_escape_code_type = CSI; } } else pending_escape_code(screen, CSI, pb(screen->parser_buf_pos)); } @@ -1456,6 +1456,11 @@ do_parse_bytes(Screen *screen, const uint8_t *read_buf, const size_t read_buf_sz _parse_bytes(screen, screen->pending_mode.buf, screen->pending_mode.used, dump_callback); screen->pending_mode.used = 0; screen->pending_mode.activated_at = 0; // ignore any pending starts in the pending bytes + if (screen->pending_mode.stop_escape_code_type) { + if (screen->pending_mode.stop_escape_code_type == DCS) { REPORT_COMMAND(screen_stop_pending_mode); } + else if (screen->pending_mode.stop_escape_code_type == CSI) { REPORT_COMMAND(screen_reset_mode, 2026, 1); } + screen->pending_mode.stop_escape_code_type = 0; + } state = START; break; @@ -1467,6 +1472,7 @@ do_parse_bytes(Screen *screen, const uint8_t *read_buf, const size_t read_buf_sz case QUEUE_PENDING: { const size_t needed_space = read_buf_sz * 2; + screen->pending_mode.stop_escape_code_type = 0; if (screen->pending_mode.capacity - screen->pending_mode.used < needed_space) { if (screen->pending_mode.capacity >= READ_BUF_SZ) { dump_partial_escape_code_to_pending(screen); diff --git a/kitty/screen.h b/kitty/screen.h index bece5ae39..0ff8de8ff 100644 --- a/kitty/screen.h +++ b/kitty/screen.h @@ -119,6 +119,7 @@ typedef struct { size_t capacity, used; uint8_t *buf; monotonic_t activated_at, wait_time; + unsigned stop_escape_code_type; } pending_mode; DisableLigature disable_ligatures; PyObject *marker; diff --git a/kitty_tests/parser.py b/kitty_tests/parser.py index ffe4efc3a..477697b0f 100644 --- a/kitty_tests/parser.py +++ b/kitty_tests/parser.py @@ -347,7 +347,7 @@ class TestParser(BaseTest): pb('\033P=1s\033\\', ('screen_start_pending_mode',)) pb('a') self.ae(str(s.line(0)), '') - pb('\033P=2s\033\\', ('screen_stop_pending_mode',), ('draw', 'a')) + pb('\033P=2s\033\\', ('draw', 'a'), ('screen_stop_pending_mode',)) self.ae(str(s.line(0)), 'a') pb('\033P=1s\033\\', ('screen_start_pending_mode',)) pb('b') @@ -356,20 +356,20 @@ class TestParser(BaseTest): pb('c', ('draw', 'bc')) self.ae(str(s.line(0)), 'abc') pb('\033P=1s\033\\d', ('screen_start_pending_mode',)) - pb('\033P=2s\033\\', ('screen_stop_pending_mode',), ('draw', 'd')) + pb('\033P=2s\033\\', ('draw', 'd'), ('screen_stop_pending_mode',)) pb('\033P=1s\033\\e', ('screen_start_pending_mode',)) pb('\033P'), pb('='), pb('2s') - pb('\033\\', ('screen_stop_pending_mode',), ('draw', 'e')) - pb('\033P=1sxyz;.;\033\\''\033P=2skjf".,>