mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
sgr parse bold and 256 fg/bg
This commit is contained in:
@ -11,12 +11,21 @@ pub const Attribute = union(enum) {
|
||||
/// Unknown attribute, the raw CSI command parameters are here.
|
||||
unknown: []const u16,
|
||||
|
||||
/// Bold the text.
|
||||
bold: void,
|
||||
|
||||
/// Set foreground color as RGB values.
|
||||
direct_color_fg: RGB,
|
||||
|
||||
/// Set background color as RGB values.
|
||||
direct_color_bg: RGB,
|
||||
|
||||
/// Set background color as 256-color palette.
|
||||
@"256_bg": u8,
|
||||
|
||||
/// Set foreground color as 256-color palette.
|
||||
@"256_fg": u8,
|
||||
|
||||
pub const RGB = struct {
|
||||
r: u8,
|
||||
g: u8,
|
||||
@ -48,6 +57,8 @@ pub const Parser = struct {
|
||||
switch (slice[0]) {
|
||||
0 => return Attribute{ .unset = {} },
|
||||
|
||||
1 => return Attribute{ .bold = {} },
|
||||
|
||||
38 => if (slice.len >= 5 and slice[1] == 2) {
|
||||
self.idx += 4;
|
||||
|
||||
@ -63,6 +74,11 @@ pub const Parser = struct {
|
||||
.b = @truncate(u8, rgb[2]),
|
||||
},
|
||||
};
|
||||
} else if (slice.len >= 2 and slice[1] == 5) {
|
||||
self.idx += 2;
|
||||
return Attribute{
|
||||
.@"256_fg" = @truncate(u8, slice[2]),
|
||||
};
|
||||
},
|
||||
|
||||
48 => if (slice.len >= 5 and slice[1] == 2) {
|
||||
@ -80,6 +96,11 @@ pub const Parser = struct {
|
||||
.b = @truncate(u8, rgb[2]),
|
||||
},
|
||||
};
|
||||
} else if (slice.len >= 2 and slice[1] == 5) {
|
||||
self.idx += 2;
|
||||
return Attribute{
|
||||
.@"256_bg" = @truncate(u8, slice[2]),
|
||||
};
|
||||
},
|
||||
|
||||
else => {},
|
||||
@ -126,3 +147,14 @@ test "sgr: Parser multiple" {
|
||||
try testing.expect(p.next() == null);
|
||||
try testing.expect(p.next() == null);
|
||||
}
|
||||
|
||||
test "sgr: bold" {
|
||||
const v = testParse(&[_]u16{1});
|
||||
try testing.expect(v == .bold);
|
||||
}
|
||||
|
||||
test "sgr: 256 color" {
|
||||
var p: Parser = .{ .params = &[_]u16{ 38, 5, 161, 48, 5, 236 } };
|
||||
try testing.expect(p.next().? == .@"256_fg");
|
||||
try testing.expect(p.next().? == .@"256_bg");
|
||||
}
|
||||
|
Reference in New Issue
Block a user