69 lines
1.6 KiB
Rust
69 lines
1.6 KiB
Rust
//! Cursor.
|
|
|
|
use std::fmt;
|
|
|
|
derive_csi_sequence!("Hide the cursor.", Hide, "?25l");
|
|
derive_csi_sequence!("Show the cursor.", Show, "?25h");
|
|
|
|
/// Goto some position ((1,1)-based).
|
|
///
|
|
/// # Why one-based?
|
|
///
|
|
/// ANSI escapes are very poorly designed, and one of the many odd aspects is being one-based. This
|
|
/// can be quite strange at first, but it is not that big of an obstruction once you get used to
|
|
/// it.
|
|
#[derive(Copy, Clone, PartialEq, Eq)]
|
|
pub struct Goto(pub u16, pub u16);
|
|
|
|
impl Default for Goto {
|
|
fn default() -> Goto { Goto(1, 1) }
|
|
}
|
|
|
|
impl fmt::Display for Goto {
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
debug_assert!(self != &Goto(0, 0), "Goto is one-based.");
|
|
|
|
write!(f, csi!("{};{}H"), self.0, self.1)
|
|
}
|
|
}
|
|
|
|
/// Move cursor left.
|
|
#[derive(Copy, Clone, PartialEq, Eq)]
|
|
pub struct Left(pub u16);
|
|
|
|
impl fmt::Display for Left {
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
write!(f, csi!("{}D"), self.0)
|
|
}
|
|
}
|
|
|
|
/// Move cursor right.
|
|
#[derive(Copy, Clone, PartialEq, Eq)]
|
|
pub struct Right(pub u16);
|
|
|
|
impl fmt::Display for Right {
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
write!(f, csi!("{}C"), self.0)
|
|
}
|
|
}
|
|
|
|
/// Move cursor up.
|
|
#[derive(Copy, Clone, PartialEq, Eq)]
|
|
pub struct Up(pub u16);
|
|
|
|
impl fmt::Display for Up {
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
write!(f, csi!("{}A"), self.0)
|
|
}
|
|
}
|
|
|
|
/// Move cursor down.
|
|
#[derive(Copy, Clone, PartialEq, Eq)]
|
|
pub struct Down(pub u16);
|
|
|
|
impl fmt::Display for Down {
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
write!(f, csi!("{}B"), self.0)
|
|
}
|
|
}
|