This commit is contained in:
Mitchell Hashimoto
2022-05-21 20:55:32 -07:00
parent b47f2e6eef
commit 3b7272ef57
2 changed files with 16 additions and 37 deletions

View File

@ -495,18 +495,20 @@ pub fn deleteLines(self: *Terminal, count: usize) void {
self.cursor.x = 0; self.cursor.x = 0;
// Remaining number of lines in the scrolling region // 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. // 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. // Scroll up the count amount.
var i: usize = 0; var y: usize = self.cursor.y;
while (i < count2) : (i += 1) { while (y <= self.scrolling_region.bottom - adjusted_count) : (y += 1) {
self.scrollUpRegion( self.screen.copyRow(y, y + adjusted_count);
self.cursor.y, }
self.scrolling_region.bottom,
); 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; 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. /// Scroll the text down by one row.
/// TODO: test /// TODO: test
pub fn scrollDown(self: *Terminal) !void { pub fn scrollDown(self: *Terminal) !void {

View File

@ -48,11 +48,11 @@ pub fn Stream(comptime Handler: type) type {
//log.debug("char: {x}", .{c}); //log.debug("char: {x}", .{c});
const actions = self.parser.next(c); const actions = self.parser.next(c);
for (actions) |action_opt| { for (actions) |action_opt| {
if (action_opt) |action| { // if (action_opt) |action| {
if (action != .print) { // if (action != .print) {
log.info("action: {}", .{action}); // log.info("action: {}", .{action});
} // }
} // }
switch (action_opt orelse continue) { switch (action_opt orelse continue) {
.print => |p| if (@hasDecl(T, "print")) try self.handler.print(p), .print => |p| if (@hasDecl(T, "print")) try self.handler.print(p),
.execute => |code| try self.execute(code), .execute => |code| try self.execute(code),
@ -328,6 +328,7 @@ pub fn Stream(comptime Handler: type) type {
// TODO: test // TODO: test
'r' => if (@hasDecl(T, "setTopAndBottomMargin")) switch (action.params.len) { 'r' => if (@hasDecl(T, "setTopAndBottomMargin")) switch (action.params.len) {
1 => try self.handler.setTopAndBottomMargin(action.params[0], 0), 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("invalid DECSTBM command: {}", .{action}),
} else log.warn("unimplemented CSI callback: {}", .{action}), } else log.warn("unimplemented CSI callback: {}", .{action}),