diff options
author | Joe Wilm <joe@jwilm.com> | 2016-10-28 09:19:48 -0700 |
---|---|---|
committer | Joe Wilm <joe@jwilm.com> | 2016-10-28 09:19:48 -0700 |
commit | a81152cc43c12f4232be29798b85ba41fd9482cb (patch) | |
tree | 86cb6102af19daaa96b3cbfb1a3ef20af0374f0e | |
parent | 7cd8a6ca12cd37ae354084c7246060219b1e3af8 (diff) | |
download | r-alacritty-a81152cc43c12f4232be29798b85ba41fd9482cb.tar.gz r-alacritty-a81152cc43c12f4232be29798b85ba41fd9482cb.tar.bz2 r-alacritty-a81152cc43c12f4232be29798b85ba41fd9482cb.zip |
Support drawing bold test with bright colors
This feature is on by default
-rw-r--r-- | src/ansi.rs | 2 | ||||
-rw-r--r-- | src/config.rs | 28 | ||||
-rw-r--r-- | src/main.rs | 1 | ||||
-rw-r--r-- | src/renderer/mod.rs | 22 | ||||
-rw-r--r-- | src/term.rs | 4 |
5 files changed, 51 insertions, 6 deletions
diff --git a/src/ansi.rs b/src/ansi.rs index c419d7e5..f6d5de37 100644 --- a/src/ansi.rs +++ b/src/ansi.rs @@ -303,7 +303,7 @@ pub enum TabulationClearMode { /// /// The order here matters since the enum should be castable to a `usize` for /// indexing a color list. -#[derive(Debug, Copy, Clone, Eq, PartialEq)] +#[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd, Ord)] pub enum Color { /// Black Black = 0, diff --git a/src/config.rs b/src/config.rs index f3e68dca..cd6880d7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -15,8 +15,13 @@ use serde_yaml; use serde::{self, Error as SerdeError}; use notify::{Watcher as WatcherApi, RecommendedWatcher as FileWatcher, op}; +/// Function that returns true for serde default +fn true_bool() -> bool { + true +} + /// Top-level config type -#[derive(Debug, Deserialize, Default)] +#[derive(Debug, Deserialize)] pub struct Config { /// Pixels per inch #[serde(default)] @@ -30,11 +35,27 @@ pub struct Config { #[serde(default)] render_timer: bool, + /// Should show render timer + #[serde(default="true_bool")] + draw_bold_text_with_bright_colors: bool, + /// The standard ANSI colors to use #[serde(default)] colors: Colors, } +impl Default for Config { + fn default() -> Config { + Config { + draw_bold_text_with_bright_colors: true, + dpi: Default::default(), + font: Default::default(), + render_timer: Default::default(), + colors: Default::default(), + } + } +} + /// Errors occurring during config loading #[derive(Debug)] pub enum Error { @@ -301,6 +322,11 @@ impl Config { self.colors.primary.background } + #[inline] + pub fn draw_bold_text_with_bright_colors(&self) -> bool { + self.draw_bold_text_with_bright_colors + } + /// Get font config #[inline] pub fn font(&self) -> &Font { diff --git a/src/main.rs b/src/main.rs index b8bc5d07..9a4a2cb6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -270,6 +270,7 @@ struct ConfigHandler { window: ::glutin::WindowProxy, } +// TODO FIXME impl config::OnConfigReload for ConfigHandler { fn on_config_reload(&mut self, config: Config) { if let Err(..) = self.tx.send(config) { diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index 4e23c0ed..018f541c 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -242,6 +242,7 @@ pub struct QuadRenderer { active_tex: GLuint, batch: Batch, colors: [Rgb; 18], + draw_bold_text_with_bright_colors: bool, rx: mpsc::Receiver<Msg>, } @@ -271,15 +272,17 @@ pub struct Batch { tex: GLuint, instances: Vec<InstanceData>, colors: [Rgb; 18], + draw_bold_text_with_bright_colors: bool, } impl Batch { #[inline] - pub fn new(colors: [Rgb; 18]) -> Batch { + pub fn new(config: &Config) -> Batch { Batch { tex: 0, instances: Vec::with_capacity(BATCH_MAX), - colors: colors, + colors: config.color_list(), + draw_bold_text_with_bright_colors: config.draw_bold_text_with_bright_colors(), } } @@ -290,7 +293,16 @@ impl Batch { let fg = match cell.fg { ::term::cell::Color::Rgb(rgb) => rgb, - ::term::cell::Color::Ansi(ansi) => self.colors[ansi as usize], + ::term::cell::Color::Ansi(ansi) => { + if self.draw_bold_text_with_bright_colors + && cell.bold() + && ansi < ::ansi::Color::BrightBlack + { + self.colors[ansi as usize + 8] + } else { + self.colors[ansi as usize] + } + } }; let bg = match cell.bg { @@ -512,9 +524,10 @@ impl QuadRenderer { vbo_instance: vbo_instance, atlas: Vec::new(), active_tex: 0, - batch: Batch::new(config.color_list()), + batch: Batch::new(config), colors: config.color_list(), rx: msg_rx, + draw_bold_text_with_bright_colors: config.draw_bold_text_with_bright_colors(), }; let atlas = Atlas::new(ATLAS_SIZE); @@ -526,6 +539,7 @@ impl QuadRenderer { pub fn update_config(&mut self, config: &Config) { self.colors = config.color_list(); self.batch.colors = config.color_list(); + self.batch.draw_bold_text_with_bright_colors = config.draw_bold_text_with_bright_colors(); } pub fn with_api<F, T>(&mut self, props: &term::SizeInfo, func: F) -> T diff --git a/src/term.rs b/src/term.rs index bcd78814..3fe6bdcf 100644 --- a/src/term.rs +++ b/src/term.rs @@ -103,6 +103,10 @@ pub mod cell { } impl Cell { + pub fn bold(&self) -> bool { + self.flags.contains(BOLD) + } + pub fn new(c: char, fg: Color, bg: Color) -> Cell { Cell { c: c.into(), |