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

config: allow using bright but not bold text when brightening text

In https://github.com/wez/wezterm/issues/2932 the user desired to have
brightened text without the boldness, as they were accustomed to that
behavior in a couple of other terminal emulators.

This commit changes the `bold_brightens_ansi_colors` from a simple
boolean to a tristate that allows for not changing the brightness,
changing the brightness, and changing the brightness while adjusting
the boldness down to normal levels.

boolean values are accepted for backwards compatibility.
This commit is contained in:
Wez Furlong 2023-01-09 15:19:17 -07:00
parent 37055d2fab
commit 4ec428ff75
No known key found for this signature in database
GPG Key ID: 7A7F66A31EC9B387
5 changed files with 82 additions and 9 deletions

View File

@ -102,8 +102,8 @@ pub struct Config {
/// When true (the default), PaletteIndex 0-7 are shifted to
/// bright when the font intensity is bold. The brightening
/// doesn't apply to text that is the default color.
#[dynamic(default = "default_true")]
pub bold_brightens_ansi_colors: bool,
#[dynamic(default)]
pub bold_brightens_ansi_colors: BoldBrightening,
/// The color palette
pub colors: Option<Palette>,
@ -1729,6 +1729,45 @@ fn default_line_to_ele_shape_cache_size() -> usize {
1024
}
#[derive(Debug, ToDynamic, Clone, Copy, PartialEq, Eq)]
pub enum BoldBrightening {
/// Bold doesn't influence palette selection
No,
/// Bold Shifts palette from 0-7 to 8-15 and preserves bold font
BrightAndBold,
/// Bold Shifts palette from 0-7 to 8-15 and removes bold intensity
BrightOnly,
}
impl FromDynamic for BoldBrightening {
fn from_dynamic(
value: &wezterm_dynamic::Value,
options: wezterm_dynamic::FromDynamicOptions,
) -> Result<Self, wezterm_dynamic::Error> {
match String::from_dynamic(value, options) {
Ok(s) => match s.as_str() {
"No" => Ok(Self::No),
"BrightAndBold" => Ok(Self::BrightAndBold),
"BrightOnly" => Ok(Self::BrightOnly),
s => Err(wezterm_dynamic::Error::Message(format!(
"`{s}` is not valid, use one of `None`, `BrightAndBold` or `BrightOnly`"
))),
},
Err(err) => match bool::from_dynamic(value, options) {
Ok(true) => Ok(Self::BrightAndBold),
Ok(false) => Ok(Self::No),
Err(_) => Err(err),
},
}
}
}
impl Default for BoldBrightening {
fn default() -> Self {
BoldBrightening::BrightAndBold
}
}
#[derive(Debug, FromDynamic, ToDynamic, Clone, Copy, PartialEq, Eq)]
pub enum ImePreeditRendering {
/// IME preedit is rendered by WezTerm itself

View File

@ -49,6 +49,9 @@ As features stabilize some brief notes about them will accumulate here.
[@Abdiramen](https://github.com/Abdiramen)!
[#2889](https://github.com/wez/wezterm/pull/2889)
[#2782](https://github.com/wez/wezterm/issues/2782)
* [bold_brightens_ansi_colors](config/lua/config/bold_brightens_ansi_colors.md)
now supports `"BrightOnly"` to use the bright color without selecting a bold
font. [#2932](https://github.com/wez/wezterm/issues/2932)
#### Updated
* Bundled harfbuzz updated to version 6.0.0

View File

@ -11,3 +11,15 @@ range of mature software; for instance, a lot of software
assumes that Black+Bold renders as a Dark Grey which is
legible on a Black background, but if this option is set to
false, it would render as Black on Black.
*Since: nightly builds only*
This option can now have one of three values:
* `"No"` - the bold attribute will not influence palette selection
* `"BrightAndBold"` - the bold attribute will select a bright version of palette indices 0-7 and preserve the bold attribute on the text, using both a bold font and a brighter color
* `"BrightOnly"` - the bold attribute will select a bright version of palette indices 0-7 but the intensity will be treated as normal and a non-bold font will be used for the text.
You may use `true` or `false` for backwards compatibility. `true` is
equivalent to `"BrightAndBold"` and `false` is equivalent to `"No"`.

View File

@ -5,8 +5,8 @@ use crate::rasterizer::{new_rasterizer, FontRasterizer};
use crate::shaper::{new_shaper, FontShaper, PresentationWidth};
use anyhow::{Context, Error};
use config::{
configuration, ConfigHandle, FontAttributes, FontRasterizerSelection, FontStretch, FontStyle,
FontWeight, TextStyle,
configuration, BoldBrightening, ConfigHandle, FontAttributes, FontRasterizerSelection,
FontStretch, FontStyle, FontWeight, TextStyle,
};
use rangeset::RangeSet;
use std::cell::RefCell;
@ -19,7 +19,7 @@ use std::time::{Duration, Instant};
use termwiz::cell::Presentation;
use thiserror::Error;
use wezterm_bidi::Direction;
use wezterm_term::CellAttributes;
use wezterm_term::{CellAttributes, Intensity};
use wezterm_toast_notification::ToastNotification;
mod hbwrap;
@ -995,8 +995,27 @@ impl FontConfigInner {
};
}
let would_bright = match attrs.foreground() {
wezterm_term::color::ColorAttribute::PaletteIndex(idx) if idx < 8 => {
attrs.intensity() == Intensity::Bold
}
_ => false,
};
for rule in &config.font_rules {
attr_match!(intensity, &rule);
if let Some(intensity) = rule.intensity {
let effective_intensity = match config.bold_brightens_ansi_colors {
BoldBrightening::BrightOnly if would_bright => Intensity::Normal,
BoldBrightening::No
| BoldBrightening::BrightAndBold
| BoldBrightening::BrightOnly => attrs.intensity(),
};
if intensity != effective_intensity {
// Rule does not match
continue;
}
// matches so far
}
attr_match!(underline, &rule);
attr_match!(italic, &rule);
attr_match!(blink, &rule);

View File

@ -25,8 +25,8 @@ use ::window::glium::{BlendingFunction, LinearBlendingFactor, Surface};
use ::window::{glium, DeadKeyStatus, PointF, RectF, SizeF, ULength, WindowOps};
use anyhow::anyhow;
use config::{
ConfigHandle, Dimension, DimensionContext, FreeTypeLoadTarget, HsbTransform, TabBarColors,
TextStyle, VisualBellTarget,
BoldBrightening, ConfigHandle, Dimension, DimensionContext, FreeTypeLoadTarget, HsbTransform,
TabBarColors, TextStyle, VisualBellTarget,
};
use euclid::num::Zero;
use mux::pane::{Pane, PaneId, WithPaneLines};
@ -3738,7 +3738,7 @@ fn resolve_fg_color_attr(
}
}
wezterm_term::color::ColorAttribute::PaletteIndex(idx)
if idx < 8 && config.bold_brightens_ansi_colors =>
if idx < 8 && config.bold_brightens_ansi_colors != BoldBrightening::No =>
{
// For compatibility purposes, switch to a brighter version
// of one of the standard ANSI colors when Bold is enabled.