1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-25 14:22:37 +03:00

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
d886de8300

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
This commit is contained in:
Wez Furlong 2021-02-19 08:28:19 -08:00
parent 651e536d87
commit 08b6043166
4 changed files with 26 additions and 2 deletions

View File

@ -3,7 +3,7 @@ use luahelper::impl_lua_conversion;
use termwiz::cell::CellAttributes; use termwiz::cell::CellAttributes;
use termwiz::color::{ColorSpec, RgbColor}; use termwiz::color::{ColorSpec, RgbColor};
#[derive(Debug, Default, Copy, Deserialize, Serialize, Clone)] #[derive(Debug, Copy, Deserialize, Serialize, Clone)]
pub struct HsbTransform { pub struct HsbTransform {
#[serde(default = "default_one_point_oh")] #[serde(default = "default_one_point_oh")]
pub hue: f32, pub hue: f32,
@ -13,6 +13,16 @@ pub struct HsbTransform {
pub brightness: f32, pub brightness: f32,
} }
impl Default for HsbTransform {
fn default() -> Self {
Self {
hue: 1.,
saturation: 1.,
brightness: 1.,
}
}
}
#[derive(Default, Debug, Deserialize, Serialize, Clone)] #[derive(Default, Debug, Deserialize, Serialize, Clone)]
pub struct Palette { pub struct Palette {
/// The text color to use when the attributes are reset to default /// The text color to use when the attributes are reset to default

View File

@ -734,6 +734,8 @@ pub struct Config {
pub window_background_image: Option<PathBuf>, pub window_background_image: Option<PathBuf>,
#[serde(default)] #[serde(default)]
pub window_background_image_hsb: Option<HsbTransform>, pub window_background_image_hsb: Option<HsbTransform>,
#[serde(default)]
pub foreground_text_hsb: HsbTransform,
/// Specifies the alpha value to use when rendering the background /// Specifies the alpha value to use when rendering the background
/// of the window. The background is taken either from the /// of the window. The background is taken either from the

View File

@ -18,6 +18,8 @@ uniform bool has_background_image;
uniform sampler2D atlas_nearest_sampler; uniform sampler2D atlas_nearest_sampler;
uniform sampler2D atlas_linear_sampler; uniform sampler2D atlas_linear_sampler;
uniform vec3 foreground_text_hsb;
out vec4 color; out vec4 color;
float multiply_one(float src, float dst, float inv_dst_alpha, float inv_src_alpha) { 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) { vec4 colorize_hsv(vec4 glyph, vec4 color) {
vec3 hsv = rgb2hsv(color.rgb); vec3 hsv = rgb2hsv(color.rgb);
hsv.b *= glyph.a; hsv.b *= glyph.a;
return vec4(hsv2rgb(hsv), glyph.a); return vec4(hsv2rgb(hsv * foreground_text_hsb), glyph.a);
} }
void main() { void main() {

View File

@ -2776,6 +2776,13 @@ impl TermWindow {
let has_background_image = self.window_background.is_some(); 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 // Pass 1: Draw backgrounds
frame.draw( frame.draw(
&*vb, &*vb,
@ -2788,6 +2795,7 @@ impl TermWindow {
window_bg_layer: true, window_bg_layer: true,
bg_and_line_layer: false, bg_and_line_layer: false,
has_background_image: has_background_image, has_background_image: has_background_image,
foreground_text_hsb: foreground_text_hsb,
}, },
&alpha_blending, &alpha_blending,
)?; )?;
@ -2804,6 +2812,7 @@ impl TermWindow {
window_bg_layer: false, window_bg_layer: false,
bg_and_line_layer: true, bg_and_line_layer: true,
has_background_image: has_background_image, has_background_image: has_background_image,
foreground_text_hsb: foreground_text_hsb,
}, },
&alpha_blending, &alpha_blending,
)?; )?;
@ -2860,6 +2869,7 @@ impl TermWindow {
window_bg_layer: false, window_bg_layer: false,
bg_and_line_layer: false, bg_and_line_layer: false,
has_background_image: has_background_image, has_background_image: has_background_image,
foreground_text_hsb: foreground_text_hsb,
}, },
&blend_but_set_alpha_to_one, &blend_but_set_alpha_to_one,
)?; )?;