Merge pull request #539 from mitchellh/wrap-audit

Reset pending wrap state audit
This commit is contained in:
Mitchell Hashimoto
2023-09-25 17:52:37 -07:00
committed by GitHub

View File

@ -1250,20 +1250,20 @@ pub fn eraseLine(
// a contiguous block of memory. // a contiguous block of memory.
if (!protected) { if (!protected) {
switch (mode) { switch (mode) {
.right => row.fillSlice( .right => {
self.screen.cursor.pen, row.fillSlice(self.screen.cursor.pen, self.screen.cursor.x, self.cols);
self.screen.cursor.x,
self.cols,
),
.left => {
row.fillSlice(self.screen.cursor.pen, 0, self.screen.cursor.x + 1);
// Unsets pending wrap state
self.screen.cursor.pending_wrap = false; 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}), 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 .{ const pen: Screen.Cell = if (!self.screen.cursor.pen.attrs.has_bg) .{} else .{
.bg = self.screen.cursor.pen.bg, .bg = self.screen.cursor.pen.bg,
.attrs = .{ .has_bg = true }, .attrs = .{ .has_bg = true },
@ -1309,6 +1312,9 @@ pub fn deleteChars(self: *Terminal, count: usize) !void {
if (count == 0) return; 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 // We go from our cursor right to the end and either copy the cell
// "count" away or clear it. // "count" away or clear it.
const line = self.screen.getRow(.{ .active = self.screen.cursor.y }); const line = self.screen.getRow(.{ .active = self.screen.cursor.y });
@ -1330,6 +1336,9 @@ pub fn eraseChars(self: *Terminal, count: usize) void {
const tracy = trace(@src()); const tracy = trace(@src());
defer tracy.end(); 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 // Our last index is at most the end of the number of chars we have
// in the current line. // in the current line.
const end = @min(self.cols, self.screen.cursor.x + count); const end = @min(self.cols, self.screen.cursor.x + count);
@ -1347,9 +1356,9 @@ pub fn cursorLeft(self: *Terminal, count: usize) void {
const tracy = trace(@src()); const tracy = trace(@src());
defer tracy.end(); defer tracy.end();
// TODO: scroll region, wrap // TODO: scroll region
self.screen.cursor.x -|= if (count == 0) 1 else count; 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 /// Move the cursor right amount columns. If amount is greater than the
@ -1376,6 +1385,7 @@ pub fn cursorDown(self: *Terminal, count: usize) void {
const tracy = trace(@src()); const tracy = trace(@src());
defer tracy.end(); defer tracy.end();
self.screen.cursor.pending_wrap = false;
self.screen.cursor.y += if (count == 0) 1 else count; self.screen.cursor.y += if (count == 0) 1 else count;
if (self.screen.cursor.y >= self.rows) { if (self.screen.cursor.y >= self.rows) {
self.screen.cursor.y = self.rows - 1; self.screen.cursor.y = self.rows - 1;
@ -1546,6 +1556,7 @@ pub fn insertLines(self: *Terminal, count: usize) !void {
// Move the cursor to the left margin // Move the cursor to the left margin
self.screen.cursor.x = 0; self.screen.cursor.x = 0;
self.screen.cursor.pending_wrap = false;
// Remaining rows from our cursor // Remaining rows from our cursor
const rem = self.scrolling_region.bottom - self.screen.cursor.y + 1; const rem = self.scrolling_region.bottom - self.screen.cursor.y + 1;
@ -1601,6 +1612,7 @@ pub fn deleteLines(self: *Terminal, count: usize) !void {
// Move the cursor to the left margin // Move the cursor to the left margin
self.screen.cursor.x = 0; self.screen.cursor.x = 0;
self.screen.cursor.pending_wrap = false;
// Perform the scroll // Perform the scroll
self.screen.scrollRegionUp( self.screen.scrollRegionUp(
@ -2367,6 +2379,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" { test "Terminal: insertLines" {
const alloc = testing.allocator; const alloc = testing.allocator;
var t = try init(alloc, 2, 5); var t = try init(alloc, 2, 5);
@ -2476,6 +2506,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" { test "Terminal: reverseIndex" {
const alloc = testing.allocator; const alloc = testing.allocator;
var t = try init(alloc, 2, 5); var t = try init(alloc, 2, 5);
@ -2940,6 +2988,42 @@ 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: 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" { test "Terminal: setCursorColAbsolute resets pending wrap" {
const alloc = testing.allocator; const alloc = testing.allocator;
var t = try init(alloc, 5, 5); var t = try init(alloc, 5, 5);
@ -3031,6 +3115,24 @@ test "Terminal: setProtectedMode" {
try testing.expect(!t.screen.cursor.pen.attrs.protected); 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" { test "Terminal: eraseLine protected right" {
const alloc = testing.allocator; const alloc = testing.allocator;
var t = try init(alloc, 10, 5); var t = try init(alloc, 10, 5);