terminal: ECH minimum count is 1

This commit is contained in:
Mitchell Hashimoto
2023-10-27 08:50:05 -07:00
parent 3a77df7ce2
commit 597f95120b

View File

@ -1346,10 +1346,12 @@ pub fn deleteChars(self: *Terminal, count: usize) !void {
} }
} }
pub fn eraseChars(self: *Terminal, count: usize) void { pub fn eraseChars(self: *Terminal, count_req: usize) void {
const tracy = trace(@src()); const tracy = trace(@src());
defer tracy.end(); defer tracy.end();
const count = @max(count_req, 1);
// This resets the pending wrap state // This resets the pending wrap state
self.screen.cursor.pending_wrap = false; self.screen.cursor.pending_wrap = false;
@ -4787,6 +4789,23 @@ test "Terminal: eraseChars simple operation" {
} }
} }
test "Terminal: eraseChars minimum one" {
const alloc = testing.allocator;
var t = try init(alloc, 5, 5);
defer t.deinit(alloc);
for ("ABC") |c| try t.print(c);
t.setCursorPos(1, 1);
t.eraseChars(0);
try t.print('X');
{
var str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings("XBC", str);
}
}
test "Terminal: eraseChars beyond screen edge" { test "Terminal: eraseChars beyond screen edge" {
const alloc = testing.allocator; const alloc = testing.allocator;
var t = try init(alloc, 5, 5); var t = try init(alloc, 5, 5);