implement faint colors (SGR 2)

This commit is contained in:
Mitchell Hashimoto
2022-08-26 11:13:34 -07:00
parent 65df657b4e
commit dc6fc5c1c3
3 changed files with 15 additions and 3 deletions

View File

@ -520,6 +520,9 @@ pub fn updateCell(
}; };
if (self.cells.items.len + needed > self.cells.capacity) return false; if (self.cells.items.len + needed > self.cells.capacity) return false;
// Alpha multiplier
const alpha: u8 = if (cell.attrs.faint) 175 else 255;
// If the cell has a background, we always draw it. // If the cell has a background, we always draw it.
if (colors.bg) |rgb| { if (colors.bg) |rgb| {
var mode: GPUCellMode = .bg; var mode: GPUCellMode = .bg;
@ -542,7 +545,7 @@ pub fn updateCell(
.bg_r = rgb.r, .bg_r = rgb.r,
.bg_g = rgb.g, .bg_g = rgb.g,
.bg_b = rgb.b, .bg_b = rgb.b,
.bg_a = 0xFF, .bg_a = alpha,
}); });
} }
@ -577,7 +580,7 @@ pub fn updateCell(
.fg_r = colors.fg.r, .fg_r = colors.fg.r,
.fg_g = colors.fg.g, .fg_g = colors.fg.g,
.fg_b = colors.fg.b, .fg_b = colors.fg.b,
.fg_a = 255, .fg_a = alpha,
.bg_r = 0, .bg_r = 0,
.bg_g = 0, .bg_g = 0,
.bg_b = 0, .bg_b = 0,
@ -602,7 +605,7 @@ pub fn updateCell(
.fg_r = colors.fg.r, .fg_r = colors.fg.r,
.fg_g = colors.fg.g, .fg_g = colors.fg.g,
.fg_b = colors.fg.b, .fg_b = colors.fg.b,
.fg_a = 255, .fg_a = alpha,
.bg_r = 0, .bg_r = 0,
.bg_g = 0, .bg_g = 0,
.bg_b = 0, .bg_b = 0,

View File

@ -301,6 +301,10 @@ pub fn setAttribute(self: *Terminal, attr: sgr.Attribute) !void {
self.screen.cursor.pen.attrs.bold = true; self.screen.cursor.pen.attrs.bold = true;
}, },
.faint => {
self.screen.cursor.pen.attrs.faint = true;
},
.underline => { .underline => {
self.screen.cursor.pen.attrs.underline = true; self.screen.cursor.pen.attrs.underline = true;
}, },

View File

@ -21,6 +21,9 @@ pub const Attribute = union(enum) {
/// Bold the text. /// Bold the text.
bold: void, bold: void,
/// Faint/dim text.
faint: void,
/// Underline the text /// Underline the text
underline: void, underline: void,
@ -88,6 +91,8 @@ pub const Parser = struct {
1 => return Attribute{ .bold = {} }, 1 => return Attribute{ .bold = {} },
2 => return Attribute{ .faint = {} },
4 => return Attribute{ .underline = {} }, 4 => return Attribute{ .underline = {} },
5 => return Attribute{ .blink = {} }, 5 => return Attribute{ .blink = {} },