mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
terminal: change mask from u256 to StaticBitSet
This commit is contained in:
@ -241,7 +241,8 @@ pub const VTEvent = struct {
|
||||
try alloc.dupeZ(u8, @tagName(value)),
|
||||
),
|
||||
|
||||
.Union => |u| if (u.tag_type) |Tag| {
|
||||
.Union => |u| {
|
||||
const Tag = u.tag_type orelse @compileError("Unions must have a tag");
|
||||
const tag_name = @tagName(@as(Tag, value));
|
||||
inline for (u.fields) |field| {
|
||||
if (std.mem.eql(u8, field.name, tag_name)) {
|
||||
@ -256,8 +257,6 @@ pub const VTEvent = struct {
|
||||
try md.put(key, s);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@compileError("Unions must have a tag");
|
||||
},
|
||||
|
||||
else => switch (Value) {
|
||||
|
@ -82,8 +82,9 @@ default_palette: color.Palette = color.default,
|
||||
/// The color palette to use. The mask indicates which palette indices have been
|
||||
/// modified with OSC 4
|
||||
color_palette: struct {
|
||||
const Mask = std.StaticBitSet(@typeInfo(color.Palette).Array.len);
|
||||
colors: color.Palette = color.default,
|
||||
mask: u256 = 0,
|
||||
mask: Mask = Mask.initEmpty(),
|
||||
} = .{},
|
||||
|
||||
/// The previous printed character. This is used for the repeat previous
|
||||
|
@ -2257,7 +2257,7 @@ const StreamHandler = struct {
|
||||
switch (kind) {
|
||||
.palette => |i| {
|
||||
self.terminal.color_palette.colors[i] = color;
|
||||
self.terminal.color_palette.mask |= @as(u256, 1) << i;
|
||||
self.terminal.color_palette.mask.set(i);
|
||||
},
|
||||
.foreground => {
|
||||
self.foreground_color = color;
|
||||
@ -2287,19 +2287,15 @@ const StreamHandler = struct {
|
||||
) !void {
|
||||
switch (kind) {
|
||||
.palette => {
|
||||
var mask = self.terminal.color_palette.mask;
|
||||
defer self.terminal.color_palette.mask = mask;
|
||||
|
||||
const mask = &self.terminal.color_palette.mask;
|
||||
if (value.len == 0) {
|
||||
// Find all bit positions in the mask which are set and
|
||||
// reset those indices to the default palette
|
||||
while (mask != 0) {
|
||||
// Safe to truncate, mask is non-zero so @ctz can never
|
||||
// return a u9
|
||||
const i: u8 = @truncate(@ctz(mask));
|
||||
var it = mask.iterator(.{});
|
||||
while (it.next()) |i| {
|
||||
log.warn("Resetting palette color {}", .{i});
|
||||
self.terminal.color_palette.colors[i] = self.terminal.default_palette[i];
|
||||
mask ^= @as(u256, 1) << i;
|
||||
mask.unset(i);
|
||||
}
|
||||
} else {
|
||||
var it = std.mem.tokenizeScalar(u8, value, ';');
|
||||
@ -2307,9 +2303,9 @@ const StreamHandler = struct {
|
||||
// Skip invalid parameters
|
||||
const i = std.fmt.parseUnsigned(u8, param, 10) catch continue;
|
||||
log.warn("Resetting palette color {}", .{i});
|
||||
if (mask & (@as(u256, 1) << i) != 0) {
|
||||
if (mask.isSet(i)) {
|
||||
self.terminal.color_palette.colors[i] = self.terminal.default_palette[i];
|
||||
mask ^= @as(u256, 1) << i;
|
||||
mask.unset(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user