core: configurable scrollback limit

This commit is contained in:
Mitchell Hashimoto
2024-03-11 21:02:28 -07:00
parent 03abde6ba8
commit 49e8acbcd2
6 changed files with 317 additions and 289 deletions

View File

@ -25,5 +25,3 @@ paged-terminal branch:
- tests and logic for overflowing page capacities:
* graphemes
* styles
- configurable scrollback size

View File

@ -427,6 +427,27 @@ command: ?[]const u8 = null,
/// command.
@"abnormal-command-exit-runtime": u32 = 250,
/// The size of the scrollback buffer in bytes. This also includes the active
/// screen. No matter what this is set to, enough memory will always be
/// allocated for the visible screen and anything leftover is the limit for
/// the scrollback.
///
/// When this limit is reached, the oldest lines are removed from the
/// scrollback.
///
/// Scrollback currently exists completely in memory. This means that the
/// larger this value, the larger potential memory usage. Scrollback is
/// allocated lazily up to this limit, so if you set this to a very large
/// value, it will not immediately consume a lot of memory.
///
/// This size is per terminal surface, not for the entire application.
///
/// It is not currently possible to set an unlimited scrollback buffer.
/// This is a future planned feature.
///
/// This can be changed at runtime but will only affect new terminal surfaces.
@"scrollback-limit": u32 = 10_000,
/// Match a regular expression against the terminal text and associate clicking
/// it with an action. This can be used to match URLs, file paths, etc. Actions
/// can be opening using the system opener (i.e. `open` or `xdg-open`) or

View File

