implement bright fg/bg

This commit is contained in:
Mitchell Hashimoto
2022-05-19 21:32:00 -07:00
parent 29f88968e9
commit 16d4648cf6
2 changed files with 23 additions and 1 deletions

View File

@ -189,6 +189,10 @@ pub fn setAttribute(self: *Terminal, attr: sgr.Attribute) !void {
.@"8_bg" => |n| self.cursor.pen.bg = color.default[@enumToInt(n)], .@"8_bg" => |n| self.cursor.pen.bg = color.default[@enumToInt(n)],
.@"8_bright_fg" => |n| self.cursor.pen.fg = color.default[@enumToInt(n)],
.@"8_bright_bg" => |n| self.cursor.pen.bg = color.default[@enumToInt(n)],
.@"256_fg" => |idx| self.cursor.pen.fg = color.default[idx], .@"256_fg" => |idx| self.cursor.pen.fg = color.default[idx],
.@"256_bg" => |idx| self.cursor.pen.bg = color.default[idx], .@"256_bg" => |idx| self.cursor.pen.bg = color.default[idx],

View File

@ -25,6 +25,10 @@ pub const Attribute = union(enum) {
@"8_bg": color.Name, @"8_bg": color.Name,
@"8_fg": color.Name, @"8_fg": color.Name,
/// Set the background/foreground as a named bright color attribute.
@"8_bright_bg": color.Name,
@"8_bright_fg": color.Name,
/// Set background color as 256-color palette. /// Set background color as 256-color palette.
@"256_bg": u8, @"256_bg": u8,
@ -116,6 +120,14 @@ pub const Parser = struct {
}; };
}, },
90...97 => return Attribute{
.@"8_bright_fg" = @intToEnum(color.Name, slice[0] - 90),
},
100...107 => return Attribute{
.@"8_bright_bg" = @intToEnum(color.Name, slice[0] - 92),
},
else => {}, else => {},
} }
@ -167,7 +179,7 @@ test "sgr: bold" {
} }
test "sgr: 8 color" { test "sgr: 8 color" {
var p: Parser = .{ .params = &[_]u16{ 31, 43 } }; var p: Parser = .{ .params = &[_]u16{ 31, 43, 103 } };
{ {
const v = p.next().?; const v = p.next().?;
@ -180,6 +192,12 @@ test "sgr: 8 color" {
try testing.expect(v == .@"8_bg"); try testing.expect(v == .@"8_bg");
try testing.expect(v.@"8_bg" == .yellow); try testing.expect(v.@"8_bg" == .yellow);
} }
{
const v = p.next().?;
try testing.expect(v == .@"8_bright_bg");
try testing.expect(v.@"8_bright_bg" == .bright_yellow);
}
} }
test "sgr: 256 color" { test "sgr: 256 color" {