mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Merge pull request #110 from ihalila/pancurses_0.8
Correct colors on pancurses+Windows and use strongly typed attributes
This commit is contained in:
commit
8dc420c3ed
@ -43,7 +43,7 @@ version = "5.85.0"
|
|||||||
[dependencies.pancurses]
|
[dependencies.pancurses]
|
||||||
features = ["wide"]
|
features = ["wide"]
|
||||||
optional = true
|
optional = true
|
||||||
version = "0.7"
|
version = "0.8"
|
||||||
|
|
||||||
[dependencies.termion]
|
[dependencies.termion]
|
||||||
optional = true
|
optional = true
|
||||||
|
@ -5,13 +5,11 @@ 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 {
|
||||||
@ -23,11 +21,10 @@ impl backend::Backend for Concrete {
|
|||||||
pancurses::cbreak();
|
pancurses::cbreak();
|
||||||
pancurses::start_color();
|
pancurses::start_color();
|
||||||
pancurses::curs_set(0);
|
pancurses::curs_set(0);
|
||||||
window.bkgd(pancurses::COLOR_PAIR(ColorStyle::Background.id() as pancurses::chtype));
|
window.bkgd(pancurses::ColorPair(ColorStyle::Background.id() as u8));
|
||||||
|
|
||||||
Concrete {
|
Concrete {
|
||||||
window: window,
|
window: window,
|
||||||
current_style: Cell::new(ColorStyle::Background),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,28 +49,18 @@ impl backend::Backend for Concrete {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn with_color<F: FnOnce()>(&self, color: ColorStyle, f: F) {
|
fn with_color<F: FnOnce()>(&self, color: ColorStyle, f: F) {
|
||||||
// TODO: pancurses doesn't have an `attr_get` equivalent
|
let (_, current_color_pair) = self.window.attrget();
|
||||||
// let mut current_style: pancurses::attr_t = 0;
|
let color_attribute = pancurses::ColorPair(color.id() as u8);
|
||||||
// let mut current_color: i16 = 0;
|
|
||||||
// pancurses::attr_get(&mut current_style, &mut current_color);
|
|
||||||
let current_style = self.current_style.get();
|
|
||||||
|
|
||||||
let style = pancurses::COLOR_PAIR(color.id() as pancurses::chtype);
|
self.window.attron(color_attribute);
|
||||||
self.window.attron(style);
|
|
||||||
|
|
||||||
self.current_style.set(color);
|
|
||||||
f();
|
f();
|
||||||
self.current_style.set(current_style);
|
self.window.attron(pancurses::ColorPair(current_color_pair as u8));
|
||||||
|
|
||||||
// self.window.attroff(style);
|
|
||||||
self.window.attron(pancurses::COLOR_PAIR(current_style.id() as pancurses::chtype));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_effect<F: FnOnce()>(&self, effect: Effect, f: F) {
|
fn with_effect<F: FnOnce()>(&self, effect: Effect, f: F) {
|
||||||
let style = match effect {
|
let style = match effect {
|
||||||
// A_REVERSE, taken from ncurses
|
Effect::Reverse => pancurses::Attribute::Reverse,
|
||||||
Effect::Reverse => 1 << (10 + 8u32),
|
Effect::Simple => pancurses::Attribute::Normal,
|
||||||
Effect::Simple => pancurses::A_NORMAL,
|
|
||||||
};
|
};
|
||||||
self.window.attron(style);
|
self.window.attron(style);
|
||||||
f();
|
f();
|
||||||
|
Loading…
Reference in New Issue
Block a user