mirror of
https://github.com/crossterm-rs/crossterm.git
synced 2025-09-28 13:31:23 +00:00
Make some commands 1-based and document that 0 is defaulted to 1.
This commit is contained in:
parent
46b1946938
commit
758d06af10
@ -55,7 +55,6 @@ pub(crate) mod sys;
|
||||
/// A command that moves the terminal cursor to the given position (column, row).
|
||||
///
|
||||
/// # Notes
|
||||
/// * This command is 0 based, meaning 0 is 1.
|
||||
/// * Top left cell is represented as `0,0`.
|
||||
/// * Commands must be executed/queued for execution otherwise they do nothing.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@ -76,7 +75,8 @@ impl Command for MoveTo {
|
||||
/// and moves it to the first column.
|
||||
///
|
||||
/// # Notes
|
||||
/// * This command is 0 based, meaning 0 is 1.
|
||||
/// * This command is 1 based, meaning `MoveToNextLine(1)` moves to the next line.
|
||||
/// * Most terminals default 0 argument to 1.
|
||||
/// * Commands must be executed/queued for execution otherwise they do nothing.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct MoveToNextLine(pub u16);
|
||||
@ -100,7 +100,8 @@ impl Command for MoveToNextLine {
|
||||
/// and moves it to the first column.
|
||||
///
|
||||
/// # Notes
|
||||
/// * This command is 0 based, meaning 0 is 1.
|
||||
/// * This command is 1 based, meaning `MoveToPreviousLine(1)` moves to the previous line.
|
||||
/// * Most terminals default 0 argument to 1.
|
||||
/// * Commands must be executed/queued for execution otherwise they do nothing.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct MoveToPreviousLine(pub u16);
|
||||
@ -123,7 +124,8 @@ impl Command for MoveToPreviousLine {
|
||||
/// A command that moves the terminal cursor to the given column on the current row.
|
||||
///
|
||||
/// # Notes
|
||||
/// * This command is 0 based, meaning 0 is 1.
|
||||
/// * This command is 0 based, meaning 0 is the leftmost column.
|
||||
/// * Most terminals default 0 argument to 1.
|
||||
/// * Commands must be executed/queued for execution otherwise they do nothing.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct MoveToColumn(pub u16);
|
||||
@ -143,7 +145,8 @@ impl Command for MoveToColumn {
|
||||
/// A command that moves the terminal cursor to the given row on the current column.
|
||||
///
|
||||
/// # Notes
|
||||
/// * This command is 0 based, meaning 0 is 1.
|
||||
/// * This command is 0 based, meaning 0 is the topmost row.
|
||||
/// * Most terminals default 0 argument to 1.
|
||||
/// * Commands must be executed/queued for execution otherwise they do nothing.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct MoveToRow(pub u16);
|
||||
@ -163,14 +166,15 @@ impl Command for MoveToRow {
|
||||
/// A command that moves the terminal cursor a given number of rows up.
|
||||
///
|
||||
/// # Notes
|
||||
/// * This command is 0 based, meaning 0 is 1.
|
||||
/// * This command is 1 based, meaning `MoveUp(1) moves the cursor up one cell.
|
||||
/// * Most terminals default 0 argument to 1.
|
||||
/// * Commands must be executed/queued for execution otherwise they do nothing.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct MoveUp(pub u16);
|
||||
|
||||
impl Command for MoveUp {
|
||||
fn write_ansi(&self, f: &mut impl fmt::Write) -> fmt::Result {
|
||||
write!(f, csi!("{}A"), self.0 + 1)?;
|
||||
write!(f, csi!("{}A"), self.0)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -183,7 +187,8 @@ impl Command for MoveUp {
|
||||
/// A command that moves the terminal cursor a given number of columns to the right.
|
||||
///
|
||||
/// # Notes
|
||||
/// * This command is 0 based, meaning 0 is 1.
|
||||
/// * This command is 1 based, meaning `MoveRight(1) moves the cursor right one cell.
|
||||
/// * Most terminals default 0 argument to 1.
|
||||
/// * Commands must be executed/queued for execution otherwise they do nothing.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct MoveRight(pub u16);
|
||||
@ -203,14 +208,15 @@ impl Command for MoveRight {
|
||||
/// A command that moves the terminal cursor a given number of rows down.
|
||||
///
|
||||
/// # Notes
|
||||
/// * This command is 0 based, meaning 0 is 1.
|
||||
/// * This command is 1 based, meaning `MoveDown(1) moves the cursor down one cell.
|
||||
/// * Most terminals default 0 argument to 1.
|
||||
/// * Commands must be executed/queued for execution otherwise they do nothing.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct MoveDown(pub u16);
|
||||
|
||||
impl Command for MoveDown {
|
||||
fn write_ansi(&self, f: &mut impl fmt::Write) -> fmt::Result {
|
||||
write!(f, csi!("{}B"), self.0 + 1)?;
|
||||
write!(f, csi!("{}B"), self.0)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -223,14 +229,15 @@ impl Command for MoveDown {
|
||||
/// A command that moves the terminal cursor a given number of columns to the left.
|
||||
///
|
||||
/// # Notes
|
||||
/// * This command is 0 based, meaning 0 is 1.
|
||||
/// * This command is 1 based, meaning `MoveLeft(1) moves the cursor left one cell.
|
||||
/// * Most terminals default 0 argument to 1.
|
||||
/// * Commands must be executed/queued for execution otherwise they do nothing.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct MoveLeft(pub u16);
|
||||
|
||||
impl Command for MoveLeft {
|
||||
fn write_ansi(&self, f: &mut impl fmt::Write) -> fmt::Result {
|
||||
write!(f, csi!("{}D"), self.0 + 1)?;
|
||||
write!(f, csi!("{}D"), self.0)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user