mod common;
#[cfg_attr(all(unix, feature = "sys"), path = "nix/mod.rs")]
#[cfg_attr(all(windows, feature = "sys"), path = "win/mod.rs")]
mod inner;
pub use common::*;
pub use inner::*;
use crate::prelude::Point;
pub trait Control {
#[must_use("Resets on drop")]
fn enable_raw_mode(&self) -> std::io::Result<()>;
fn get_size(&self) -> std::io::Result<Point>;
fn is_tty(&self) -> bool;
fn is_raw(&self) -> bool;
fn is_ansi(&self) -> bool;
fn output(&self) -> &ControlOut;
fn input(&self) -> &ControlIn;
fn clone(&self) -> Self
where
Self: Sized;
#[cfg(all(windows, feature = "sys"))]
fn get_initial_style(&self) -> u16;
#[cfg(all(windows, feature = "sys"))]
fn use_alternate_screen(&self, alternate: bool) -> std::io::Result<()>;
}
impl<T> Control for &T
where
T: Control,
T: ?Sized,
{
fn enable_raw_mode(&self) -> std::io::Result<()> {
T::enable_raw_mode(self)
}
fn get_size(&self) -> std::io::Result<Point> {
T::get_size(self)
}
fn is_tty(&self) -> bool {
T::is_tty(self)
}
fn is_raw(&self) -> bool {
T::is_raw(self)
}
fn is_ansi(&self) -> bool {
T::is_ansi(self)
}
fn output(&self) -> &ControlOut {
T::output(self)
}
fn input(&self) -> &ControlIn {
T::input(self)
}
fn clone(&self) -> Self
where
Self: Sized,
{
self
}
#[cfg(all(windows, feature = "sys"))]
fn get_initial_style(&self) -> u16 {
T::get_initial_style(self)
}
#[cfg(all(windows, feature = "sys"))]
fn use_alternate_screen(&self, alternate: bool) -> std::io::Result<()> {
T::use_alternate_screen(self, alternate)
}
}