aboutsummaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2017-02-11 12:49:40 -0800
committerJoe Wilm <jwilm@users.noreply.github.com>2017-02-11 14:18:05 -0800
commit908ea5543a40b772d2336e2ce981aae61dc6b2d7 (patch)
tree65c265378a75e214a0bc05f74de8c50156cc8dee /src/config.rs
parentd2e8a0cd103a4923d296136ac499ce026fdd625a (diff)
downloadalacritty-908ea5543a40b772d2336e2ce981aae61dc6b2d7.tar.gz
alacritty-908ea5543a40b772d2336e2ce981aae61dc6b2d7.zip
Move color list to Term struct
The color list needs to be updated by the parser, and this isn't possible if it's on the config. This change makes sense semantically as well since it's really part of the terminal state. This is in preparation for OSC color parsing.
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs186
1 files changed, 16 insertions, 170 deletions
diff --git a/src/config.rs b/src/config.rs
index 6daa0eb1..fafb61c2 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -7,7 +7,6 @@ use std::borrow::Cow;
use std::{env, fmt};
use std::fs::{self, File};
use std::io::{self, Read, Write};
-use std::ops::{Index, IndexMut};
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::sync::mpsc;
@@ -24,8 +23,6 @@ use notify::{Watcher as WatcherApi, RecommendedWatcher as FileWatcher, op};
use input::{Action, Binding, MouseBinding, KeyBinding};
use index::{Line, Column};
-use ansi;
-
/// Function that returns true for serde default
fn true_bool() -> bool {
true
@@ -77,148 +74,6 @@ impl Default for Mouse {
}
}
-/// List of indexed colors
-///
-/// The first 16 entries are the standard ansi named colors. Items 16..232 are
-/// the color cube. Items 233..256 are the grayscale ramp. Finally, item 256 is
-/// the configured foreground color, item 257 is the configured background
-/// color, item 258 is the cursor foreground color, item 259 is the cursor
-//background color.
-pub struct ColorList([Rgb; 260]);
-
-impl fmt::Debug for ColorList {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- f.write_str("ColorList[..]")
- }
-}
-
-impl Default for ColorList {
- fn default() -> ColorList {
- ColorList::from(Colors::default())
- }
-}
-
-impl From<Colors> for ColorList {
- fn from(colors: Colors) -> ColorList {
- // Type inference fails without this annotation
- let mut list: ColorList = unsafe { ::std::mem::uninitialized() };
-
- list.fill_named(&colors);
- list.fill_cube();
- list.fill_gray_ramp();
-
- list
- }
-}
-
-impl ColorList {
- fn fill_named(&mut self, colors: &Colors) {
- // Normals
- self[ansi::NamedColor::Black] = colors.normal.black;
- self[ansi::NamedColor::Red] = colors.normal.red;
- self[ansi::NamedColor::Green] = colors.normal.green;
- self[ansi::NamedColor::Yellow] = colors.normal.yellow;
- self[ansi::NamedColor::Blue] = colors.normal.blue;
- self[ansi::NamedColor::Magenta] = colors.normal.magenta;
- self[ansi::NamedColor::Cyan] = colors.normal.cyan;
- self[ansi::NamedColor::White] = colors.normal.white;
-
- // Brights
- self[ansi::NamedColor::BrightBlack] = colors.bright.black;
- self[ansi::NamedColor::BrightRed] = colors.bright.red;
- self[ansi::NamedColor::BrightGreen] = colors.bright.green;
- self[ansi::NamedColor::BrightYellow] = colors.bright.yellow;
- self[ansi::NamedColor::BrightBlue] = colors.bright.blue;
- self[ansi::NamedColor::BrightMagenta] = colors.bright.magenta;
- self[ansi::NamedColor::BrightCyan] = colors.bright.cyan;
- self[ansi::NamedColor::BrightWhite] = colors.bright.white;
-
- // Foreground and background
- self[ansi::NamedColor::Foreground] = colors.primary.foreground;
- self[ansi::NamedColor::Background] = colors.primary.background;
-
- // Foreground and background for custom cursor colors
- self[ansi::NamedColor::CursorForeground] = colors.cursor.foreground;
- self[ansi::NamedColor::CursorBackground] = colors.cursor.background;
- }
-
- fn fill_cube(&mut self) {
- let mut index = 16;
- // Build colors
- for r in 0..6 {
- for g in 0..6 {
- for b in 0..6 {
- self[index] = Rgb {
- r: if r == 0 { 0 } else { r * 40 + 55 },
- b: if b == 0 { 0 } else { b * 40 + 55 },
- g: if g == 0 { 0 } else { g * 40 + 55 },
- };
- index += 1;
- }
- }
- }
-
- debug_assert!(index == 232);
- }
-
- fn fill_gray_ramp(&mut self) {
- let mut index = 232;
-
- for i in 0..24 {
- let value = i * 10 + 8;
- self[index] = Rgb {
- r: value,
- g: value,
- b: value
- };
- index += 1;
- }
-
- debug_assert!(index == 256);
- }
-}
-
-impl Index<ansi::NamedColor> for ColorList {
- type Output = Rgb;
-
- #[inline]
- fn index(&self, idx: ansi::NamedColor) -> &Self::Output {
- &self.0[idx as usize]
- }
-}
-
-impl IndexMut<ansi::NamedColor> for ColorList {
- #[inline]
- fn index_mut(&mut self, idx: ansi::NamedColor) -> &mut Self::Output {
- &mut self.0[idx as usize]
- }
-}
-
-impl Index<usize> for ColorList {
- type Output = Rgb;
-
- #[inline]
- fn index(&self, idx: usize) -> &Self::Output {
- &self.0[idx]
- }
-}
-
-impl Index<u8> for ColorList {
- type Output = Rgb;
-
- #[inline]
- fn index(&self, idx: u8) -> &Self::Output {
- &self.0[idx as usize]
- }
-}
-
-impl IndexMut<usize> for ColorList {
- #[inline]
- fn index_mut(&mut self, idx: usize) -> &mut Self::Output {
- &mut self.0[idx]
- }
-}
-
/// VisulBellAnimations are modeled after a subset of CSS transitions and Robert
/// Penner's Easing Functions.
#[derive(Clone, Copy, Debug, Deserialize)]
@@ -341,7 +196,7 @@ pub struct Config {
draw_bold_text_with_bright_colors: bool,
#[serde(default)]
- colors: ColorList,
+ colors: Colors,
/// Keybindings
#[serde(default="default_key_bindings")]
@@ -789,15 +644,6 @@ impl de::Deserialize for RawBinding {
}
}
-impl de::Deserialize for ColorList {
- fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
- where D: de::Deserializer
- {
- let named_colors = Colors::deserialize(deserializer)?;
- Ok(ColorList::from(named_colors))
- }
-}
-
impl de::Deserialize for MouseBinding {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where D: de::Deserializer
@@ -836,11 +682,11 @@ pub enum Error {
#[derive(Debug, Deserialize)]
pub struct Colors {
- primary: PrimaryColors,
+ pub primary: PrimaryColors,
#[serde(default="default_cursor_colors")]
- cursor: PrimaryColors,
- normal: AnsiColors,
- bright: AnsiColors,
+ pub cursor: PrimaryColors,
+ pub normal: AnsiColors,
+ pub bright: AnsiColors,
}
fn default_cursor_colors() -> PrimaryColors {
@@ -853,9 +699,9 @@ fn default_cursor_colors() -> PrimaryColors {
#[derive(Debug, Deserialize)]
pub struct PrimaryColors {
#[serde(deserialize_with = "rgb_from_hex")]
- background: Rgb,
+ pub background: Rgb,
#[serde(deserialize_with = "rgb_from_hex")]
- foreground: Rgb,
+ pub foreground: Rgb,
}
impl Default for Colors {
@@ -894,21 +740,21 @@ impl Default for Colors {
#[derive(Debug, Deserialize)]
pub struct AnsiColors {
#[serde(deserialize_with = "rgb_from_hex")]
- black: Rgb,
+ pub black: Rgb,
#[serde(deserialize_with = "rgb_from_hex")]
- red: Rgb,
+ pub red: Rgb,
#[serde(deserialize_with = "rgb_from_hex")]
- green: Rgb,
+ pub green: Rgb,
#[serde(deserialize_with = "rgb_from_hex")]
- yellow: Rgb,
+ pub yellow: Rgb,
#[serde(deserialize_with = "rgb_from_hex")]
- blue: Rgb,
+ pub blue: Rgb,
#[serde(deserialize_with = "rgb_from_hex")]
- magenta: Rgb,
+ pub magenta: Rgb,
#[serde(deserialize_with = "rgb_from_hex")]
- cyan: Rgb,
+ pub cyan: Rgb,
#[serde(deserialize_with = "rgb_from_hex")]
- white: Rgb,
+ pub white: Rgb,
}
/// Deserialize an Rgb from a hex string
@@ -1076,7 +922,7 @@ impl Config {
///
/// The ordering returned here is expected by the terminal. Colors are simply indexed in this
/// array for performance.
- pub fn color_list(&self) -> &ColorList {
+ pub fn colors(&self) -> &Colors {
&self.colors
}