mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-04-21 08:58:37 +03:00
shell-integration: comptime buffer capacity
This commit is contained in:
@ -150,17 +150,23 @@ pub fn setupFeatures(
|
|||||||
env: *EnvMap,
|
env: *EnvMap,
|
||||||
features: config.ShellIntegrationFeatures,
|
features: config.ShellIntegrationFeatures,
|
||||||
) !void {
|
) !void {
|
||||||
var enabled = try std.BoundedArray(u8, 256).init(0);
|
const fields = @typeInfo(@TypeOf(features)).@"struct".fields;
|
||||||
|
const capacity: usize = capacity: {
|
||||||
|
comptime var n: usize = fields.len - 1; // commas
|
||||||
|
inline for (fields) |field| n += field.name.len;
|
||||||
|
break :capacity n;
|
||||||
|
};
|
||||||
|
var buffer = try std.BoundedArray(u8, capacity).init(0);
|
||||||
|
|
||||||
inline for (@typeInfo(@TypeOf(features)).@"struct".fields) |f| {
|
inline for (fields) |field| {
|
||||||
if (@field(features, f.name)) {
|
if (@field(features, field.name)) {
|
||||||
if (enabled.len > 0) try enabled.append(',');
|
if (buffer.len > 0) try buffer.append(',');
|
||||||
try enabled.appendSlice(f.name);
|
try buffer.appendSlice(field.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enabled.len > 0) {
|
if (buffer.len > 0) {
|
||||||
try env.put("GHOSTTY_SHELL_FEATURES", enabled.slice());
|
try env.put("GHOSTTY_SHELL_FEATURES", buffer.slice());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user