mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 00:06:09 +03:00
scroll can be a multiple of row count
This commit is contained in:
@ -100,24 +100,19 @@ pub fn rowIndex(self: Screen, idx: usize) usize {
|
|||||||
return val - self.storage.len;
|
return val - self.storage.len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Scroll the screen up (positive) or down (negiatve). Scrolling direction
|
/// Scroll the screen up (positive) or down (negative). Scrolling direction
|
||||||
/// is the direction text would move. For example, scrolling down would
|
/// is the direction text would move. For example, scrolling down would
|
||||||
/// move existing text downward.
|
/// move existing text downward.
|
||||||
pub fn scroll(self: *Screen, count: isize) void {
|
pub fn scroll(self: *Screen, count: isize) void {
|
||||||
// TODO: this math is super dumb, it doesn't work if count is a
|
|
||||||
// a multiple of rows
|
|
||||||
if (count < 0) {
|
if (count < 0) {
|
||||||
const amount = @intCast(usize, -count);
|
const amount = @mod(@intCast(usize, -count), self.rows);
|
||||||
if (amount > self.zero) {
|
if (amount > self.zero) {
|
||||||
self.zero = self.rows - amount;
|
self.zero = self.rows - amount;
|
||||||
} else {
|
} else {
|
||||||
self.zero -|= amount;
|
self.zero -|= amount;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.zero += @intCast(usize, count);
|
self.zero = @mod(self.zero + @intCast(usize, count), self.rows);
|
||||||
if (self.zero > self.storage.len) {
|
|
||||||
self.zero -= self.storage.len;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,12 +213,29 @@ test "Screen: scrolling" {
|
|||||||
try testing.expectEqual(@as(usize, 10), s.rowIndex(1));
|
try testing.expectEqual(@as(usize, 10), s.rowIndex(1));
|
||||||
try testing.expectEqual(@as(usize, 0), s.rowIndex(2));
|
try testing.expectEqual(@as(usize, 0), s.rowIndex(2));
|
||||||
|
|
||||||
|
{
|
||||||
// Test our contents rotated
|
// Test our contents rotated
|
||||||
var contents = try s.testString(alloc);
|
var contents = try s.testString(alloc);
|
||||||
defer alloc.free(contents);
|
defer alloc.free(contents);
|
||||||
try testing.expectEqualStrings("2EFGH\n3IJKL\n1ABCD", contents);
|
try testing.expectEqualStrings("2EFGH\n3IJKL\n1ABCD", contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Scroll by a multiple
|
||||||
|
s.scroll(@intCast(isize, s.rows) * 4);
|
||||||
|
|
||||||
|
// Test our row index
|
||||||
|
try testing.expectEqual(@as(usize, 5), s.rowIndex(0));
|
||||||
|
try testing.expectEqual(@as(usize, 10), s.rowIndex(1));
|
||||||
|
try testing.expectEqual(@as(usize, 0), s.rowIndex(2));
|
||||||
|
|
||||||
|
{
|
||||||
|
// Test our contents rotated
|
||||||
|
var contents = try s.testString(alloc);
|
||||||
|
defer alloc.free(contents);
|
||||||
|
try testing.expectEqualStrings("2EFGH\n3IJKL\n1ABCD", contents);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
test "Screen: scroll down from 0" {
|
test "Screen: scroll down from 0" {
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
const alloc = testing.allocator;
|
const alloc = testing.allocator;
|
||||||
@ -238,12 +250,29 @@ test "Screen: scroll down from 0" {
|
|||||||
try testing.expectEqual(@as(usize, 0), s.rowIndex(1));
|
try testing.expectEqual(@as(usize, 0), s.rowIndex(1));
|
||||||
try testing.expectEqual(@as(usize, 5), s.rowIndex(2));
|
try testing.expectEqual(@as(usize, 5), s.rowIndex(2));
|
||||||
|
|
||||||
|
{
|
||||||
// Test our contents rotated
|
// Test our contents rotated
|
||||||
var contents = try s.testString(alloc);
|
var contents = try s.testString(alloc);
|
||||||
defer alloc.free(contents);
|
defer alloc.free(contents);
|
||||||
try testing.expectEqualStrings("3IJKL\n1ABCD\n2EFGH", contents);
|
try testing.expectEqualStrings("3IJKL\n1ABCD\n2EFGH", contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Scroll by a multiple
|
||||||
|
s.scroll(-4 * @intCast(isize, s.rows));
|
||||||
|
|
||||||
|
// Test our row index
|
||||||
|
try testing.expectEqual(@as(usize, 10), s.rowIndex(0));
|
||||||
|
try testing.expectEqual(@as(usize, 0), s.rowIndex(1));
|
||||||
|
try testing.expectEqual(@as(usize, 5), s.rowIndex(2));
|
||||||
|
|
||||||
|
{
|
||||||
|
// Test our contents rotated
|
||||||
|
var contents = try s.testString(alloc);
|
||||||
|
defer alloc.free(contents);
|
||||||
|
try testing.expectEqualStrings("3IJKL\n1ABCD\n2EFGH", contents);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
test "Screen: row copy" {
|
test "Screen: row copy" {
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
const alloc = testing.allocator;
|
const alloc = testing.allocator;
|
||||||
|
@ -193,8 +193,6 @@ pub fn print(self: *Terminal, c: u21) !void {
|
|||||||
/// invoke scroll down with amount=1
|
/// invoke scroll down with amount=1
|
||||||
/// * If the cursor is not on the top-most line of the scrolling region:
|
/// * If the cursor is not on the top-most line of the scrolling region:
|
||||||
/// move the cursor one line up
|
/// move the cursor one line up
|
||||||
///
|
|
||||||
// TODO: test
|
|
||||||
pub fn reverseIndex(self: *Terminal) !void {
|
pub fn reverseIndex(self: *Terminal) !void {
|
||||||
// TODO: scrolling region
|
// TODO: scrolling region
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user