mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-25 14:05:41 -05:00
Add optional dim foreground color
Add optional color for the dim foreground (`\e[2m;`) Defaults to 2/3 of the foreground color. (same as other colors). If a bright color is dimmed, it's displayed as the normal color. The exception for this is when the bright foreground is dimmed when no bright foreground color is set. In that case it's treated as a normal foreground color and dimmed to DimForeground. To minimize the surprise for the user, the bright and dim colors have been completely removed from the default configuration file. Some documentation has also been added to make it clear to users what these options can be used for. This fixes #1448.
This commit is contained in:
parent
ea512cb0f3
commit
d25134bc6b
6 changed files with 44 additions and 9 deletions
|
@ -117,7 +117,15 @@ colors:
|
||||||
primary:
|
primary:
|
||||||
background: '0x000000'
|
background: '0x000000'
|
||||||
foreground: '0xeaeaea'
|
foreground: '0xeaeaea'
|
||||||
bright_foreground: '0xeaeaea'
|
|
||||||
|
# (Optional) Bright and Dim foreground colors
|
||||||
|
#
|
||||||
|
# The dimmed foreground color is calculated automatically if it is not present.
|
||||||
|
# If the bright foreground color is not set, or `draw_bold_text_with_bright_colors`
|
||||||
|
# is `false`, the normal foreground color will be used.
|
||||||
|
#
|
||||||
|
# dim_foreground: '0x9a9a9a'
|
||||||
|
# bright_foreground: '0xffffff'
|
||||||
|
|
||||||
# Colors the cursor will use if `custom_cursor_colors` is true
|
# Colors the cursor will use if `custom_cursor_colors` is true
|
||||||
cursor:
|
cursor:
|
||||||
|
|
|
@ -95,7 +95,15 @@ colors:
|
||||||
primary:
|
primary:
|
||||||
background: '0x000000'
|
background: '0x000000'
|
||||||
foreground: '0xeaeaea'
|
foreground: '0xeaeaea'
|
||||||
bright_foreground: '0xeaeaea'
|
|
||||||
|
# (Optional) Bright and Dim foreground colors
|
||||||
|
#
|
||||||
|
# The dimmed foreground color is calculated automatically if it is not present.
|
||||||
|
# If the bright foreground color is not set, or `draw_bold_text_with_bright_colors`
|
||||||
|
# is `false`, the normal foreground color will be used.
|
||||||
|
#
|
||||||
|
# dim_foreground: '0x9a9a9a'
|
||||||
|
# bright_foreground: '0xffffff'
|
||||||
|
|
||||||
# Colors the cursor will use if `custom_cursor_colors` is true
|
# Colors the cursor will use if `custom_cursor_colors` is true
|
||||||
cursor:
|
cursor:
|
||||||
|
|
|
@ -560,6 +560,8 @@ pub enum NamedColor {
|
||||||
DimWhite,
|
DimWhite,
|
||||||
/// The bright foreground color
|
/// The bright foreground color
|
||||||
BrightForeground,
|
BrightForeground,
|
||||||
|
/// Dim foreground
|
||||||
|
DimForeground,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NamedColor {
|
impl NamedColor {
|
||||||
|
@ -574,6 +576,7 @@ impl NamedColor {
|
||||||
NamedColor::Magenta => NamedColor::BrightMagenta,
|
NamedColor::Magenta => NamedColor::BrightMagenta,
|
||||||
NamedColor::Cyan => NamedColor::BrightCyan,
|
NamedColor::Cyan => NamedColor::BrightCyan,
|
||||||
NamedColor::White => NamedColor::BrightWhite,
|
NamedColor::White => NamedColor::BrightWhite,
|
||||||
|
NamedColor::DimForeground => NamedColor::Foreground,
|
||||||
NamedColor::DimBlack => NamedColor::Black,
|
NamedColor::DimBlack => NamedColor::Black,
|
||||||
NamedColor::DimRed => NamedColor::Red,
|
NamedColor::DimRed => NamedColor::Red,
|
||||||
NamedColor::DimGreen => NamedColor::Green,
|
NamedColor::DimGreen => NamedColor::Green,
|
||||||
|
@ -596,6 +599,7 @@ impl NamedColor {
|
||||||
NamedColor::Magenta => NamedColor::DimMagenta,
|
NamedColor::Magenta => NamedColor::DimMagenta,
|
||||||
NamedColor::Cyan => NamedColor::DimCyan,
|
NamedColor::Cyan => NamedColor::DimCyan,
|
||||||
NamedColor::White => NamedColor::DimWhite,
|
NamedColor::White => NamedColor::DimWhite,
|
||||||
|
NamedColor::Foreground => NamedColor::DimForeground,
|
||||||
NamedColor::BrightBlack => NamedColor::Black,
|
NamedColor::BrightBlack => NamedColor::Black,
|
||||||
NamedColor::BrightRed => NamedColor::Red,
|
NamedColor::BrightRed => NamedColor::Red,
|
||||||
NamedColor::BrightGreen => NamedColor::Green,
|
NamedColor::BrightGreen => NamedColor::Green,
|
||||||
|
@ -604,6 +608,7 @@ impl NamedColor {
|
||||||
NamedColor::BrightMagenta => NamedColor::Magenta,
|
NamedColor::BrightMagenta => NamedColor::Magenta,
|
||||||
NamedColor::BrightCyan => NamedColor::Cyan,
|
NamedColor::BrightCyan => NamedColor::Cyan,
|
||||||
NamedColor::BrightWhite => NamedColor::White,
|
NamedColor::BrightWhite => NamedColor::White,
|
||||||
|
NamedColor::BrightForeground => NamedColor::Foreground,
|
||||||
val => val
|
val => val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1023,11 +1023,13 @@ pub struct PrimaryColors {
|
||||||
pub background: Rgb,
|
pub background: Rgb,
|
||||||
#[serde(deserialize_with = "rgb_from_hex")]
|
#[serde(deserialize_with = "rgb_from_hex")]
|
||||||
pub foreground: Rgb,
|
pub foreground: Rgb,
|
||||||
#[serde(default, deserialize_with = "deserialize_bright_foreground")]
|
#[serde(default, deserialize_with = "deserialize_optional_color")]
|
||||||
pub bright_foreground: Option<Rgb>,
|
pub bright_foreground: Option<Rgb>,
|
||||||
|
#[serde(default, deserialize_with = "deserialize_optional_color")]
|
||||||
|
pub dim_foreground: Option<Rgb>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize_bright_foreground<'a, D>(deserializer: D) -> ::std::result::Result<Option<Rgb>, D::Error>
|
fn deserialize_optional_color<'a, D>(deserializer: D) -> ::std::result::Result<Option<Rgb>, D::Error>
|
||||||
where D: de::Deserializer<'a>
|
where D: de::Deserializer<'a>
|
||||||
{
|
{
|
||||||
match Option::deserialize(deserializer) {
|
match Option::deserialize(deserializer) {
|
||||||
|
@ -1049,6 +1051,7 @@ impl Default for PrimaryColors {
|
||||||
background: Rgb { r: 0, g: 0, b: 0 },
|
background: Rgb { r: 0, g: 0, b: 0 },
|
||||||
foreground: Rgb { r: 0xea, g: 0xea, b: 0xea },
|
foreground: Rgb { r: 0xea, g: 0xea, b: 0xea },
|
||||||
bright_foreground: None,
|
bright_foreground: None,
|
||||||
|
dim_foreground: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ use std::fmt;
|
||||||
use {Rgb, ansi};
|
use {Rgb, ansi};
|
||||||
use config::Colors;
|
use config::Colors;
|
||||||
|
|
||||||
pub const COUNT: usize = 269;
|
pub const COUNT: usize = 270;
|
||||||
|
|
||||||
/// List of indexed colors
|
/// List of indexed colors
|
||||||
///
|
///
|
||||||
|
@ -13,7 +13,7 @@ pub const COUNT: usize = 269;
|
||||||
/// the configured foreground color, item 257 is the configured background
|
/// the configured foreground color, item 257 is the configured background
|
||||||
/// color, item 258 is the cursor foreground color, item 259 is the cursor
|
/// color, item 258 is the cursor foreground color, item 259 is the cursor
|
||||||
/// background color. Following that are 8 positions for dim colors.
|
/// background color. Following that are 8 positions for dim colors.
|
||||||
/// Item 268 is the bright foreground color.
|
/// Item 268 is the bright foreground color, 269 the dim foreground.
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct List([Rgb; COUNT]);
|
pub struct List([Rgb; COUNT]);
|
||||||
|
|
||||||
|
@ -65,6 +65,10 @@ impl List {
|
||||||
self[ansi::NamedColor::Cursor] = colors.cursor.cursor;
|
self[ansi::NamedColor::Cursor] = colors.cursor.cursor;
|
||||||
|
|
||||||
// Dims
|
// Dims
|
||||||
|
self[ansi::NamedColor::DimForeground] = colors
|
||||||
|
.primary
|
||||||
|
.dim_foreground
|
||||||
|
.unwrap_or(colors.primary.foreground * 0.66);
|
||||||
match colors.dim {
|
match colors.dim {
|
||||||
Some(ref dim) => {
|
Some(ref dim) => {
|
||||||
trace!("Using config-provided dim colors");
|
trace!("Using config-provided dim colors");
|
||||||
|
|
|
@ -275,11 +275,18 @@ impl<'a> RenderableCellsIter<'a> {
|
||||||
Color::Spec(rgb) => rgb,
|
Color::Spec(rgb) => rgb,
|
||||||
Color::Named(ansi) => {
|
Color::Named(ansi) => {
|
||||||
match (self.config.draw_bold_text_with_bright_colors(), cell.flags & Flags::DIM_BOLD) {
|
match (self.config.draw_bold_text_with_bright_colors(), cell.flags & Flags::DIM_BOLD) {
|
||||||
|
// If no bright foreground is set, treat it like the BOLD flag doesn't exist
|
||||||
|
(_, self::cell::Flags::DIM_BOLD)
|
||||||
|
if ansi == NamedColor::Foreground
|
||||||
|
&& self.config.colors().primary.bright_foreground.is_none() =>
|
||||||
|
{
|
||||||
|
self.colors[NamedColor::DimForeground]
|
||||||
|
}
|
||||||
// Draw bold text in bright colors *and* contains bold flag.
|
// Draw bold text in bright colors *and* contains bold flag.
|
||||||
(true, self::cell::Flags::DIM_BOLD) |
|
(true, self::cell::Flags::BOLD) => self.colors[ansi.to_bright()],
|
||||||
(true, self::cell::Flags::BOLD) => self.colors[ansi.to_bright()],
|
|
||||||
// Cell is marked as dim and not bold
|
// Cell is marked as dim and not bold
|
||||||
(_, self::cell::Flags::DIM) => self.colors[ansi.to_dim()],
|
(_, self::cell::Flags::DIM) |
|
||||||
|
(false, self::cell::Flags::DIM_BOLD) => self.colors[ansi.to_dim()],
|
||||||
// None of the above, keep original color.
|
// None of the above, keep original color.
|
||||||
_ => self.colors[ansi]
|
_ => self.colors[ansi]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue