Move back-end selection to backend::Concrete instead of ::B

This commit is contained in:
nabijaczleweli 2016-10-10 02:16:35 +02:00
parent 79bb6ff415
commit 4c9c4b5568
No known key found for this signature in database
GPG Key ID: BCFD0B018D2658F1
6 changed files with 23 additions and 39 deletions

View File

@ -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) {

View File

@ -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),

View File

@ -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(),
};

View File

@ -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<Box<Fn(&mut Cursive) + Send>>,
cb_sink: mpsc::Sender<Box<Fn(&mut Cursive) + Send>>,
@ -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);

View File

@ -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<Cell<bool>>,
/// 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<T: Into<Vec2>>(size: T, theme: Theme, backend: &'a B) -> Self {
pub fn new<T: Into<Vec2>>(size: T, theme: Theme, backend: &'a backend::Concrete) -> Self {
Printer {
offset: Vec2::zero(),
size: size.into(),

View File

@ -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,