Skip to content

Commit

Permalink
Add bright foreground color option
Browse files Browse the repository at this point in the history
It was requested in alacritty#825 that it should be possible to
add an optional bright foreground color.

This is now added to the primary colors structure and allows the user to
set a foreground color for bold normal text. This has no effect unless
the `draw_bold_text_with_bright_colors` option is also enabled.

If the color is not specified, the bright foreground color will fall
back to the normal foreground color.
  • Loading branch information
chrisduerr committed Mar 5, 2018
1 parent 82c8bde commit 63d8234
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions alacritty.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ colors:
primary:
background: '0x000000'
foreground: '0xeaeaea'
bright_foreground: '0xeaeaea'

# Colors the cursor will use if `custom_cursor_colors` is true
cursor:
Expand Down
1 change: 1 addition & 0 deletions alacritty_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ colors:
primary:
background: '0x000000'
foreground: '0xeaeaea'
bright_foreground: '0xeaeaea'

# Colors the cursor will use if `custom_cursor_colors` is true
cursor:
Expand Down
3 changes: 3 additions & 0 deletions src/ansi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,8 @@ pub enum NamedColor {
BrightWhite,
/// The foreground color
Foreground = 256,
/// The bright foreground color
BrightForeground,
/// The background color
Background,
/// Color for the text under the cursor
Expand Down Expand Up @@ -563,6 +565,7 @@ pub enum NamedColor {
impl NamedColor {
pub fn to_bright(&self) -> Self {
match *self {
NamedColor::Foreground => NamedColor::BrightForeground,
NamedColor::Black => NamedColor::BrightBlack,
NamedColor::Red => NamedColor::BrightRed,
NamedColor::Green => NamedColor::BrightGreen,
Expand Down
19 changes: 19 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,13 +1017,32 @@ pub struct PrimaryColors {
pub background: Rgb,
#[serde(deserialize_with = "rgb_from_hex")]
pub foreground: Rgb,
#[serde(default, deserialize_with = "deserialize_bright_foreground")]
pub bright_foreground: Option<Rgb>,
}

fn deserialize_bright_foreground<'a, D>(deserializer: D) -> ::std::result::Result<Option<Rgb>, D::Error>
where D: de::Deserializer<'a>
{
match Option::deserialize(deserializer) {
Ok(Some(color)) => {
let color: serde_yaml::Value = color;
Ok(Some(rgb_from_hex(color).unwrap()))
},
Ok(None) => Ok(None),
Err(err) => {
eprintln!("problem with config: {}; Using foreground color", err);
Ok(None)
},
}
}

impl Default for PrimaryColors {
fn default() -> Self {
PrimaryColors {
background: Rgb { r: 0, g: 0, b: 0 },
foreground: Rgb { r: 0xea, g: 0xea, b: 0xea },
bright_foreground: None,
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/term/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::fmt;
use {Rgb, ansi};
use config::Colors;

pub const COUNT: usize = 268;
pub const COUNT: usize = 269;

/// List of indexed colors
///
Expand Down Expand Up @@ -50,6 +50,10 @@ impl List {
self[ansi::NamedColor::BrightMagenta] = colors.bright.magenta;
self[ansi::NamedColor::BrightCyan] = colors.bright.cyan;
self[ansi::NamedColor::BrightWhite] = colors.bright.white;
self[ansi::NamedColor::BrightForeground] = colors
.primary
.bright_foreground
.unwrap_or(colors.primary.foreground);

// Foreground and background
self[ansi::NamedColor::Foreground] = colors.primary.foreground;
Expand Down

0 comments on commit 63d8234

Please sign in to comment.