1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-18 13:55:23 -05:00

Change cursor colors config to use text and cursor

This changes the cursor color config to use the `text` and `cursor`
properties instead of the current `foreground` and `background`
properties. The latter names stop making sense when dealing with cursors
like a vertical bar or underscore. In the new system, the block,
underscore, or vertical bar would always take the color of `cursor`, and
the text would take the color of `text` when using a block, or keep its
normal color when using the underscore or vertical bar.

A warning is now emitted on startup when the old form of cursor color
config is used. This will be a hard error in the future.
This commit is contained in:
Joe Wilm 2017-02-24 08:23:07 -08:00 committed by Joe Wilm
parent fef965c121
commit 31ed5160a0
8 changed files with 109 additions and 41 deletions

22
Cargo.lock generated
View file

@ -18,8 +18,8 @@ dependencies = [
"mio 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"notify 2.6.3 (registry+https://github.com/rust-lang/crates.io-index)", "notify 2.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_yaml 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde_yaml 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"vte 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "vte 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -850,12 +850,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "serde" name = "serde"
version = "0.9.3" version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "serde_codegen_internals" name = "serde_codegen_internals"
version = "0.12.0" version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"syn 0.11.4 (registry+https://github.com/rust-lang/crates.io-index)", "syn 0.11.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -863,11 +863,11 @@ dependencies = [
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "0.9.2" version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"quote 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_codegen_internals 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde_codegen_internals 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.11.4 (registry+https://github.com/rust-lang/crates.io-index)", "syn 0.11.4 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -890,7 +890,7 @@ dependencies = [
"dtoa 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "dtoa 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"itoa 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "itoa 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@ -899,7 +899,7 @@ version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"linked-hash-map 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "linked-hash-map 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)",
"yaml-rust 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "yaml-rust 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -1285,9 +1285,9 @@ dependencies = [
"checksum semver 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2d5b7638a1f03815d94e88cb3b3c08e87f0db4d683ef499d1836aaf70a45623f" "checksum semver 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2d5b7638a1f03815d94e88cb3b3c08e87f0db4d683ef499d1836aaf70a45623f"
"checksum serde 0.7.15 (registry+https://github.com/rust-lang/crates.io-index)" = "1b0e0732aa8ec4267f61815a396a942ba3525062e3bd5520aa8419927cfc0a92" "checksum serde 0.7.15 (registry+https://github.com/rust-lang/crates.io-index)" = "1b0e0732aa8ec4267f61815a396a942ba3525062e3bd5520aa8419927cfc0a92"
"checksum serde 0.8.23 (registry+https://github.com/rust-lang/crates.io-index)" = "9dad3f759919b92c3068c696c15c3d17238234498bbdcc80f2c469606f948ac8" "checksum serde 0.8.23 (registry+https://github.com/rust-lang/crates.io-index)" = "9dad3f759919b92c3068c696c15c3d17238234498bbdcc80f2c469606f948ac8"
"checksum serde 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ff246881a798936bb630947e77add6c4b031fbf28312aca8e3d7c8949429e5f0" "checksum serde 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)" = "204db0f2a5335be7313fd4453132fd56d2085aed081c673140a256772903e116"
"checksum serde_codegen_internals 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fbca5cba592a2874e48fb67a61479f5b86c0b84a86cf82fa81f947ea538e1449" "checksum serde_codegen_internals 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a5113d5bd16471b183803b374f0fe4877ad9658b95e33b11f4a004d73aacc74a"
"checksum serde_derive 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7278d46eaf402b063c25288d0e4232029e9fb2f20e272a932b2c15a9fed7f32d" "checksum serde_derive 0.9.8 (registry+https://github.com/rust-lang/crates.io-index)" = "e88ec062a02cbebfd6276044a305d665a9919b497aa6acb2e12c070d1a50d32d"
"checksum serde_json 0.8.6 (registry+https://github.com/rust-lang/crates.io-index)" = "67f7d2e9edc3523a9c8ec8cd6ec481b3a27810aafee3e625d311febd3e656b4c" "checksum serde_json 0.8.6 (registry+https://github.com/rust-lang/crates.io-index)" = "67f7d2e9edc3523a9c8ec8cd6ec481b3a27810aafee3e625d311febd3e656b4c"
"checksum serde_json 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d30dd31e5b6b2752ba87da4bb34edc01391bbab71563fc1e95cdd1e30dce16b8" "checksum serde_json 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d30dd31e5b6b2752ba87da4bb34edc01391bbab71563fc1e95cdd1e30dce16b8"
"checksum serde_yaml 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6c13dac9aa2a6dd1172806c391e4c1a3853708b3161ebef9cb7892dc31509332" "checksum serde_yaml 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6c13dac9aa2a6dd1172806c391e4c1a3853708b3161ebef9cb7892dc31509332"

View file

@ -79,8 +79,8 @@ colors:
# Colors the cursor will use if `custom_cursor_colors` is true # Colors the cursor will use if `custom_cursor_colors` is true
cursor: cursor:
background: '0xffffff' text: '0x000000'
foreground: '0x000000' cursor: '0xffffff'
# Normal colors # Normal colors
normal: normal:

View file

@ -78,8 +78,8 @@ colors:
# Colors the cursor will use if `custom_cursor_colors` is true # Colors the cursor will use if `custom_cursor_colors` is true
cursor: cursor:
background: '0xffffff' text: '0x000000'
foreground: '0x000000' cursor: '0xffffff'
# Normal colors # Normal colors
normal: normal:

View file

@ -383,10 +383,10 @@ pub enum NamedColor {
Foreground = 256, Foreground = 256,
/// The background color /// The background color
Background, Background,
/// The cursor foreground color /// Color for the text under the cursor
CursorForeground, CursorText,
/// The cursor background color /// Color for the cursor itself
CursorBackground, Cursor,
} }
impl NamedColor { impl NamedColor {

View file

@ -24,6 +24,8 @@ use notify::{Watcher as WatcherApi, RecommendedWatcher as FileWatcher, op};
use input::{Action, Binding, MouseBinding, KeyBinding}; use input::{Action, Binding, MouseBinding, KeyBinding};
use index::{Line, Column}; use index::{Line, Column};
use util::fmt::Yellow;
/// Function that returns true for serde default /// Function that returns true for serde default
fn true_bool() -> bool { fn true_bool() -> bool {
true true
@ -694,19 +696,72 @@ pub enum Error {
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct Colors { pub struct Colors {
pub primary: PrimaryColors, pub primary: PrimaryColors,
#[serde(default="default_cursor_colors")] #[serde(deserialize_with="deserialize_cursor_colors", default="default_cursor_colors")]
pub cursor: PrimaryColors, pub cursor: CursorColors,
pub normal: AnsiColors, pub normal: AnsiColors,
pub bright: AnsiColors, pub bright: AnsiColors,
} }
fn default_cursor_colors() -> PrimaryColors { fn deserialize_cursor_colors<D>(deserializer: D) -> ::std::result::Result<CursorColors, D::Error>
PrimaryColors { where D: de::Deserializer
foreground: Rgb { r: 0, g: 0, b: 0 }, {
background: Rgb { r: 0xff, g: 0xff, b: 0xff }, let either = CursorOrPrimaryColors::deserialize(deserializer)?;
Ok(either.into_cursor_colors())
}
#[derive(Deserialize)]
#[serde(untagged)]
pub enum CursorOrPrimaryColors {
Cursor {
#[serde(deserialize_with = "rgb_from_hex")]
text: Rgb,
#[serde(deserialize_with = "rgb_from_hex")]
cursor: Rgb,
},
Primary {
#[serde(deserialize_with = "rgb_from_hex")]
foreground: Rgb,
#[serde(deserialize_with = "rgb_from_hex")]
background: Rgb,
} }
} }
impl CursorOrPrimaryColors {
fn into_cursor_colors(self) -> CursorColors {
match self {
CursorOrPrimaryColors::Cursor { text, cursor } => CursorColors {
text: text,
cursor: cursor
},
CursorOrPrimaryColors::Primary { foreground, background } => {
// Must print in config since logger isn't setup yet.
println!("{}",
Yellow("You're using a deprecated form of cursor color config. Please update \
your config to use `text` and `cursor` properties instead of `foreground` \
and `background`. This will become an error in a future release.")
);
CursorColors {
text: foreground,
cursor: background
}
}
}
}
}
fn default_cursor_colors() -> CursorColors {
CursorColors {
text: Rgb { r: 0, g: 0, b: 0 },
cursor: Rgb { r: 0xff, g: 0xff, b: 0xff },
}
}
#[derive(Debug)]
pub struct CursorColors {
pub text: Rgb,
pub cursor: Rgb,
}
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct PrimaryColors { pub struct PrimaryColors {
#[serde(deserialize_with = "rgb_from_hex")] #[serde(deserialize_with = "rgb_from_hex")]
@ -731,7 +786,7 @@ impl Default for Colors {
blue: Rgb {r: 0x7a, g: 0xa6, b: 0xda}, blue: Rgb {r: 0x7a, g: 0xa6, b: 0xda},
magenta: Rgb {r: 0xc3, g: 0x97, b: 0xd8}, magenta: Rgb {r: 0xc3, g: 0x97, b: 0xd8},
cyan: Rgb {r: 0x70, g: 0xc0, b: 0xba}, cyan: Rgb {r: 0x70, g: 0xc0, b: 0xba},
white: Rgb {r: 0x42, g: 0x42, b: 0x42}, white: Rgb {r: 0xea, g: 0xea, b: 0xea},
}, },
bright: AnsiColors { bright: AnsiColors {
black: Rgb {r: 0x66, g: 0x66, b: 0x66}, black: Rgb {r: 0x66, g: 0x66, b: 0x66},
@ -741,7 +796,7 @@ impl Default for Colors {
blue: Rgb {r: 0x7a, g: 0xa6, b: 0xda}, blue: Rgb {r: 0x7a, g: 0xa6, b: 0xda},
magenta: Rgb {r: 0xb7, g: 0x7e, b: 0xe0}, magenta: Rgb {r: 0xb7, g: 0x7e, b: 0xe0},
cyan: Rgb {r: 0x54, g: 0xce, b: 0xd6}, cyan: Rgb {r: 0x54, g: 0xce, b: 0xd6},
white: Rgb {r: 0x2a, g: 0x2a, b: 0x2a}, white: Rgb {r: 0xff, g: 0xff, b: 0xff},
} }
} }
} }

View file

@ -53,8 +53,8 @@ impl List {
self[ansi::NamedColor::Background] = colors.primary.background; self[ansi::NamedColor::Background] = colors.primary.background;
// Foreground and background for custom cursor colors // Foreground and background for custom cursor colors
self[ansi::NamedColor::CursorForeground] = colors.cursor.foreground; self[ansi::NamedColor::CursorText] = colors.cursor.text;
self[ansi::NamedColor::CursorBackground] = colors.cursor.background; self[ansi::NamedColor::Cursor] = colors.cursor.cursor;
} }
fn fill_cube(&mut self) { fn fill_cube(&mut self) {

View file

@ -91,9 +91,8 @@ impl<'a> RenderableCellsIter<'a> {
if self.config.custom_cursor_colors() { if self.config.custom_cursor_colors() {
let cell = &mut self.grid[self.cursor]; let cell = &mut self.grid[self.cursor];
cell.fg = Color::Named(NamedColor::CursorForeground); cell.fg = Color::Named(NamedColor::CursorText);
cell.bg = Color::Named(NamedColor::CursorBackground); cell.bg = Color::Named(NamedColor::Cursor);
} else { } else {
let cell = &mut self.grid[self.cursor]; let cell = &mut self.grid[self.cursor];
mem::swap(&mut cell.fg, &mut cell.bg); mem::swap(&mut cell.fg, &mut cell.bg);

View file

@ -49,19 +49,33 @@ pub fn limit<T: Ord>(value: T, min: T, max: T) -> T {
pub mod fmt { pub mod fmt {
use std::fmt; use std::fmt;
/// Write a `Display` or `Debug` escaped with Red macro_rules! define_colors {
pub struct Red<T>(pub T); ($($(#[$attrs:meta])* pub struct $s:ident => $color:expr;)*) => {
$(
$(#[$attrs])*
pub struct $s<T>(pub T);
impl<T: fmt::Display> fmt::Display for Red<T> { impl<T: fmt::Display> fmt::Display for $s<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "\x1b[31m{}\x1b[0m", self.0) write!(f, "\x1b[{}m{}\x1b[0m", $color, self.0)
}
}
impl<T: fmt::Debug> fmt::Debug for $s<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "\x1b[{}m{:?}\x1b[0m", $color, self.0)
}
}
)*
} }
} }
impl<T: fmt::Debug> fmt::Debug for Red<T> { define_colors! {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { /// Write a `Display` or `Debug` escaped with Red
write!(f, "\x1b[31m{:?}\x1b[0m", self.0) pub struct Red => "31";
}
/// Write a `Display` or `Debug` escaped with Yellow
pub struct Yellow => "33";
} }
} }