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] [dependencies.termion]
optional = true optional = true
# version = "1.1.1" version = "1.1.1"
git = "https://github.com/gyscos/termion"
[dependencies.bear-lib-terminal] [dependencies.bear-lib-terminal]
optional = true optional = true

View File

@ -10,6 +10,7 @@ use self::termion::raw::IntoRawMode;
use std::cell::Cell; use std::cell::Cell;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::io::Write; use std::io::Write;
use std::fmt;
use ::theme; use ::theme;
@ -24,6 +25,22 @@ trait Effectable {
fn off(&self); 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 { impl Effectable for theme::Effect {
fn on(&self) { fn on(&self) {
match *self { match *self {
@ -41,7 +58,7 @@ impl Effectable for theme::Effect {
} }
fn apply_colors(fg: &color::Color, bg: &color::Color) { 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 { impl Concrete {