eraseDisplay honors sgr

This commit is contained in:
Mitchell Hashimoto
2022-05-12 21:19:02 -07:00
parent db3f760a1d
commit fc3fac971a
2 changed files with 25 additions and 18 deletions

View File

@ -207,29 +207,36 @@ pub fn eraseDisplay(
) !void {
switch (mode) {
.complete => {
for (self.screen.items) |*line| line.deinit(alloc);
self.screen.clearRetainingCapacity();
var y: usize = 0;
while (y < self.rows) : (y += 1) {
var x: usize = 0;
while (x < self.cols) : (x += 1) {
const cell = try self.getOrPutCell(alloc, x, y);
cell.* = self.cursor.pen;
cell.char = 0;
}
}
},
.below => {
// If our cursor is outside our screen, we can't erase anything.
if (self.cursor.y >= self.screen.items.len) return;
var line = &self.screen.items[self.cursor.y];
// Clear this line right (including the cursor)
if (self.cursor.x < line.items.len) {
for (line.items[self.cursor.x..line.items.len]) |*cell|
// All lines to the right (including the cursor)
var x: usize = self.cursor.x;
while (x < self.cols) : (x += 1) {
const cell = try self.getOrPutCell(alloc, x, self.cursor.y);
cell.* = self.cursor.pen;
cell.char = 0;
}
// Remaining lines are deallocated
if (self.cursor.y + 1 < self.screen.items.len) {
for (self.screen.items[self.cursor.y + 1 .. self.screen.items.len]) |*below|
below.deinit(alloc);
// All lines below
var y: usize = self.cursor.y + 1;
while (y < self.rows) : (y += 1) {
x = 0;
while (x < self.cols) : (x += 1) {
const cell = try self.getOrPutCell(alloc, x, y);
cell.* = self.cursor.pen;
cell.char = 0;
}
}
// Shrink
self.screen.shrinkRetainingCapacity(self.cursor.y + 1);
},
else => {

View File

@ -48,7 +48,7 @@ pub fn Stream(comptime Handler: type) type {
//log.debug("char: {}", .{c});
const actions = self.parser.next(c);
for (actions) |action_opt| {
// if (action_opt) |action| log.info("action: {}", .{action});
if (action_opt) |action| log.info("action: {}", .{action});
switch (action_opt orelse continue) {
.print => |p| if (@hasDecl(T, "print")) try self.handler.print(p),
.execute => |code| try self.execute(code),