Remember current color style in pancurses backend

This commit is contained in:
Alexandre Bury 2016-10-12 14:14:32 -07:00
parent ad4da8acc1
commit 7e382593a8

View File

@ -1,14 +1,17 @@
extern crate pancurses; extern crate pancurses;
use backend; use backend;
use event::{Event, Key}; use event::{Event, Key};
use self::super::find_closest; use self::super::find_closest;
use std::cell::Cell;
use theme::{Color, ColorStyle, Effect}; use theme::{Color, ColorStyle, Effect};
use utf8; use utf8;
pub struct Concrete { pub struct Concrete {
window: pancurses::Window, window: pancurses::Window,
current_style: Cell<ColorStyle>,
} }
impl backend::Backend for Concrete { impl backend::Backend for Concrete {
@ -22,7 +25,10 @@ impl backend::Backend for Concrete {
pancurses::curs_set(0); pancurses::curs_set(0);
window.bkgd(pancurses::COLOR_PAIR(ColorStyle::Background.id() as u64)); window.bkgd(pancurses::COLOR_PAIR(ColorStyle::Background.id() as u64));
Concrete { window: window } Concrete {
window: window,
current_style: Cell::new(ColorStyle::Background),
}
} }
fn screen_size(&self) -> (usize, usize) { fn screen_size(&self) -> (usize, usize) {
@ -50,12 +56,17 @@ impl backend::Backend for Concrete {
// let mut current_style: pancurses::attr_t = 0; // let mut current_style: pancurses::attr_t = 0;
// let mut current_color: i16 = 0; // let mut current_color: i16 = 0;
// pancurses::attr_get(&mut current_style, &mut current_color); // pancurses::attr_get(&mut current_style, &mut current_color);
let current_style = self.current_style.get();
let style = pancurses::COLOR_PAIR(color.id() as u64); let style = pancurses::COLOR_PAIR(color.id() as u64);
self.window.attron(style); self.window.attron(style);
self.current_style.set(color);
f(); f();
self.window.attroff(style); self.current_style.set(current_style);
// pancurses::attron(current_style);
// self.window.attroff(style);
self.window.attron(pancurses::COLOR_PAIR(current_style.id() as u64));
} }
fn with_effect<F: FnOnce()>(&self, effect: Effect, f: F) { fn with_effect<F: FnOnce()>(&self, effect: Effect, f: F) {