terminal: scroll up full top/bottom region was off by one

Fixes #689

See test cases, verified with xterm.
This commit is contained in:
Mitchell Hashimoto
2023-10-16 09:23:30 -07:00
parent 1c0fd2442b
commit 12054087e1
3 changed files with 57 additions and 1 deletions

View File

@ -1765,7 +1765,7 @@ pub fn deleteLines(self: *Terminal, count: usize) !void {
self.screen.scrollRegionUp( self.screen.scrollRegionUp(
.{ .active = self.screen.cursor.y }, .{ .active = self.screen.cursor.y },
.{ .active = self.scrolling_region.bottom }, .{ .active = self.scrolling_region.bottom },
@min(count, self.scrolling_region.bottom - self.screen.cursor.y), @min(count, (self.scrolling_region.bottom - self.screen.cursor.y) + 1),
); );
return; return;
} }
@ -6364,6 +6364,44 @@ test "Terminal: scrollUp preserves pending wrap" {
} }
} }
test "Terminal: scrollUp full top/bottom region" {
const alloc = testing.allocator;
var t = try init(alloc, 5, 5);
defer t.deinit(alloc);
try t.printString("top");
t.setCursorPos(5, 1);
try t.printString("ABCDE");
t.setTopAndBottomMargin(2, 5);
try t.scrollUp(4);
{
var str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings("top", str);
}
}
test "Terminal: scrollUp full top/bottomleft/right scroll region" {
const alloc = testing.allocator;
var t = try init(alloc, 5, 5);
defer t.deinit(alloc);
try t.printString("top");
t.setCursorPos(5, 1);
try t.printString("ABCDE");
t.modes.set(.enable_left_and_right_margin, true);
t.setTopAndBottomMargin(2, 5);
t.setLeftAndRightMargin(2, 4);
try t.scrollUp(4);
{
var str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings("top\n\n\n\nA E", str);
}
}
test "Terminal: tabClear single" { test "Terminal: tabClear single" {
const alloc = testing.allocator; const alloc = testing.allocator;
var t = try init(alloc, 30, 5); var t = try init(alloc, 30, 5);

View File

@ -469,6 +469,8 @@ pub inline fn queueWrite(self: *Exec, data: []const u8, linefeed: bool) !void {
break :slice buf[0..buf_i]; break :slice buf[0..buf_i];
}; };
// for (slice) |b| log.warn("write: {x}", .{b});
ev.data_stream.queueWrite( ev.data_stream.queueWrite(
ev.loop, ev.loop,
&ev.write_queue, &ev.write_queue,

View File

@ -95,3 +95,19 @@ printf "X"
|________| |________|
|X_______| |X_______|
``` ```
### SU V-5: Scroll Full Top/Bottom Scroll Region
```bash
printf "\033[1;1H" # move to top-left
printf "\033[0J" # clear screen
printf "top"
printf "\033[5;1H"
printf "ABCDEF"
printf "\033[2;5r" # scroll region top/bottom
printf "\033[4S"
```
```
|top_____|
```