From 961e836d6726662c3c68bb88a43b73e4e31bcdd5 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 25 Sep 2023 16:13:07 -0700 Subject: [PATCH 1/6] terminal: DL should reset wrap --- src/terminal/Terminal.zig | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index 73a1f800b..e8f39bf24 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -1601,6 +1601,7 @@ pub fn deleteLines(self: *Terminal, count: usize) !void { // Move the cursor to the left margin self.screen.cursor.x = 0; + self.screen.cursor.pending_wrap = false; // Perform the scroll self.screen.scrollRegionUp( @@ -2367,6 +2368,24 @@ test "Terminal: deleteLines with scroll region, cursor outside of region" { } } +test "Terminal: deleteLines resets wrap" { + const alloc = testing.allocator; + var t = try init(alloc, 5, 5); + defer t.deinit(alloc); + + for ("ABCDE") |c| try t.print(c); + try testing.expect(t.screen.cursor.pending_wrap); + try t.deleteLines(1); + try testing.expect(!t.screen.cursor.pending_wrap); + try t.print('B'); + + { + var str = try t.plainString(testing.allocator); + defer testing.allocator.free(str); + try testing.expectEqualStrings("B", str); + } +} + test "Terminal: insertLines" { const alloc = testing.allocator; var t = try init(alloc, 2, 5); From 27cc8e5529dc1642621e4d21691cbb77b7aafd26 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 25 Sep 2023 16:17:22 -0700 Subject: [PATCH 2/6] terminal: insertLines resets wrap --- src/terminal/Terminal.zig | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index e8f39bf24..68fe3380a 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -1546,6 +1546,7 @@ pub fn insertLines(self: *Terminal, count: usize) !void { // Move the cursor to the left margin self.screen.cursor.x = 0; + self.screen.cursor.pending_wrap = false; // Remaining rows from our cursor const rem = self.scrolling_region.bottom - self.screen.cursor.y + 1; @@ -2495,6 +2496,24 @@ test "Terminal: insertLines more than remaining" { } } +test "Terminal: insertLines resets wrap" { + const alloc = testing.allocator; + var t = try init(alloc, 5, 5); + defer t.deinit(alloc); + + for ("ABCDE") |c| try t.print(c); + try testing.expect(t.screen.cursor.pending_wrap); + try t.insertLines(1); + try testing.expect(!t.screen.cursor.pending_wrap); + try t.print('B'); + + { + var str = try t.plainString(testing.allocator); + defer testing.allocator.free(str); + try testing.expectEqualStrings("B\nABCDE", str); + } +} + test "Terminal: reverseIndex" { const alloc = testing.allocator; var t = try init(alloc, 2, 5); From 804d25278729f0d3277176431ab572ac8f6af98c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 25 Sep 2023 16:21:04 -0700 Subject: [PATCH 3/6] terminal: deleteChars resets pending wrap state --- src/terminal/Terminal.zig | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index 68fe3380a..a2d620840 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -1309,6 +1309,9 @@ pub fn deleteChars(self: *Terminal, count: usize) !void { if (count == 0) return; + // This resets the pending wrap state + self.screen.cursor.pending_wrap = false; + // We go from our cursor right to the end and either copy the cell // "count" away or clear it. const line = self.screen.getRow(.{ .active = self.screen.cursor.y }); @@ -2978,6 +2981,24 @@ test "Terminal: deleteChars should shift left" { } } +test "Terminal: deleteChars resets wrap" { + const alloc = testing.allocator; + var t = try init(alloc, 5, 5); + defer t.deinit(alloc); + + for ("ABCDE") |c| try t.print(c); + try testing.expect(t.screen.cursor.pending_wrap); + try t.deleteChars(1); + try testing.expect(!t.screen.cursor.pending_wrap); + try t.print('X'); + + { + var str = try t.plainString(testing.allocator); + defer testing.allocator.free(str); + try testing.expectEqualStrings("ABCDX", str); + } +} + test "Terminal: setCursorColAbsolute resets pending wrap" { const alloc = testing.allocator; var t = try init(alloc, 5, 5); From 1f3138add704fd7353147b5b239fd345de9fd128 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 25 Sep 2023 16:23:29 -0700 Subject: [PATCH 4/6] terminal: eraseChars resets wrap --- src/terminal/Terminal.zig | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index a2d620840..b9077544b 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -1333,6 +1333,9 @@ pub fn eraseChars(self: *Terminal, count: usize) void { const tracy = trace(@src()); defer tracy.end(); + // This resets the pending wrap state + self.screen.cursor.pending_wrap = false; + // Our last index is at most the end of the number of chars we have // in the current line. const end = @min(self.cols, self.screen.cursor.x + count); @@ -2999,6 +3002,24 @@ test "Terminal: deleteChars resets wrap" { } } +test "Terminal: eraseChars resets wrap" { + const alloc = testing.allocator; + var t = try init(alloc, 5, 5); + defer t.deinit(alloc); + + for ("ABCDE") |c| try t.print(c); + try testing.expect(t.screen.cursor.pending_wrap); + t.eraseChars(1); + try testing.expect(!t.screen.cursor.pending_wrap); + try t.print('X'); + + { + var str = try t.plainString(testing.allocator); + defer testing.allocator.free(str); + try testing.expectEqualStrings("ABCDX", str); + } +} + test "Terminal: setCursorColAbsolute resets pending wrap" { const alloc = testing.allocator; var t = try init(alloc, 5, 5); From 2c260713320a91d79d8539e7d1b43050f66e81c8 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 25 Sep 2023 17:32:51 -0700 Subject: [PATCH 5/6] terminal: eraseLine resets wrap --- src/terminal/Terminal.zig | 43 +++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index b9077544b..8aa22cf5f 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -1250,20 +1250,20 @@ pub fn eraseLine( // a contiguous block of memory. if (!protected) { switch (mode) { - .right => row.fillSlice( - self.screen.cursor.pen, - self.screen.cursor.x, - self.cols, - ), - - .left => { - row.fillSlice(self.screen.cursor.pen, 0, self.screen.cursor.x + 1); - - // Unsets pending wrap state + .right => { + row.fillSlice(self.screen.cursor.pen, self.screen.cursor.x, self.cols); self.screen.cursor.pending_wrap = false; }, - .complete => row.fill(self.screen.cursor.pen), + .left => { + row.fillSlice(self.screen.cursor.pen, 0, self.screen.cursor.x + 1); + self.screen.cursor.pending_wrap = false; + }, + + .complete => { + row.fill(self.screen.cursor.pen); + self.screen.cursor.pending_wrap = false; + }, else => log.err("unimplemented erase line mode: {}", .{mode}), } @@ -1283,6 +1283,9 @@ pub fn eraseLine( }, }; + // All modes will clear the pending wrap state + self.screen.cursor.pending_wrap = false; + const pen: Screen.Cell = if (!self.screen.cursor.pen.attrs.has_bg) .{} else .{ .bg = self.screen.cursor.pen.bg, .attrs = .{ .has_bg = true }, @@ -3111,6 +3114,24 @@ test "Terminal: setProtectedMode" { try testing.expect(!t.screen.cursor.pen.attrs.protected); } +test "Terminal: eraseLine resets wrap" { + const alloc = testing.allocator; + var t = try init(alloc, 5, 5); + defer t.deinit(alloc); + + for ("ABCDE") |c| try t.print(c); + try testing.expect(t.screen.cursor.pending_wrap); + t.eraseLine(.right, false); + try testing.expect(!t.screen.cursor.pending_wrap); + try t.print('B'); + + { + var str = try t.plainString(testing.allocator); + defer testing.allocator.free(str); + try testing.expectEqualStrings("ABCDB", str); + } +} + test "Terminal: eraseLine protected right" { const alloc = testing.allocator; var t = try init(alloc, 10, 5); From 3f48a43ba48ee904eda5d531463473fd5d0ee4c8 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 25 Sep 2023 17:42:37 -0700 Subject: [PATCH 6/6] terminal: cursors must set pending wrap --- src/terminal/Terminal.zig | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index 8aa22cf5f..f45ffc77b 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -1356,9 +1356,9 @@ pub fn cursorLeft(self: *Terminal, count: usize) void { const tracy = trace(@src()); defer tracy.end(); - // TODO: scroll region, wrap - + // TODO: scroll region self.screen.cursor.x -|= if (count == 0) 1 else count; + self.screen.cursor.pending_wrap = false; } /// Move the cursor right amount columns. If amount is greater than the @@ -1385,6 +1385,7 @@ pub fn cursorDown(self: *Terminal, count: usize) void { const tracy = trace(@src()); defer tracy.end(); + self.screen.cursor.pending_wrap = false; self.screen.cursor.y += if (count == 0) 1 else count; if (self.screen.cursor.y >= self.rows) { self.screen.cursor.y = self.rows - 1;