Skip to content

Commit

Permalink
respect new underline color when rendering
Browse files Browse the repository at this point in the history
```
printf "\x1b[4m\x1b[58;2;255;0;0mred underline\x1b[0m"
```

prints "red underline" in the foreground color, with an
underline that is bright red `rgb(255, 0, 0)`.

refs: #415
  • Loading branch information
wez committed Jan 5, 2021
1 parent b35f3aa commit 7c8f2b7
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 25 deletions.
5 changes: 3 additions & 2 deletions wezterm-gui/src/gui/fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ in vec3 o_hsv;
in vec4 o_bg_color;
in vec4 o_cursor_color;
in vec4 o_fg_color;
in vec4 o_underline_color;

uniform mat4 projection;
uniform bool window_bg_layer;
Expand Down Expand Up @@ -89,9 +90,9 @@ void main() {
vec4 under_color = texture(atlas_nearest_sampler, o_underline);
if (under_color.a != 0.0) {
// if the underline glyph isn't transparent in this position then
// we take the text fg color, otherwise we'll leave the color
// we take the underline color, otherwise we'll leave the color
// at the background color.
color = o_fg_color;
color = o_underline_color;
}

// Similar to the above: if the cursor texture isn't transparent
Expand Down
9 changes: 9 additions & 0 deletions wezterm-gui/src/gui/quad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub struct Vertex {
pub cursor_color: (f32, f32, f32, f32),
pub bg_color: (f32, f32, f32, f32),
pub fg_color: (f32, f32, f32, f32),
pub underline_color: (f32, f32, f32, f32),
pub hsv: (f32, f32, f32),
// We use a float for this because I can't get
// bool or integer values to work:
Expand All @@ -55,6 +56,7 @@ pub struct Vertex {
cursor_color,
bg_color,
fg_color,
underline_color,
hsv,
has_color
);
Expand Down Expand Up @@ -171,6 +173,13 @@ impl<'a> Quad<'a> {
}
}

pub fn set_underline_color(&mut self, color: Color) {
let color = color.to_tuple_rgba();
for v in self.vert.iter_mut() {
v.underline_color = color;
}
}

pub fn set_bg_color(&mut self, color: Color) {
let color = color.to_tuple_rgba();
for v in self.vert.iter_mut() {
Expand Down
66 changes: 43 additions & 23 deletions wezterm-gui/src/gui/termwindow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2434,6 +2434,7 @@ impl TermWindow {
};

quad.set_fg_color(foreground);
quad.set_underline_color(foreground);
quad.set_bg_color(background);
quad.set_hsv(None);
quad.set_texture(texture_rect);
Expand Down Expand Up @@ -2563,6 +2564,7 @@ impl TermWindow {

quad.set_bg_color(color);
quad.set_fg_color(color);
quad.set_underline_color(color);
quad.set_position(left, top, right, bottom);
quad.set_texture(white_space);
quad.set_texture_adjust(0., 0., 0., 0.);
Expand Down Expand Up @@ -2594,6 +2596,7 @@ impl TermWindow {
quad.set_hsv(config.window_background_image_hsb);
quad.set_cursor_color(color);
quad.set_fg_color(color);
quad.set_underline_color(color);
quad.set_bg_color(color);
}

Expand Down Expand Up @@ -2803,31 +2806,40 @@ impl TermWindow {

let bg_is_default = attrs.background == ColorAttribute::Default;
let bg_color = params.palette.resolve_bg(attrs.background);
let fg_color = match attrs.foreground {
wezterm_term::color::ColorAttribute::Default => {
if let Some(fg) = style.foreground {
fg
} else {
params.palette.resolve_fg(attrs.foreground)

fn resolve_fg_color_attr(
attrs: &CellAttributes,
fg: &ColorAttribute,
params: &RenderScreenLineOpenGLParams,
style: &config::TextStyle,
) -> RgbColor {
match fg {
wezterm_term::color::ColorAttribute::Default => {
if let Some(fg) = style.foreground {
fg
} else {
params.palette.resolve_fg(attrs.foreground)
}
}
wezterm_term::color::ColorAttribute::PaletteIndex(idx)
if *idx < 8 && params.config.bold_brightens_ansi_colors =>
{
// For compatibility purposes, switch to a brighter version
// of one of the standard ANSI colors when Bold is enabled.
// This lifts black to dark grey.
let idx = if attrs.intensity() == wezterm_term::Intensity::Bold {
*idx + 8
} else {
*idx
};
params
.palette
.resolve_fg(wezterm_term::color::ColorAttribute::PaletteIndex(idx))
}
_ => params.palette.resolve_fg(*fg),
}
wezterm_term::color::ColorAttribute::PaletteIndex(idx)
if idx < 8 && params.config.bold_brightens_ansi_colors =>
{
// For compatibility purposes, switch to a brighter version
// of one of the standard ANSI colors when Bold is enabled.
// This lifts black to dark grey.
let idx = if attrs.intensity() == wezterm_term::Intensity::Bold {
idx + 8
} else {
idx
};
params
.palette
.resolve_fg(wezterm_term::color::ColorAttribute::PaletteIndex(idx))
}
_ => params.palette.resolve_fg(attrs.foreground),
};
}
let fg_color = resolve_fg_color_attr(&attrs, &attrs.foreground, &params, &style);

let (fg_color, bg_color, bg_is_default) = {
let mut fg = fg_color;
Expand All @@ -2843,6 +2855,11 @@ impl TermWindow {
};

let glyph_color = rgbcolor_to_window_color(fg_color);
let underline_color = match attrs.underline_color() {
ColorAttribute::Default => fg_color,
c => resolve_fg_color_attr(&attrs, &c, &params, &style),
};
let underline_color = rgbcolor_to_window_color(underline_color);

let bg_color = rgbcolor_alpha_to_window_color(
bg_color,
Expand Down Expand Up @@ -3015,6 +3032,7 @@ impl TermWindow {

quad.set_hsv(hsv);
quad.set_fg_color(glyph_color);
quad.set_underline_color(underline_color);
quad.set_bg_color(bg_color);
quad.set_texture(texture_rect);
quad.set_texture_adjust(0., 0., 0., 0.);
Expand Down Expand Up @@ -3065,6 +3083,7 @@ impl TermWindow {
quad.set_texture(texture_rect);
quad.set_texture_adjust(left, top, right, bottom);
quad.set_underline(underline_tex_rect);
quad.set_underline_color(underline_color);
quad.set_hsv(hsv);
quad.set_has_color(glyph.has_color);
quad.set_cursor(
Expand Down Expand Up @@ -3121,6 +3140,7 @@ impl TermWindow {

quad.set_bg_color(bg_color);
quad.set_fg_color(glyph_color);
quad.set_underline_color(glyph_color);
quad.set_texture(white_space);
quad.set_texture_adjust(0., 0., 0., 0.);
quad.set_underline(white_space);
Expand Down
3 changes: 3 additions & 0 deletions wezterm-gui/src/gui/vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ in vec2 tex;
in vec2 underline;
in vec4 bg_color;
in vec4 fg_color;
in vec4 underline_color;
in float has_color;
in vec2 cursor;
in vec4 cursor_color;
Expand All @@ -24,6 +25,7 @@ out vec3 o_hsv;
out vec4 o_bg_color;
out vec4 o_cursor_color;
out vec4 o_fg_color;
out vec4 o_underline_color;

// Returns a position that is outside of the viewport,
// such that this vertex effectively won't contribute
Expand All @@ -39,6 +41,7 @@ void main() {
o_fg_color = fg_color;
o_bg_color = bg_color;
o_underline = underline;
o_underline_color = underline_color;
o_cursor = cursor;
o_cursor_color = cursor_color;
o_hsv = hsv;
Expand Down

0 comments on commit 7c8f2b7

Please sign in to comment.