mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 16:26:08 +03:00
clearHistory
This commit is contained in:
@ -541,6 +541,19 @@ fn maxCapacity(self: Screen) usize {
|
|||||||
return (self.rows + self.max_scrollback) * (self.cols + 1);
|
return (self.rows + self.max_scrollback) * (self.cols + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Clear all the history. This moves the viewport back to the "top", too.
|
||||||
|
pub fn clearHistory(self: *Screen) void {
|
||||||
|
// If there is no history, do nothing.
|
||||||
|
if (self.history == 0) return;
|
||||||
|
|
||||||
|
// Delete all our history
|
||||||
|
self.storage.deleteOldest(self.history * (self.cols + 1));
|
||||||
|
self.history = 0;
|
||||||
|
|
||||||
|
// Back to the top
|
||||||
|
self.viewport = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/// Scroll behaviors for the scroll function.
|
/// Scroll behaviors for the scroll function.
|
||||||
pub const Scroll = union(enum) {
|
pub const Scroll = union(enum) {
|
||||||
/// Scroll to the top of the scroll buffer. The first line of the
|
/// Scroll to the top of the scroll buffer. The first line of the
|
||||||
@ -1601,6 +1614,64 @@ test "Screen: row copy" {
|
|||||||
try testing.expectEqualStrings("2EFGH\n3IJKL\n2EFGH", contents);
|
try testing.expectEqualStrings("2EFGH\n3IJKL\n2EFGH", contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "Screen: clear history with no history" {
|
||||||
|
const testing = std.testing;
|
||||||
|
const alloc = testing.allocator;
|
||||||
|
|
||||||
|
var s = try init(alloc, 3, 5, 3);
|
||||||
|
defer s.deinit();
|
||||||
|
try s.testWriteString("4ABCD\n5EFGH\n6IJKL");
|
||||||
|
try testing.expect(s.viewportIsBottom());
|
||||||
|
s.clearHistory();
|
||||||
|
try testing.expect(s.viewportIsBottom());
|
||||||
|
{
|
||||||
|
// Test our contents rotated
|
||||||
|
var contents = try s.testString(alloc, .viewport);
|
||||||
|
defer alloc.free(contents);
|
||||||
|
try testing.expectEqualStrings("4ABCD\n5EFGH\n6IJKL", contents);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// Test our contents rotated
|
||||||
|
var contents = try s.testString(alloc, .screen);
|
||||||
|
defer alloc.free(contents);
|
||||||
|
try testing.expectEqualStrings("4ABCD\n5EFGH\n6IJKL", contents);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test "Screen: clear history" {
|
||||||
|
const testing = std.testing;
|
||||||
|
const alloc = testing.allocator;
|
||||||
|
|
||||||
|
var s = try init(alloc, 3, 5, 3);
|
||||||
|
defer s.deinit();
|
||||||
|
try s.testWriteString("1ABCD\n2EFGH\n3IJKL\n4ABCD\n5EFGH\n6IJKL");
|
||||||
|
try testing.expect(s.viewportIsBottom());
|
||||||
|
|
||||||
|
// Scroll to top
|
||||||
|
try s.scroll(.{ .top = {} });
|
||||||
|
{
|
||||||
|
// Test our contents rotated
|
||||||
|
var contents = try s.testString(alloc, .viewport);
|
||||||
|
defer alloc.free(contents);
|
||||||
|
try testing.expectEqualStrings("1ABCD\n2EFGH\n3IJKL", contents);
|
||||||
|
}
|
||||||
|
|
||||||
|
s.clearHistory();
|
||||||
|
try testing.expect(s.viewportIsBottom());
|
||||||
|
{
|
||||||
|
// Test our contents rotated
|
||||||
|
var contents = try s.testString(alloc, .viewport);
|
||||||
|
defer alloc.free(contents);
|
||||||
|
try testing.expectEqualStrings("4ABCD\n5EFGH\n6IJKL", contents);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// Test our contents rotated
|
||||||
|
var contents = try s.testString(alloc, .screen);
|
||||||
|
defer alloc.free(contents);
|
||||||
|
try testing.expectEqualStrings("4ABCD\n5EFGH\n6IJKL", contents);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
test "Screen: selectionString" {
|
test "Screen: selectionString" {
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
const alloc = testing.allocator;
|
const alloc = testing.allocator;
|
||||||
|
@ -806,11 +806,7 @@ pub fn eraseDisplay(
|
|||||||
self.screen.cursor.pending_wrap = false;
|
self.screen.cursor.pending_wrap = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
.scrollback => {
|
.scrollback => self.screen.clearHistory(),
|
||||||
var it = self.screen.rowIterator(.history);
|
|
||||||
while (it.next()) |row| row.clear(self.screen.cursor.pen);
|
|
||||||
@panic("MOVE TO SCREEN SO CIRC BUF IS CORRECT");
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user