@ -63,7 +63,7 @@ pub fn cursorStyle(
test "cursor: default uses configured style" {
const testing = std.testing;
const alloc = testing.allocator;
var term = try terminal.Terminal.init(alloc, 10, 10);
var term = try terminal.Terminal.init(alloc, .{ .cols = 10, .rows = 10 });
defer term.deinit(alloc);
term.screen.cursor.cursor_style = .bar;
@ -84,7 +84,7 @@ test "cursor: default uses configured style" {
test "cursor: blinking disabled" {
const testing = std.testing;
const alloc = testing.allocator;
var term = try terminal.Terminal.init(alloc, 10, 10);
var term = try terminal.Terminal.init(alloc, .{ .cols = 10, .rows = 10 });
defer term.deinit(alloc);
term.screen.cursor.cursor_style = .bar;
@ -105,7 +105,7 @@ test "cursor: blinking disabled" {
test "cursor: explictly not visible" {
const testing = std.testing;
const alloc = testing.allocator;
var term = try terminal.Terminal.init(alloc, 10, 10);
var term = try terminal.Terminal.init(alloc, .{ .cols = 10, .rows = 10 });
defer term.deinit(alloc);
term.screen.cursor.cursor_style = .bar;
@ -127,7 +127,7 @@ test "cursor: explictly not visible" {
test "cursor: always block with preedit" {
const testing = std.testing;
const alloc = testing.allocator;
var term = try terminal.Terminal.init(alloc, 10, 10);
var term = try terminal.Terminal.init(alloc, .{ .cols = 10, .rows = 10 });
defer term.deinit(alloc);
var state: State = .{

File diff suppressed because it is too large Load Diff

View File

@ -645,7 +645,7 @@ fn trackPin(
test "storage: add placement with zero placement id" {
const testing = std.testing;
const alloc = testing.allocator;
var t = try terminal.Terminal.init(alloc, 100, 100);
var t = try terminal.Terminal.init(alloc, .{ .cols = 100, .rows = 100 });
defer t.deinit(alloc);
t.width_px = 100;
t.height_px = 100;
@ -674,7 +674,7 @@ test "storage: add placement with zero placement id" {
test "storage: delete all placements and images" {
const testing = std.testing;
const alloc = testing.allocator;
var t = try terminal.Terminal.init(alloc, 3, 3);
var t = try terminal.Terminal.init(alloc, .{ .rows = 3, .cols = 3 });
defer t.deinit(alloc);
const tracked = t.screen.pages.countTrackedPins();
@ -697,7 +697,7 @@ test "storage: delete all placements and images" {
test "storage: delete all placements and images preserves limit" {
const testing = std.testing;
const alloc = testing.allocator;
var t = try terminal.Terminal.init(alloc, 3, 3);
var t = try terminal.Terminal.init(alloc, .{ .rows = 3, .cols = 3 });
defer t.deinit(alloc);
const tracked = t.screen.pages.countTrackedPins();
@ -722,7 +722,7 @@ test "storage: delete all placements and images preserves limit" {
test "storage: delete all placements" {
const testing = std.testing;
const alloc = testing.allocator;
var t = try terminal.Terminal.init(alloc, 3, 3);
var t = try terminal.Terminal.init(alloc, .{ .rows = 3, .cols = 3 });
defer t.deinit(alloc);
const tracked = t.screen.pages.countTrackedPins();
@ -745,7 +745,7 @@ test "storage: delete all placements" {
test "storage: delete all placements by image id" {
const testing = std.testing;
const alloc = testing.allocator;
var t = try terminal.Terminal.init(alloc, 3, 3);
var t = try terminal.Terminal.init(alloc, .{ .rows = 3, .cols = 3 });
defer t.deinit(alloc);
const tracked = t.screen.pages.countTrackedPins();
@ -768,7 +768,7 @@ test "storage: delete all placements by image id" {
test "storage: delete all placements by image id and unused images" {
const testing = std.testing;
const alloc = testing.allocator;
var t = try terminal.Terminal.init(alloc, 3, 3);
var t = try terminal.Terminal.init(alloc, .{ .rows = 3, .cols = 3 });
defer t.deinit(alloc);
const tracked = t.screen.pages.countTrackedPins();
@ -791,7 +791,7 @@ test "storage: delete all placements by image id and unused images" {
test "storage: delete placement by specific id" {
const testing = std.testing;
const alloc = testing.allocator;
var t = try terminal.Terminal.init(alloc, 3, 3);
var t = try terminal.Terminal.init(alloc, .{ .rows = 3, .cols = 3 });
defer t.deinit(alloc);
const tracked = t.screen.pages.countTrackedPins();
@ -819,7 +819,7 @@ test "storage: delete placement by specific id" {
test "storage: delete intersecting cursor" {
const testing = std.testing;
const alloc = testing.allocator;
var t = try terminal.Terminal.init(alloc, 100, 100);
var t = try terminal.Terminal.init(alloc, .{ .rows = 100, .cols = 100 });
defer t.deinit(alloc);
t.width_px = 100;
t.height_px = 100;
@ -851,7 +851,7 @@ test "storage: delete intersecting cursor" {
test "storage: delete intersecting cursor plus unused" {
const testing = std.testing;
const alloc = testing.allocator;
var t = try terminal.Terminal.init(alloc, 100, 100);
var t = try terminal.Terminal.init(alloc, .{ .rows = 100, .cols = 100 });
defer t.deinit(alloc);
t.width_px = 100;
t.height_px = 100;
@ -883,7 +883,7 @@ test "storage: delete intersecting cursor plus unused" {
test "storage: delete intersecting cursor hits multiple" {
const testing = std.testing;
const alloc = testing.allocator;
var t = try terminal.Terminal.init(alloc, 100, 100);
var t = try terminal.Terminal.init(alloc, .{ .rows = 100, .cols = 100 });
defer t.deinit(alloc);
t.width_px = 100;
t.height_px = 100;
@ -909,7 +909,7 @@ test "storage: delete intersecting cursor hits multiple" {
test "storage: delete by column" {
const testing = std.testing;
const alloc = testing.allocator;
var t = try terminal.Terminal.init(alloc, 100, 100);
var t = try terminal.Terminal.init(alloc, .{ .rows = 100, .cols = 100 });
defer t.deinit(alloc);
t.width_px = 100;
t.height_px = 100;
@ -942,7 +942,7 @@ test "storage: delete by column" {
test "storage: delete by row" {
const testing = std.testing;
const alloc = testing.allocator;
var t = try terminal.Terminal.init(alloc, 100, 100);
var t = try terminal.Terminal.init(alloc, .{ .rows = 100, .cols = 100 });
defer t.deinit(alloc);
t.width_px = 100;
t.height_px = 100;

View File

@ -128,11 +128,11 @@ pub const DerivedConfig = struct {
/// process.
pub fn init(alloc: Allocator, opts: termio.Options) !Exec {
// Create our terminal
var term = try terminal.Terminal.init(
alloc,
opts.grid_size.columns,
opts.grid_size.rows,
);
var term = try terminal.Terminal.init(alloc, .{
.cols = opts.grid_size.columns,
.rows = opts.grid_size.rows,
.max_scrollback = opts.full_config.@"scrollback-limit",
});
errdefer term.deinit(alloc);
term.default_palette = opts.config.palette;
term.color_palette.colors = opts.config.palette;