Back to upstream termion

Just figured I could implement Color for a custom wrapper struct.
This commit is contained in:
Alexandre Bury 2016-10-27 20:35:34 -07:00
parent 949b1e9632
commit ce009d0e5f
2 changed files with 19 additions and 3 deletions

View File

@ -33,8 +33,7 @@ version = "0.6"
[dependencies.termion]
optional = true
# version = "1.1.1"
git = "https://github.com/gyscos/termion"
version = "1.1.1"
[dependencies.bear-lib-terminal]
optional = true

View File

@ -10,6 +10,7 @@ use self::termion::raw::IntoRawMode;
use std::cell::Cell;
use std::collections::BTreeMap;
use std::io::Write;
use std::fmt;
use ::theme;
@ -24,6 +25,22 @@ trait Effectable {
fn off(&self);
}
struct ColorRef<'a>(&'a color::Color);
impl <'a> color::Color for ColorRef<'a> {
#[inline]
fn write_fg(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.write_fg(f)
}
#[inline]
fn write_bg(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.write_bg(f)
}
}
impl Effectable for theme::Effect {
fn on(&self) {
match *self {
@ -41,7 +58,7 @@ impl Effectable for theme::Effect {
}
fn apply_colors(fg: &color::Color, bg: &color::Color) {
print!("{}{}", color::Fg(fg), color::Bg(bg));
print!("{}{}", color::Fg(ColorRef(fg)), color::Bg(ColorRef(bg)));
}
impl Concrete {