pub mod test;
#[cfg(feature = "crossterm")]
pub mod crossterm_backend;
use crate::core::cell::Cell;
use crate::core::rect::{Position, Size};
use crate::core::style::{Color, Modifier};
use std::io;
pub trait Backend {
fn draw<'a, I>(&mut self, content: I) -> io::Result<()>
where
I: Iterator<Item = (u16, u16, &'a Cell)>;
fn hide_cursor(&mut self) -> io::Result<()>;
fn show_cursor(&mut self) -> io::Result<()>;
fn set_cursor_position(&mut self, position: Position) -> io::Result<()>;
fn get_cursor_position(&mut self) -> io::Result<Position>;
fn clear(&mut self) -> io::Result<()>;
fn size(&self) -> io::Result<Size>;
fn flush(&mut self) -> io::Result<()>;
fn enable_mouse_capture(&mut self) -> io::Result<()>;
fn disable_mouse_capture(&mut self) -> io::Result<()>;
fn enter_alternate_screen(&mut self) -> io::Result<()>;
fn leave_alternate_screen(&mut self) -> io::Result<()>;
fn enable_raw_mode(&mut self) -> io::Result<()>;
fn disable_raw_mode(&mut self) -> io::Result<()>;
fn enable_bracketed_paste(&mut self) -> io::Result<()> {
Ok(())
}
fn disable_bracketed_paste(&mut self) -> io::Result<()> {
Ok(())
}
fn begin_sync(&mut self) -> io::Result<()> {
Ok(())
}
fn end_sync(&mut self) -> io::Result<()> {
Ok(())
}
}
#[cfg(feature = "crossterm")]
pub(crate) fn to_crossterm_color(color: Color) -> crossterm::style::Color {
match color {
Color::Reset => crossterm::style::Color::Reset,
Color::Black => crossterm::style::Color::Black,
Color::Red => crossterm::style::Color::DarkRed,
Color::Green => crossterm::style::Color::DarkGreen,
Color::Yellow => crossterm::style::Color::DarkYellow,
Color::Blue => crossterm::style::Color::DarkBlue,
Color::Magenta => crossterm::style::Color::DarkMagenta,
Color::Cyan => crossterm::style::Color::DarkCyan,
Color::Gray => crossterm::style::Color::Grey,
Color::DarkGray => crossterm::style::Color::DarkGrey,
Color::LightRed => crossterm::style::Color::Red,
Color::LightGreen => crossterm::style::Color::Green,
Color::LightYellow => crossterm::style::Color::Yellow,
Color::LightBlue => crossterm::style::Color::Blue,
Color::LightMagenta => crossterm::style::Color::Magenta,
Color::LightCyan => crossterm::style::Color::Cyan,
Color::White => crossterm::style::Color::White,
Color::Indexed(i) => crossterm::style::Color::AnsiValue(i),
Color::Rgb(r, g, b) => crossterm::style::Color::Rgb { r, g, b },
}
}
#[cfg(feature = "crossterm")]
pub(crate) fn to_crossterm_attributes(modifier: Modifier) -> Vec<crossterm::style::Attribute> {
use crossterm::style::Attribute;
let mut attrs = Vec::new();
if modifier.contains(Modifier::BOLD) {
attrs.push(Attribute::Bold);
}
if modifier.contains(Modifier::DIM) {
attrs.push(Attribute::Dim);
}
if modifier.contains(Modifier::ITALIC) {
attrs.push(Attribute::Italic);
}
if modifier.contains(Modifier::UNDERLINED) {
attrs.push(Attribute::Underlined);
}
if modifier.contains(Modifier::SLOW_BLINK) {
attrs.push(Attribute::SlowBlink);
}
if modifier.contains(Modifier::RAPID_BLINK) {
attrs.push(Attribute::RapidBlink);
}
if modifier.contains(Modifier::REVERSED) {
attrs.push(Attribute::Reverse);
}
if modifier.contains(Modifier::HIDDEN) {
attrs.push(Attribute::Hidden);
}
if modifier.contains(Modifier::CROSSED_OUT) {
attrs.push(Attribute::CrossedOut);
}
if modifier.contains(Modifier::OVERLINED) {
attrs.push(Attribute::OverLined);
}
attrs
}