From a661f00651e6df94475d076c3d7a3cc3c32913fd Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 17 May 2024 22:27:17 +0530 Subject: [PATCH] Fix the previous fix Store pending responses since the parser can call HandleDCS multiple times in a single Read() --- tools/cmd/at/socket_io.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/cmd/at/socket_io.go b/tools/cmd/at/socket_io.go index f3b3a5f48..9ea1abb52 100644 --- a/tools/cmd/at/socket_io.go +++ b/tools/cmd/at/socket_io.go @@ -45,15 +45,16 @@ func write_many_to_conn(conn *net.Conn, datums ...[]byte) error { } type response_reader struct { - parser wcswidth.EscapeCodeParser - storage [utils.DEFAULT_IO_BUFFER_SIZE]byte + parser wcswidth.EscapeCodeParser + storage [utils.DEFAULT_IO_BUFFER_SIZE]byte + pending_responses []string } func (r *response_reader) read_response_from_conn(conn *net.Conn, timeout time.Duration) (serialized_response []byte, err error) { keep_going := true r.parser.HandleDCS = func(data []byte) error { if bytes.HasPrefix(data, []byte("@kitty-cmd")) { - serialized_response = data[len("@kitty-cmd"):] + r.pending_responses = append(r.pending_responses, string(data[len("@kitty-cmd"):])) keep_going = false } return nil @@ -69,6 +70,10 @@ func (r *response_reader) read_response_from_conn(conn *net.Conn, timeout time.D } r.parser.Parse(buf[:n]) } + if len(r.pending_responses) > 0 { + serialized_response = utils.UnsafeStringToBytes(r.pending_responses[0]) + r.pending_responses = r.pending_responses[1:] + } return }