Switch backend with cargo features

Use `termion` feature and disable default features to use the termion
backend.
This commit is contained in:
Alexandre Bury 2016-10-08 17:11:17 -07:00
parent df4397a174
commit ad7606ca55
3 changed files with 19 additions and 8 deletions

View File

@ -16,7 +16,7 @@ skeptic = "0.6"
[dependencies]
odds = "0.2"
termion = "1.1.1"
termion = {version="1.1.1", optional=true}
toml = "0.2"
unicode-segmentation = "0.1"
unicode-width = "0.1"
@ -24,6 +24,7 @@ unicode-width = "0.1"
[dependencies.ncurses]
features = ["wide"]
version = "5.82.0"
optional=true
[dev-dependencies]
rand = "0.3"
@ -31,3 +32,6 @@ skeptic = "0.6"
[lib]
name = "cursive"
[features]
default = ["ncurses"]

View File

@ -2,11 +2,10 @@ use event;
use theme;
// Module is not named `ncurses` to avoir naming conflict
mod curses;
mod termion;
pub use self::curses::NcursesBackend;
pub use self::termion::TermionBackend;
#[cfg(feature = "ncurses")]
pub mod curses;
#[cfg(feature = "termion")]
pub mod termion;
pub trait Backend {
fn init() -> Self;

View File

@ -56,12 +56,15 @@
//! and log to it instead of stdout.
#![deny(missing_docs)]
#[cfg(feature = "ncurses")]
extern crate ncurses;
#[cfg(feature = "termion")]
extern crate termion;
extern crate toml;
extern crate unicode_segmentation;
extern crate unicode_width;
extern crate odds;
extern crate termion;
macro_rules! println_stderr(
($($arg:tt)*) => { {
@ -155,8 +158,13 @@ new_default!(Cursive);
// Use the Ncurses backend.
// TODO: make this feature-driven
#[cfg(feature = "termion")]
#[doc(hidden)]
pub type B = backend::TermionBackend;
pub type B = backend::termion::TermionBackend;
#[doc(hidden)]
#[cfg(feature = "ncurses")]
pub type B = backend::curses::NcursesBackend;
impl Cursive {
/// Creates a new Cursive root, and initialize ncurses.