Merge pull request #1019 from mitchellh/underline-palette

terminal: support `58;5` for setting underline color via 256 palette
This commit is contained in:
Mitchell Hashimoto
2023-12-07 15:04:26 -08:00
committed by GitHub
3 changed files with 19 additions and 0 deletions

View File

@ -515,6 +515,11 @@ pub fn setAttribute(self: *Terminal, attr: sgr.Attribute) !void {
};
},
.@"256_underline_color" => |idx| {
self.screen.cursor.pen.attrs.underline_color = true;
self.screen.cursor.pen.underline_fg = self.color_palette.colors[idx];
},
.reset_underline_color => {
self.screen.cursor.pen.attrs.underline_color = false;
},

View File

@ -34,6 +34,7 @@ pub const Attribute = union(enum) {
underline: Underline,
reset_underline: void,
underline_color: color.RGB,
@"256_underline_color": u8,
reset_underline_color: void,
/// Blink the text
@ -253,6 +254,11 @@ pub const Parser = struct {
.b = @truncate(rgb[2]),
},
};
} else if (slice.len >= 3 and slice[1] == 5) {
self.idx += 2;
return Attribute{
.@"256_underline_color" = @truncate(slice[2]),
};
},
59 => return Attribute{ .reset_underline_color = {} },
@ -462,6 +468,13 @@ 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");
try testing.expect(p.next() == null);
}
test "sgr: 256 color underline" {
var p: Parser = .{ .params = &[_]u16{ 58, 5, 9 } };
try testing.expect(p.next().? == .@"256_underline_color");
try testing.expect(p.next() == null);
}
test "sgr: 24-bit bg color" {

View File

@ -577,6 +577,7 @@ pub fn Stream(comptime Handler: type) type {
// SGR - Select Graphic Rendition
'm' => switch (action.intermediates.len) {
0 => if (@hasDecl(T, "setAttribute")) {
// log.info("parse SGR params={any}", .{action.params});
var p: sgr.Parser = .{ .params = action.params, .colon = action.sep == .colon };
while (p.next()) |attr| {
// log.info("SGR attribute: {}", .{attr});