From 4c9c4b556820176863632d07820bda2e89411e0d Mon Sep 17 00:00:00 2001 From: nabijaczleweli Date: Mon, 10 Oct 2016 02:16:35 +0200 Subject: [PATCH] Move back-end selection to backend::Concrete instead of ::B --- src/backend/curses/n.rs | 9 +++++---- src/backend/curses/pan.rs | 11 ++++++----- src/backend/termion.rs | 9 +++++---- src/lib.rs | 20 ++------------------ src/printer.rs | 7 +++---- src/theme.rs | 6 ++---- 6 files changed, 23 insertions(+), 39 deletions(-) diff --git a/src/backend/curses/n.rs b/src/backend/curses/n.rs index e46dd3b..0735a7e 100644 --- a/src/backend/curses/n.rs +++ b/src/backend/curses/n.rs @@ -1,13 +1,14 @@ +extern crate ncurses; + use backend; use event::{Event, Key}; -use ncurses; use theme::{BaseColor, Color, ColorStyle, Effect}; use utf8; -pub struct NcursesBackend; +pub struct Concrete; -impl backend::Backend for NcursesBackend { +impl backend::Backend for Concrete { fn init() -> Self { ::std::env::set_var("ESCDELAY", "25"); ncurses::setlocale(ncurses::LcCategory::all, ""); @@ -20,7 +21,7 @@ impl backend::Backend for NcursesBackend { ncurses::wbkgd(unsafe { ncurses::stdscr() }, ncurses::COLOR_PAIR(ColorStyle::Background.id())); - NcursesBackend + Concrete } fn screen_size(&self) -> (usize, usize) { diff --git a/src/backend/curses/pan.rs b/src/backend/curses/pan.rs index 1811c9b..fa5106d 100644 --- a/src/backend/curses/pan.rs +++ b/src/backend/curses/pan.rs @@ -1,16 +1,17 @@ +extern crate pancurses; + use backend; use event::{Event, Key}; -use pancurses; use self::super::find_closest; use theme::{BaseColor, Color, ColorStyle, Effect}; use utf8; -pub struct PancursesBackend { +pub struct Concrete { window: pancurses::Window, } -impl backend::Backend for PancursesBackend { +impl backend::Backend for Concrete { fn init() -> Self { ::std::env::set_var("ESCDELAY", "25"); let window = pancurses::initscr(); @@ -21,7 +22,7 @@ impl backend::Backend for PancursesBackend { pancurses::curs_set(0); window.bkgd(pancurses::COLOR_PAIR(ColorStyle::Background.id() as u64)); - PancursesBackend { window: window } + Concrete { window: window } } fn screen_size(&self) -> (usize, usize) { @@ -89,7 +90,7 @@ impl backend::Backend for PancursesBackend { pancurses::Input::Unknown(i) => Event::Unknown(i), // TODO: I honestly have no fucking idea what KeyCodeYes is pancurses::Input::KeyCodeYes => Event::Refresh, - pancurses::Input::KeyBreak => Event::Key(PauseBreak), + pancurses::Input::KeyBreak => Event::Key(Key::PauseBreak), pancurses::Input::KeyDown => Event::Key(Key::Down), pancurses::Input::KeyUp => Event::Key(Key::Up), pancurses::Input::KeyLeft => Event::Key(Key::Left), diff --git a/src/backend/termion.rs b/src/backend/termion.rs index d3b25b4..19c44ca 100644 --- a/src/backend/termion.rs +++ b/src/backend/termion.rs @@ -1,20 +1,21 @@ +extern crate termion; + use ::backend; use ::event::{Event, Key}; use std::io::Write; -use termion; use termion::input::TermRead; use termion::raw::IntoRawMode; use ::theme::{BaseColor, Color, ColorStyle, Effect}; -pub struct TermionBackend { +pub struct Concrete { terminal: termion::raw::RawTerminal<::std::io::Stdout>, } -impl backend::Backend for TermionBackend { +impl backend::Backend for Concrete { fn init() -> Self { print!("{}", termion::cursor::Hide); - let backend = TermionBackend { + let backend = Concrete { terminal: ::std::io::stdout().into_raw_mode().unwrap(), }; diff --git a/src/lib.rs b/src/lib.rs index 439d314..a1a5639 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -56,12 +56,6 @@ //! and log to it instead of stdout. #![deny(missing_docs)] -#[cfg(feature = "ncurses")] -extern crate ncurses; -#[cfg(feature = "pancurses")] -extern crate pancurses; -#[cfg(feature = "termion")] -extern crate termion; extern crate toml; extern crate unicode_segmentation; extern crate unicode_width; @@ -149,7 +143,7 @@ pub struct Cursive { running: bool, - backend: B, + backend: backend::Concrete, cb_source: mpsc::Receiver>, cb_sink: mpsc::Sender>, @@ -157,21 +151,11 @@ pub struct Cursive { new_default!(Cursive); -#[doc(hidden)] -#[cfg(feature = "ncurses")] -pub type B = backend::NcursesBackend; -#[doc(hidden)] -#[cfg(feature = "pancurses")] -pub type B = backend::PancursesBackend; -#[doc(hidden)] -#[cfg(feature = "termion")] -pub type B = backend::TermionBackend; - impl Cursive { /// Creates a new Cursive root, and initialize the back-end. pub fn new() -> Self { // Default delay is way too long. 25 is imperceptible yet works fine. - let mut backend = B::init(); + let mut backend = backend::Concrete::init(); let theme = theme::load_default(); theme.activate(&mut backend); diff --git a/src/printer.rs b/src/printer.rs index 09736e0..5c4e728 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -1,8 +1,7 @@ //! Makes drawing on ncurses windows easier. -use B; -use backend::Backend; +use backend::{self, Backend}; use std::cell::Cell; use std::cmp::min; use std::rc::Rc; @@ -27,7 +26,7 @@ pub struct Printer<'a> { /// `true` if nothing has been drawn yet. new: Rc>, /// Backend used to actually draw things - backend: &'a B, + backend: &'a backend::Concrete, } impl<'a> Printer<'a> { @@ -35,7 +34,7 @@ impl<'a> Printer<'a> { /// /// But nobody needs to know that. #[doc(hidden)] - pub fn new>(size: T, theme: Theme, backend: &'a B) -> Self { + pub fn new>(size: T, theme: Theme, backend: &'a backend::Concrete) -> Self { Printer { offset: Vec2::zero(), size: size.into(), diff --git a/src/theme.rs b/src/theme.rs index b15624b..49bdd43 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -115,9 +115,7 @@ //! ``` -use B; - -use backend::Backend; +use backend::{self, Backend}; use std::fs::File; use std::io; use std::io::Read; @@ -230,7 +228,7 @@ impl Theme { /// **Don't use this directly.** Uses [`Cursive::set_theme`] instead. /// /// [`Cursive::set_theme`]: ../struct.Cursive.html#method.set_theme - pub fn activate(&self, backend: &mut B) { + pub fn activate(&self, backend: &mut backend::Concrete) { // Initialize each color with the backend backend.init_color_style(ColorStyle::Background, &self.colors.view,