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