Crossterm: define platform-dependant Stdout type

This commit is contained in:
Alexandre Bury 2020-01-06 11:25:32 -08:00
parent f1fe477e6d
commit 237c6c8e33

View File

@ -7,7 +7,7 @@
use std::{ use std::{
cell::{Cell, RefCell, RefMut}, cell::{Cell, RefCell, RefMut},
fs::File, fs::File,
io::{self, BufWriter, Stdout, Write}, io::{self, BufWriter, Write},
time::Duration, time::Duration,
}; };
@ -36,15 +36,18 @@ use crate::{
vec::Vec2, vec::Vec2,
}; };
#[cfg(windows)]
type Stdout = io::Stdout;
#[cfg(unix)]
type Stdout = File;
/// Backend using crossterm /// Backend using crossterm
pub struct Backend { pub struct Backend {
current_style: Cell<theme::ColorPair>, current_style: Cell<theme::ColorPair>,
last_button: Option<MouseButton>, last_button: Option<MouseButton>,
#[cfg(windows)]
stdout: RefCell<BufWriter<Stdout>>, stdout: RefCell<BufWriter<Stdout>>,
#[cfg(unix)]
stdout: RefCell<BufWriter<File>>,
} }
impl From<CMouseButton> for MouseButton { impl From<CMouseButton> for MouseButton {
@ -234,12 +237,6 @@ impl Backend {
.unwrap(); .unwrap();
} }
#[cfg(unix)]
fn stdout_mut(&self) -> RefMut<BufWriter<File>> {
self.stdout.borrow_mut()
}
#[cfg(windows)]
fn stdout_mut(&self) -> RefMut<BufWriter<Stdout>> { fn stdout_mut(&self) -> RefMut<BufWriter<Stdout>> {
self.stdout.borrow_mut() self.stdout.borrow_mut()
} }