diff options
Diffstat (limited to 'core/term')
| -rw-r--r-- | core/term/terminal.zig | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/core/term/terminal.zig b/core/term/terminal.zig index 1673a3d8..187ed144 100644 --- a/core/term/terminal.zig +++ b/core/term/terminal.zig @@ -631,19 +631,30 @@ pub fn resize(state: *State, cols: u16, rows: u16, later: bool) void { state.resize_to = .{ .cols = cols, .rows = rows }; return; } - state.changes +%= 1; - state.vt.resize(state.gpa, .{ .cols = cols, .rows = rows }) catch {}; + reflow(state, cols, rows); } /// The size `resize` left for later, made; whether there was one. pub fn resizeDeferred(state: *State) bool { const size = state.resize_to orelse return false; state.resize_to = null; - state.changes +%= 1; - state.vt.resize(state.gpa, .{ .cols = size.cols, .rows = size.rows }) catch {}; + reflow(state, size.cols, size.rows); return true; } +/// Its grid reflowed, and its view a row of its history again, as `viewTo` +/// and `grid` have it: ghostty's view follows a cell, which a widening +/// can leave mid-row (a wrapped line's second row joined to its first) and +/// the next narrowing carries a row down, where a view put back at its row +/// (a replica's rollback, core/replica.zig `putViews`) stays. +fn reflow(state: *State, cols: u16, rows: u16) void { + state.changes +%= 1; + state.vt.resize(state.gpa, .{ .cols = cols, .rows = rows }) catch {}; + inline for (.{ .primary, .alternate }) |which| if (state.vt.screens.get(which)) |screen| { + if (screen.pages.viewport == .pin) screen.pages.viewport_pin.x = 0; + }; +} + /// The emulator's size in pixels follows the core's cells: kitty graphics /// placements are sized by it, and CSI 14/16 t report it. pub fn cellPixels(state: *State, w: u32, h: u32) void { @@ -1591,6 +1602,27 @@ pub fn images(state: *State, gpa: std.mem.Allocator, at: ImagesAt, out: *std.Arr state.images.draw(state.gpa, gpa, &state.vt, at, rows_of[0..vp_rows], out, frame, frame_cols); } +test "a view put back at the row it reports is the view it was, through a reflow: a view on a wrapped line's second row, joined into the row above by a widening and parted again by a narrowing, is the same row put back or not" { + // The bytes soak's divergence (reports/pardes-term-join-6.md): a + // client's rollback puts each terminal's view back at its row + // (core/replica.zig `putViews`), and ghostty's view is a cell, which + // a widening leaves mid-row and the next narrowing carries a row down. + const gpa = std.testing.allocator; + const left = try open(gpa, 20, 2); + defer close(left); + const put = try open(gpa, 20, 2); + defer close(put); + for ([_]*State{ left, put }) |s| { + // Lines two rows long at 20 columns, one at 40. + for (0..30) |_| ingest(s, "abcdefghijklmnopqrstuvwxyz0123\r\n"); + viewTo(s, 1); + resize(s, 40, 2, false); + } + viewTo(put, grid(put).view); + for ([_]*State{ left, put }) |s| resize(s, 20, 2, false); + try std.testing.expectEqual(grid(left), grid(put)); +} + test "the luminance table answers exactly what ghostty computes" { for (0..256) |i| { const c: u8 = @intCast(i); |
