Commit af0e1f3

Eric Bower  ·  2026-04-08 23:05:34 -0400 EDT
parent 3971f2d
chore: cleanup util formatting
1 files changed,  +32, -52
+32, -52
......@@ -339,11 +339,13 @@ pub fn serializeTerminalState(alloc: std.mem.Allocator, term: *ghostty_vt.Termin
339339 sb_bottom.x = @intCast(pages.cols - 1);
340340
341341 var scroll_fmt = ghostty_vt.formatter.TerminalFormatter.init(term, .vt);
342- scroll_fmt.content = .{ .selection = ghostty_vt.Selection.init(
343- screen_top,
344- sb_bottom,
345- false,
346- ) };
342+ scroll_fmt.content = .{
343+ .selection = ghostty_vt.Selection.init(
344+ screen_top,
345+ sb_bottom,
346+ false,
347+ ),
348+ };
347349 scroll_fmt.extra = .none; // no modes, cursor, keyboard — just content
348350 scroll_fmt.format(&builder.writer) catch |err| {
349351 std.log.warn("failed to format scrollback err={s}", .{@errorName(err)});
......@@ -361,17 +363,21 @@ pub fn serializeTerminalState(alloc: std.mem.Allocator, term: *ghostty_vt.Termin
361363
362364 // Restrict content to the active viewport only
363365 const active_tl = pages.pin(.{ .active = .{ .x = 0, .y = 0 } });
364- const active_br = pages.pin(.{ .active = .{
365- .x = @intCast(pages.cols - 1),
366- .y = @intCast(pages.rows - 1),
367- } });
366+ const active_br = pages.pin(.{
367+ .active = .{
368+ .x = @intCast(pages.cols - 1),
369+ .y = @intCast(pages.rows - 1),
370+ },
371+ });
368372
369373 if (active_tl != null and active_br != null) {
370- vis_fmt.content = .{ .selection = ghostty_vt.Selection.init(
371- active_tl.?,
372- active_br.?,
373- false,
374- ) };
374+ vis_fmt.content = .{
375+ .selection = ghostty_vt.Selection.init(
376+ active_tl.?,
377+ active_br.?,
378+ false,
379+ ),
380+ };
375381 }
376382 // Fallback: if pins are somehow invalid, use null selection (all content)
377383
......@@ -815,20 +821,6 @@ test "serializeTerminalState excludes synchronized output replay" {
815821 try std.testing.expect(std.mem.indexOf(u8, output, "\x1b[?2026h") == null);
816822 }
817823
818-// ---------------------------------------------------------------------------
819-// Integration tests: serializeTerminalState roundtrip verification
820-//
821-// These tests exercise the ghostty-vt roundtrip pattern:
822-// 1. Create Terminal A, feed VT sequences (scrollback, markers, cursor)
823-// 2. Serialize A via serializeTerminalState()
824-// 3. Create Terminal B (same dimensions), feed serialized bytes
825-// 4. Compare B's screen content and cursor with A's
826-//
827-// This verifies that what the user sees after re-attach matches what the
828-// daemon's terminal state actually contains — including in nested sessions
829-// (zmx→SSH→zmx) where serialized state flows through multiple layers.
830-// ---------------------------------------------------------------------------
831-
832824 fn testCreateTerminal(alloc: std.mem.Allocator, cols: u16, rows: u16, vt_data: []const u8) !ghostty_vt.Terminal {
833825 var term = try ghostty_vt.Terminal.init(alloc, .{
834826 .cols = cols,
......@@ -892,8 +884,7 @@ fn expectMarkerAtRow(alloc: std.mem.Allocator, term: *ghostty_vt.Terminal, marke
892884 test "serializeTerminalState roundtrip preserves cursor position" {
893885 const alloc = std.testing.allocator;
894886
895- var term = try testCreateTerminal(alloc, 80, 24,
896- "\x1b[2J" ++ // clear
887+ var term = try testCreateTerminal(alloc, 80, 24, "\x1b[2J" ++ // clear
897888 "\x1b[10;20H" // cursor at row 10, col 20 (1-indexed)
898889 );
899890 defer term.deinit(alloc);
......@@ -909,14 +900,12 @@ test "serializeTerminalState roundtrip preserves cursor position" {
909900 test "serializeTerminalState roundtrip preserves CUP-positioned markers" {
910901 const alloc = std.testing.allocator;
911902
912- var term = try testCreateTerminal(alloc, 80, 24,
913- "\x1b[2J" ++
903+ var term = try testCreateTerminal(alloc, 80, 24, "\x1b[2J" ++
914904 "\x1b[2;5HMARK_A" ++
915905 "\x1b[6;15HMARK_B" ++
916906 "\x1b[10;30HMARK_C" ++
917907 "\x1b[14;50HMARK_D" ++
918- "\x1b[16;20H"
919- );
908+ "\x1b[16;20H");
920909 defer term.deinit(alloc);
921910
922911 var client = try serializeRoundtrip(alloc, &term);
......@@ -947,13 +936,11 @@ test "serializeTerminalState with scrollback preserves visible content" {
947936 }
948937
949938 // Clear screen and place markers at specific positions
950- try stream.nextSlice(
951- "\x1b[2J" ++
939+ try stream.nextSlice("\x1b[2J" ++
952940 "\x1b[2;5HMARK_A" ++
953941 "\x1b[6;15HMARK_B" ++
954942 "\x1b[10;30HMARK_C" ++
955- "\x1b[16;20H"
956- );
943+ "\x1b[16;20H");
957944
958945 // Verify source terminal has scrollback
959946 const pages = &term.screens.active.pages;
......@@ -989,12 +976,10 @@ test "serializeTerminalState nested roundtrip preserves content" {
989976 const line = std.fmt.bufPrint(&buf, "SCROLL_{d}\r\n", .{i}) catch unreachable;
990977 try inner_stream.nextSlice(line);
991978 }
992- try inner_stream.nextSlice(
993- "\x1b[2J" ++
979+ try inner_stream.nextSlice("\x1b[2J" ++
994980 "\x1b[3;10HINNER_A" ++
995981 "\x1b[12;25HINNER_B" ++
996- "\x1b[20;5H"
997- );
982+ "\x1b[20;5H");
998983 }
999984
1000985 // Record inner's ground truth
......@@ -1030,8 +1015,7 @@ test "serializeTerminalState nested roundtrip preserves content" {
10301015 test "serializeTerminalState alternate screen not leaked" {
10311016 const alloc = std.testing.allocator;
10321017
1033- var term = try testCreateTerminal(alloc, 80, 24,
1034- "\x1b[?1049h" ++ // enter alt screen
1018+ var term = try testCreateTerminal(alloc, 80, 24, "\x1b[?1049h" ++ // enter alt screen
10351019 "\x1b[2J\x1b[3;10HALT_MARK" ++ // write on alt screen
10361020 "\x1b[?1049l" ++ // exit alt screen
10371021 "\x1b[2J\x1b[2;5HMAIN_MARK\x1b[8;20H" // write on main screen
......@@ -1052,13 +1036,11 @@ test "serializeTerminalState alternate screen not leaked" {
10521036 test "serializeTerminalState size mismatch roundtrip" {
10531037 const alloc = std.testing.allocator;
10541038
1055- var term = try testCreateTerminal(alloc, 80, 30,
1056- "\x1b[2J" ++
1039+ var term = try testCreateTerminal(alloc, 80, 30, "\x1b[2J" ++
10571040 "\x1b[3;10HSIZE_A" ++
10581041 "\x1b[12;20HSIZE_B" ++
10591042 "\x1b[20;40HSIZE_C" ++
1060- "\x1b[15;15H"
1061- );
1043+ "\x1b[15;15H");
10621044 defer term.deinit(alloc);
10631045
10641046 // Resize to 24 rows (simulates outer terminal being smaller)
......@@ -1085,12 +1067,10 @@ test "serializeTerminalState scrollback + size mismatch nested roundtrip" {
10851067 const line = std.fmt.bufPrint(&buf, "LINE_{d}\r\n", .{i}) catch unreachable;
10861068 try inner_stream.nextSlice(line);
10871069 }
1088- try inner_stream.nextSlice(
1089- "\x1b[2J" ++
1070+ try inner_stream.nextSlice("\x1b[2J" ++
10901071 "\x1b[3;10HSTRESS_A" ++
10911072 "\x1b[12;25HSTRESS_B" ++
1092- "\x1b[16;20H"
1093- );
1073+ "\x1b[16;20H");
10941074 }
10951075
10961076 // Resize inner to 24 rows (outer terminal is smaller)