@@ -1329,16 +1329,16 @@ test "writeClipboard - chunks large payload through GNU Screen passthrough" {
13291329 try term .writeClipboard (& writer , .clipboard , payload );
13301330
13311331 const output = writer .getWritten ();
1332- try testing .expect ( countSubstring ( output , ansi . ANSI . screenDcsStart ) > 1 );
1333- try testing .expect ( std . mem . endsWith ( u8 , output , ansi . ANSI . screenDcsEnd ) );
1334-
1335- var frame_start : usize = 0 ;
1336- while ( std . mem . findPos (u8 , output , frame_start , ansi . ANSI . screenDcsStart )) | start | {
1337- const content_start = start + ansi . ANSI . screenDcsStart . len ;
1338- const next_start = std . mem . findPos ( u8 , output , content_start , ansi . ANSI . screenDcsStart ) orelse output .len ;
1339- try testing . expect ( next_start - content_start <= Terminal . SCREEN_PASSTHROUGH_CHUNK_SIZE + ansi . ANSI . screenDcsEnd .len );
1340- frame_start = next_start ;
1341- }
1332+ const forwarded_buffer = try testing .allocator . alloc ( u8 , output . len );
1333+ defer testing .allocator . free ( forwarded_buffer );
1334+ const forwarded = try forwardScreenDcs ( output , forwarded_buffer );
1335+ const encoded_len = std . base64 . standard . Encoder . calcSize ( payload . len ) ;
1336+ const expected = try testing . allocator . alloc (u8 , " \x1b ]52;c;" .len + encoded_len + 1 );
1337+ defer testing . allocator . free ( expected ) ;
1338+ @memcpy ( expected [0 .. " \x1b ]52;c;" .len ], " \x1b ]52;c;" ) ;
1339+ _ = std . base64 . standard . Encoder . encode ( expected [ " \x1b ]52;c;" .len .. expected .len - 1 ], payload );
1340+ expected [ expected . len - 1 ] = ' \x07 ' ;
1341+ try testing . expectEqualSlices ( u8 , expected , forwarded );
13421342}
13431343
13441344test "writeClipboard - base64 encodes raw UTF-8 bytes" {
@@ -1431,15 +1431,15 @@ test "writeClipboard - Screen framing crosses the 252-byte boundary" {
14311431 try env .put ("STY" , "12345.pts-0.hostname" );
14321432 var term = Terminal .init (.{ .env_map = & env });
14331433
1434- const payload_one_chunk = [_ ]u8 {'A' } ** 180 ;
1434+ const payload_one_chunk = [_ ]u8 {'A' } ** 183 ;
14351435 var writer = TestWriter .init (testing .allocator );
14361436 defer writer .deinit ();
14371437 try term .writeClipboard (& writer , .clipboard , & payload_one_chunk );
14381438 try testing .expectEqual (@as (usize , 1 ), countSubstring (writer .getWritten (), ansi .ANSI .screenDcsStart ));
14391439 try testing .expectEqual (try term .clipboardSequenceSize (payload_one_chunk .len ), writer .getWritten ().len );
14401440
14411441 writer .reset ();
1442- const payload_two_chunks = [_ ]u8 {'A' } ** 181 ;
1442+ const payload_two_chunks = [_ ]u8 {'A' } ** 184 ;
14431443 try term .writeClipboard (& writer , .clipboard , & payload_two_chunks );
14441444 try testing .expectEqual (@as (usize , 2 ), countSubstring (writer .getWritten (), ansi .ANSI .screenDcsStart ));
14451445 try testing .expectEqual (try term .clipboardSequenceSize (payload_two_chunks .len ), writer .getWritten ().len );
@@ -1477,21 +1477,13 @@ test "writeClipboard - wraps in DCS passthrough for GNU Screen" {
14771477 try env .put ("STY" , "12345.pts-0.hostname" );
14781478
14791479 var term = Terminal .init (.{ .env_map = & env });
1480- term .caps .osc52 = true ;
14811480
14821481 var writer = TestWriter .init (testing .allocator );
14831482 defer writer .deinit ();
14841483
14851484 try term .writeClipboard (& writer , .clipboard , "test" );
14861485
1487- const output = writer .getWritten ();
1488- // Should start with DCS (but not tmux prefix)
1489- try testing .expect (std .mem .startsWith (u8 , output , "\x1b P" ));
1490- try testing .expect (! std .mem .startsWith (u8 , output , "\x1b Ptmux;" ));
1491- // Should end with DCS terminator
1492- try testing .expect (std .mem .endsWith (u8 , output , "\x1b \\ " ));
1493- // Should have doubled ESC characters
1494- try testing .expect (std .mem .find (u8 , output , "\x1b\x1b " ) != null );
1486+ try testing .expectEqualStrings ("\x1b P\x1b ]52;c;dGVzdA==\x07\x1b \\ " , writer .getWritten ());
14951487}
14961488
14971489test "writeClipboard - handles tmux sessions" {
@@ -1542,6 +1534,27 @@ fn countSubstring(haystack: []const u8, needle: []const u8) usize {
15421534 return count ;
15431535}
15441536
1537+ fn forwardScreenDcs (input : []const u8 , output : []u8 ) ! []const u8 {
1538+ var input_offset : usize = 0 ;
1539+ var output_offset : usize = 0 ;
1540+ while (input_offset < input .len ) {
1541+ if (! std .mem .startsWith (u8 , input [input_offset .. ], ansi .ANSI .screenDcsStart )) {
1542+ return error .InvalidScreenDcsStart ;
1543+ }
1544+ const content_start = input_offset + ansi .ANSI .screenDcsStart .len ;
1545+ const end_offset = std .mem .find (u8 , input [content_start .. ], ansi .ANSI .screenDcsEnd ) orelse {
1546+ return error .MissingScreenDcsEnd ;
1547+ };
1548+ const content = input [content_start .. content_start + end_offset ];
1549+ if (content .len > Terminal .SCREEN_PASSTHROUGH_CHUNK_SIZE ) return error .ScreenDcsPayloadTooLarge ;
1550+ if (output_offset + content .len > output .len ) return error .ScreenDcsOutputTooSmall ;
1551+ @memcpy (output [output_offset .. output_offset + content .len ], content );
1552+ output_offset += content .len ;
1553+ input_offset = content_start + end_offset + ansi .ANSI .screenDcsEnd .len ;
1554+ }
1555+ return output [0.. output_offset ];
1556+ }
1557+
15451558test "queryTerminalSend - skips OSC 66 queries when OPENTUI_FORCE_EXPLICIT_WIDTH=false" {
15461559 if (builtin .os .tag == .windows ) return error .SkipZigTest ;
15471560
0 commit comments