Support drawing bold test with bright colors

This feature is on by default
This commit is contained in:
Joe Wilm 2016-10-28 09:19:48 -07:00
parent 7cd8a6ca12
commit a81152cc43
5 changed files with 51 additions and 6 deletions

View File

@ -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,

View File

@ -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 {

View File

@ -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) {

View File

@ -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

View File

@ -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(),