terminal: add kitty image limits to Terminal.Options

Move kitty_image_storage_limit and kitty_image_loading_limits into
Terminal.Options so callers can set them at construction time
rather than calling setter functions after init. The values flow
through to Screen.Options during ScreenSet initialization. Termio
now passes both at construction, keeping the setter functions for
the updateConfig path.
This commit is contained in:
Mitchell Hashimoto
2026-04-05 07:20:07 -07:00
parent 64dcb91c1f
commit 935d37fbf1
2 changed files with 17 additions and 4 deletions

View File

@@ -191,6 +191,19 @@ pub const Options = struct {
/// The default mode state. When the terminal gets a reset, it
/// will revert back to this state.
default_modes: modespkg.ModePacked = .{},
/// The total storage limit for Kitty images in bytes. Has no effect
/// if kitty images are disabled at build-time.
kitty_image_storage_limit: usize = 320 * 1000 * 1000, // 320MB
/// The limits for what medium types are allowed for Kitty image loading.
/// Has no effect if kitty images are disabled otherwise. For example,
// if no `sys.decode_png` hook is specified, png formats are disabled
// no matter what.
kitty_image_loading_limits: if (build_options.kitty_graphics)
kitty.graphics.LoadingImage.Limits
else
void = if (build_options.kitty_graphics) .direct else {},
};
/// Initialize a new terminal.
@@ -205,6 +218,8 @@ pub fn init(
.cols = cols,
.rows = rows,
.max_scrollback = opts.max_scrollback,
.kitty_image_storage_limit = opts.kitty_image_storage_limit,
.kitty_image_loading_limits = opts.kitty_image_loading_limits,
});
errdefer screen_set.deinit(alloc);

View File

@@ -255,14 +255,12 @@ pub fn init(self: *Termio, alloc: Allocator, opts: termio.Options) !void {
},
.palette = .init(opts.config.palette),
},
.kitty_image_storage_limit = opts.config.image_storage_limit,
.kitty_image_loading_limits = .all,
};
});
errdefer term.deinit(alloc);
// Set the Kitty image settings
try term.setKittyGraphicsSizeLimit(alloc, opts.config.image_storage_limit);
term.setKittyGraphicsLoadingLimits(.all);
// Set our default cursor style
term.screens.active.cursor.cursor_style = opts.config.cursor_style;