From ad7606ca5571f229411b5726276e4bf8dda419e5 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Sat, 8 Oct 2016 17:11:17 -0700 Subject: [PATCH] Switch backend with cargo features Use `termion` feature and disable default features to use the termion backend. --- Cargo.toml | 6 +++++- src/backend/mod.rs | 9 ++++----- src/lib.rs | 12 ++++++++++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3cd2d73..0775cc4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] diff --git a/src/backend/mod.rs b/src/backend/mod.rs index 10a892e..6c53cb0 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -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; diff --git a/src/lib.rs b/src/lib.rs index 398396b..a2d5a32 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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.