From f85030875eb8da1a117753a9b447db2bda78061b Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Sat, 15 Aug 2026 01:12:08 +0000 Subject: [PATCH] Loop: preserve partial sequences across reads Account for both retained and newly read bytes when parsing a sequence split across TTY reads. Fixes #359 Fixes #360 Amp-Thread-ID: https://ampcode.com/threads/T-01a002d1-a0c6-7643-9537-afd697b81cac Co-authored-by: Tim Culverhouse --- src/Loop.zig | 5 +++-- 1 file(s) changed, 3 insertion(s)(+), 2 deletion(s)(-) diff --git a/src/Loop.zig b/src/Loop.zig --- a/src/Loop.zig +++ b/src/Loop.zig @@ -190,7 +190,8 @@ var read_start: usize = 0; // read loop read_loop: while (!self.should_quit) { - const n = try self.tty.read(buf[read_start..]); + const bytes_read = try self.tty.read(buf[read_start..]); + const n = read_start + bytes_read; var seq_start: usize = 0; while (seq_start < n) { const result = try parser.parse(buf[seq_start..n], paste_allocator); @@ -201,7 +202,7 @@ while (seq_start < n) : (seq_start += 1) { buf[seq_start - initial_start] = buf[seq_start]; } - read_start = seq_start - initial_start + 1; + read_start = seq_start - initial_start; continue :read_loop; } read_start = 0; -- tangled.sh