From 08b6043166c17166173392aed1220d60716d3c43 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Fri, 19 Feb 2021 08:28:19 -0800 Subject: [PATCH] gui: introduce foreground_text_hsb transform This allows explicitly manipulating the hue, saturation, brightness of the text rendered in the terminal, allowing users to dial in the accidental effect that was introduced by d886de830091366cf79ee9b18ad24e6944cba104 For example, this will punch up the brightness: ``` foreground_text_hsb = { hue = 1.0, saturation = 1.0, brightness = 1.5, }, ``` refs: https://github.com/wez/wezterm/issues/491 --- config/src/color.rs | 12 +++++++++++- config/src/lib.rs | 2 ++ wezterm-gui/src/gui/fragment.glsl | 4 +++- wezterm-gui/src/gui/termwindow.rs | 10 ++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/config/src/color.rs b/config/src/color.rs index edeb22904..572c72bbf 100644 --- a/config/src/color.rs +++ b/config/src/color.rs @@ -3,7 +3,7 @@ use luahelper::impl_lua_conversion; use termwiz::cell::CellAttributes; use termwiz::color::{ColorSpec, RgbColor}; -#[derive(Debug, Default, Copy, Deserialize, Serialize, Clone)] +#[derive(Debug, Copy, Deserialize, Serialize, Clone)] pub struct HsbTransform { #[serde(default = "default_one_point_oh")] pub hue: f32, @@ -13,6 +13,16 @@ pub struct HsbTransform { pub brightness: f32, } +impl Default for HsbTransform { + fn default() -> Self { + Self { + hue: 1., + saturation: 1., + brightness: 1., + } + } +} + #[derive(Default, Debug, Deserialize, Serialize, Clone)] pub struct Palette { /// The text color to use when the attributes are reset to default diff --git a/config/src/lib.rs b/config/src/lib.rs index 4c73f8555..b80d34cb8 100644 --- a/config/src/lib.rs +++ b/config/src/lib.rs @@ -734,6 +734,8 @@ pub struct Config { pub window_background_image: Option, #[serde(default)] pub window_background_image_hsb: Option, + #[serde(default)] + pub foreground_text_hsb: HsbTransform, /// Specifies the alpha value to use when rendering the background /// of the window. The background is taken either from the diff --git a/wezterm-gui/src/gui/fragment.glsl b/wezterm-gui/src/gui/fragment.glsl index 26507b8fd..78d14cb8e 100644 --- a/wezterm-gui/src/gui/fragment.glsl +++ b/wezterm-gui/src/gui/fragment.glsl @@ -18,6 +18,8 @@ uniform bool has_background_image; uniform sampler2D atlas_nearest_sampler; uniform sampler2D atlas_linear_sampler; +uniform vec3 foreground_text_hsb; + out vec4 color; float multiply_one(float src, float dst, float inv_dst_alpha, float inv_src_alpha) { @@ -88,7 +90,7 @@ vec4 colorize(vec4 glyph, vec4 color) { vec4 colorize_hsv(vec4 glyph, vec4 color) { vec3 hsv = rgb2hsv(color.rgb); hsv.b *= glyph.a; - return vec4(hsv2rgb(hsv), glyph.a); + return vec4(hsv2rgb(hsv * foreground_text_hsb), glyph.a); } void main() { diff --git a/wezterm-gui/src/gui/termwindow.rs b/wezterm-gui/src/gui/termwindow.rs index 61b7a302f..906552bf7 100644 --- a/wezterm-gui/src/gui/termwindow.rs +++ b/wezterm-gui/src/gui/termwindow.rs @@ -2776,6 +2776,13 @@ impl TermWindow { let has_background_image = self.window_background.is_some(); + let foreground_text_hsb = configuration().foreground_text_hsb; + let foreground_text_hsb = ( + foreground_text_hsb.hue, + foreground_text_hsb.saturation, + foreground_text_hsb.brightness, + ); + // Pass 1: Draw backgrounds frame.draw( &*vb, @@ -2788,6 +2795,7 @@ impl TermWindow { window_bg_layer: true, bg_and_line_layer: false, has_background_image: has_background_image, + foreground_text_hsb: foreground_text_hsb, }, &alpha_blending, )?; @@ -2804,6 +2812,7 @@ impl TermWindow { window_bg_layer: false, bg_and_line_layer: true, has_background_image: has_background_image, + foreground_text_hsb: foreground_text_hsb, }, &alpha_blending, )?; @@ -2860,6 +2869,7 @@ impl TermWindow { window_bg_layer: false, bg_and_line_layer: false, has_background_image: has_background_image, + foreground_text_hsb: foreground_text_hsb, }, &blend_but_set_alpha_to_one, )?;