diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index 4dd352186..6b50fd001 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -495,18 +495,20 @@ pub fn deleteLines(self: *Terminal, count: usize) void { self.cursor.x = 0; // Remaining number of lines in the scrolling region - const rem = self.scrolling_region.bottom - self.cursor.y; + const rem = self.scrolling_region.bottom - self.cursor.y + 1; // If the count is more than our remaining lines, we adjust down. - const count2 = @minimum(count, rem); + const adjusted_count = @minimum(count, rem); // Scroll up the count amount. - var i: usize = 0; - while (i < count2) : (i += 1) { - self.scrollUpRegion( - self.cursor.y, - self.scrolling_region.bottom, - ); + var y: usize = self.cursor.y; + while (y <= self.scrolling_region.bottom - adjusted_count) : (y += 1) { + self.screen.copyRow(y, y + adjusted_count); + } + + while (y <= self.scrolling_region.bottom) : (y += 1) { + const row = self.screen.getRow(y); + std.mem.set(Screen.Cell, row, self.cursor.pen); } } @@ -520,30 +522,6 @@ pub fn scrollUp(self: *Terminal) void { for (last) |*cell| cell.char = 0; } -/// Scroll the given region up. -/// -/// Top and bottom are 0-indexed. -fn scrollUpRegion( - self: *Terminal, - top: usize, - bottom: usize, -) void { - const tracy = trace(@src()); - defer tracy.end(); - - // Only go to the end of the region OR the end of our lines. - const end = @minimum(bottom, self.screen.rows - 1); - - var i: usize = top; - while (i < end) : (i += 1) { - self.screen.copyRow(i, i + 1); - } - - // Blank our last line if we have space. - const row = self.screen.getRow(i); - for (row) |*cell| cell.char = 0; -} - /// Scroll the text down by one row. /// TODO: test pub fn scrollDown(self: *Terminal) !void { diff --git a/src/terminal/stream.zig b/src/terminal/stream.zig index 581706f9f..ba262a52f 100644 --- a/src/terminal/stream.zig +++ b/src/terminal/stream.zig @@ -48,11 +48,11 @@ pub fn Stream(comptime Handler: type) type { //log.debug("char: {x}", .{c}); const actions = self.parser.next(c); for (actions) |action_opt| { - if (action_opt) |action| { - if (action != .print) { - log.info("action: {}", .{action}); - } - } + // if (action_opt) |action| { + // if (action != .print) { + // 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), @@ -328,6 +328,7 @@ pub fn Stream(comptime Handler: type) type { // TODO: test 'r' => if (@hasDecl(T, "setTopAndBottomMargin")) switch (action.params.len) { 1 => try self.handler.setTopAndBottomMargin(action.params[0], 0), + 2 => try self.handler.setTopAndBottomMargin(action.params[0], action.params[1]), else => log.warn("invalid DECSTBM command: {}", .{action}), } else log.warn("unimplemented CSI callback: {}", .{action}),