use std::io::Write;
use crate::Command;
#[derive(Debug, Clone, Copy)]
pub struct Hide;
impl Command for Hide {
fn write_ansi(&self, w: &mut impl Write) -> std::io::Result<()> {
w.write_all(b"\x1b[?25l")
}
}
#[derive(Debug, Clone, Copy)]
pub struct Show;
impl Command for Show {
fn write_ansi(&self, w: &mut impl Write) -> std::io::Result<()> {
w.write_all(b"\x1b[?25h")
}
}
#[derive(Debug, Clone, Copy)]
pub struct MoveTo(pub u16, pub u16);
impl Command for MoveTo {
fn write_ansi(&self, w: &mut impl Write) -> std::io::Result<()> {
write!(w, "\x1b[{};{}H", self.1 + 1, self.0 + 1)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum SetCursorStyle {
DefaultUserShape,
BlinkingBlock,
SteadyBlock,
BlinkingUnderScore,
SteadyUnderScore,
BlinkingBar,
SteadyBar,
}
impl Command for SetCursorStyle {
fn write_ansi(&self, w: &mut impl Write) -> std::io::Result<()> {
let n = match self {
SetCursorStyle::DefaultUserShape => 0,
SetCursorStyle::BlinkingBlock => 1,
SetCursorStyle::SteadyBlock => 2,
SetCursorStyle::BlinkingUnderScore => 3,
SetCursorStyle::SteadyUnderScore => 4,
SetCursorStyle::BlinkingBar => 5,
SetCursorStyle::SteadyBar => 6,
};
write!(w, "\x1b[{n} q")
}
}