Make clear which mouse commands are 0-based and which are 1-based. (#684)
This commit is contained in:
parent
f523c110a6
commit
0a435e6cb9
@ -39,8 +39,8 @@ fn test_move_cursor_to_previous_line<W>(w: &mut W) -> Result<()>
|
|||||||
where
|
where
|
||||||
W: Write,
|
W: Write,
|
||||||
{
|
{
|
||||||
draw_cursor_box(w, "MoveToPreviousLine (2)", |_, _| {
|
draw_cursor_box(w, "MoveToPreviousLine (1)", |_, _| {
|
||||||
cursor::MoveToPreviousLine(2)
|
cursor::MoveToPreviousLine(1)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,15 +48,15 @@ fn test_move_cursor_to_next_line<W>(w: &mut W) -> Result<()>
|
|||||||
where
|
where
|
||||||
W: Write,
|
W: Write,
|
||||||
{
|
{
|
||||||
draw_cursor_box(w, "MoveToNextLine (2)", |_, _| cursor::MoveToNextLine(2))
|
draw_cursor_box(w, "MoveToNextLine (1)", |_, _| cursor::MoveToNextLine(1))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_move_cursor_to_column<W>(w: &mut W) -> Result<()>
|
fn test_move_cursor_to_column<W>(w: &mut W) -> Result<()>
|
||||||
where
|
where
|
||||||
W: Write,
|
W: Write,
|
||||||
{
|
{
|
||||||
draw_cursor_box(w, "MoveToColumn (2)", |center_x, _| {
|
draw_cursor_box(w, "MoveToColumn (1)", |center_x, _| {
|
||||||
cursor::MoveToColumn(center_x + 2)
|
cursor::MoveToColumn(center_x + 1)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,7 +140,7 @@ where
|
|||||||
cursor::MoveTo(0, 0),
|
cursor::MoveTo(0, 0),
|
||||||
style::SetForegroundColor(style::Color::Red),
|
style::SetForegroundColor(style::Color::Red),
|
||||||
style::Print(format!(
|
style::Print(format!(
|
||||||
"Red box is the center. After the action: '{}' another box is drawn.",
|
"Red box is the center. After the action: '{}' '√' is drawn to reflect the action from the center.",
|
||||||
description
|
description
|
||||||
))
|
))
|
||||||
)?;
|
)?;
|
||||||
@ -157,7 +157,7 @@ where
|
|||||||
queue!(
|
queue!(
|
||||||
w,
|
w,
|
||||||
cursor::MoveTo(column, row),
|
cursor::MoveTo(column, row),
|
||||||
style::PrintStyledContent("▓".red())
|
style::PrintStyledContent("▓".red()),
|
||||||
)?;
|
)?;
|
||||||
} else {
|
} else {
|
||||||
queue!(
|
queue!(
|
||||||
@ -172,7 +172,8 @@ where
|
|||||||
queue!(
|
queue!(
|
||||||
w,
|
w,
|
||||||
cursor::MoveTo(center_x, center_y),
|
cursor::MoveTo(center_x, center_y),
|
||||||
style::PrintStyledContent("▀".red().on_white())
|
style::PrintStyledContent("▀".red().on_white()),
|
||||||
|
cursor::MoveTo(center_x, center_y),
|
||||||
)?;
|
)?;
|
||||||
queue!(
|
queue!(
|
||||||
w,
|
w,
|
||||||
|
@ -55,7 +55,6 @@ pub(crate) mod sys;
|
|||||||
/// A command that moves the terminal cursor to the given position (column, row).
|
/// A command that moves the terminal cursor to the given position (column, row).
|
||||||
///
|
///
|
||||||
/// # Notes
|
/// # Notes
|
||||||
///
|
|
||||||
/// * Top left cell is represented as `0,0`.
|
/// * Top left cell is represented as `0,0`.
|
||||||
/// * Commands must be executed/queued for execution otherwise they do nothing.
|
/// * Commands must be executed/queued for execution otherwise they do nothing.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
@ -76,16 +75,15 @@ impl Command for MoveTo {
|
|||||||
/// and moves it to the first column.
|
/// and moves it to the first column.
|
||||||
///
|
///
|
||||||
/// # Notes
|
/// # Notes
|
||||||
///
|
/// * This command is 1 based, meaning `MoveToNextLine(1)` moves to the next line.
|
||||||
/// Commands must be executed/queued for execution otherwise they do nothing.
|
/// * Most terminals default 0 argument to 1.
|
||||||
|
/// * Commands must be executed/queued for execution otherwise they do nothing.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub struct MoveToNextLine(pub u16);
|
pub struct MoveToNextLine(pub u16);
|
||||||
|
|
||||||
impl Command for MoveToNextLine {
|
impl Command for MoveToNextLine {
|
||||||
fn write_ansi(&self, f: &mut impl fmt::Write) -> fmt::Result {
|
fn write_ansi(&self, f: &mut impl fmt::Write) -> fmt::Result {
|
||||||
if self.0 != 0 {
|
write!(f, csi!("{}E"), self.0)?;
|
||||||
write!(f, csi!("{}E"), self.0)?;
|
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,16 +100,15 @@ impl Command for MoveToNextLine {
|
|||||||
/// and moves it to the first column.
|
/// and moves it to the first column.
|
||||||
///
|
///
|
||||||
/// # Notes
|
/// # Notes
|
||||||
///
|
/// * This command is 1 based, meaning `MoveToPreviousLine(1)` moves to the previous line.
|
||||||
/// Commands must be executed/queued for execution otherwise they do nothing.
|
/// * Most terminals default 0 argument to 1.
|
||||||
|
/// * Commands must be executed/queued for execution otherwise they do nothing.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub struct MoveToPreviousLine(pub u16);
|
pub struct MoveToPreviousLine(pub u16);
|
||||||
|
|
||||||
impl Command for MoveToPreviousLine {
|
impl Command for MoveToPreviousLine {
|
||||||
fn write_ansi(&self, f: &mut impl fmt::Write) -> fmt::Result {
|
fn write_ansi(&self, f: &mut impl fmt::Write) -> fmt::Result {
|
||||||
if self.0 != 0 {
|
write!(f, csi!("{}F"), self.0)?;
|
||||||
write!(f, csi!("{}F"), self.0)?;
|
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,16 +124,14 @@ impl Command for MoveToPreviousLine {
|
|||||||
/// A command that moves the terminal cursor to the given column on the current row.
|
/// A command that moves the terminal cursor to the given column on the current row.
|
||||||
///
|
///
|
||||||
/// # Notes
|
/// # Notes
|
||||||
///
|
/// * This command is 0 based, meaning 0 is the leftmost column.
|
||||||
/// Commands must be executed/queued for execution otherwise they do nothing.
|
/// * Commands must be executed/queued for execution otherwise they do nothing.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub struct MoveToColumn(pub u16);
|
pub struct MoveToColumn(pub u16);
|
||||||
|
|
||||||
impl Command for MoveToColumn {
|
impl Command for MoveToColumn {
|
||||||
fn write_ansi(&self, f: &mut impl fmt::Write) -> fmt::Result {
|
fn write_ansi(&self, f: &mut impl fmt::Write) -> fmt::Result {
|
||||||
if self.0 != 0 {
|
write!(f, csi!("{}G"), self.0 + 1)?;
|
||||||
write!(f, csi!("{}G"), self.0)?;
|
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,16 +144,14 @@ impl Command for MoveToColumn {
|
|||||||
/// A command that moves the terminal cursor to the given row on the current column.
|
/// A command that moves the terminal cursor to the given row on the current column.
|
||||||
///
|
///
|
||||||
/// # Notes
|
/// # Notes
|
||||||
///
|
/// * This command is 0 based, meaning 0 is the topmost row.
|
||||||
/// Commands must be executed/queued for execution otherwise they do nothing.
|
/// * Commands must be executed/queued for execution otherwise they do nothing.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub struct MoveToRow(pub u16);
|
pub struct MoveToRow(pub u16);
|
||||||
|
|
||||||
impl Command for MoveToRow {
|
impl Command for MoveToRow {
|
||||||
fn write_ansi(&self, f: &mut impl fmt::Write) -> fmt::Result {
|
fn write_ansi(&self, f: &mut impl fmt::Write) -> fmt::Result {
|
||||||
if self.0 != 0 {
|
write!(f, csi!("{}d"), self.0 + 1)?;
|
||||||
write!(f, csi!("{}d"), self.0)?
|
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,16 +164,15 @@ impl Command for MoveToRow {
|
|||||||
/// A command that moves the terminal cursor a given number of rows up.
|
/// A command that moves the terminal cursor a given number of rows up.
|
||||||
///
|
///
|
||||||
/// # Notes
|
/// # Notes
|
||||||
///
|
/// * This command is 1 based, meaning `MoveUp(1)` moves the cursor up one cell.
|
||||||
/// Commands must be executed/queued for execution otherwise they do nothing.
|
/// * Most terminals default 0 argument to 1.
|
||||||
|
/// * Commands must be executed/queued for execution otherwise they do nothing.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub struct MoveUp(pub u16);
|
pub struct MoveUp(pub u16);
|
||||||
|
|
||||||
impl Command for MoveUp {
|
impl Command for MoveUp {
|
||||||
fn write_ansi(&self, f: &mut impl fmt::Write) -> fmt::Result {
|
fn write_ansi(&self, f: &mut impl fmt::Write) -> fmt::Result {
|
||||||
if self.0 != 0 {
|
write!(f, csi!("{}A"), self.0)?;
|
||||||
write!(f, csi!("{}A"), self.0)?;
|
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,16 +185,15 @@ impl Command for MoveUp {
|
|||||||
/// A command that moves the terminal cursor a given number of columns to the right.
|
/// A command that moves the terminal cursor a given number of columns to the right.
|
||||||
///
|
///
|
||||||
/// # Notes
|
/// # Notes
|
||||||
///
|
/// * This command is 1 based, meaning `MoveRight(1)` moves the cursor right one cell.
|
||||||
/// Commands must be executed/queued for execution otherwise they do nothing.
|
/// * Most terminals default 0 argument to 1.
|
||||||
|
/// * Commands must be executed/queued for execution otherwise they do nothing.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub struct MoveRight(pub u16);
|
pub struct MoveRight(pub u16);
|
||||||
|
|
||||||
impl Command for MoveRight {
|
impl Command for MoveRight {
|
||||||
fn write_ansi(&self, f: &mut impl fmt::Write) -> fmt::Result {
|
fn write_ansi(&self, f: &mut impl fmt::Write) -> fmt::Result {
|
||||||
if self.0 != 0 {
|
write!(f, csi!("{}C"), self.0)?;
|
||||||
write!(f, csi!("{}C"), self.0)?;
|
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,16 +206,15 @@ impl Command for MoveRight {
|
|||||||
/// A command that moves the terminal cursor a given number of rows down.
|
/// A command that moves the terminal cursor a given number of rows down.
|
||||||
///
|
///
|
||||||
/// # Notes
|
/// # Notes
|
||||||
///
|
/// * This command is 1 based, meaning `MoveDown(1)` moves the cursor down one cell.
|
||||||
/// Commands must be executed/queued for execution otherwise they do nothing.
|
/// * Most terminals default 0 argument to 1.
|
||||||
|
/// * Commands must be executed/queued for execution otherwise they do nothing.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub struct MoveDown(pub u16);
|
pub struct MoveDown(pub u16);
|
||||||
|
|
||||||
impl Command for MoveDown {
|
impl Command for MoveDown {
|
||||||
fn write_ansi(&self, f: &mut impl fmt::Write) -> fmt::Result {
|
fn write_ansi(&self, f: &mut impl fmt::Write) -> fmt::Result {
|
||||||
if self.0 != 0 {
|
write!(f, csi!("{}B"), self.0)?;
|
||||||
write!(f, csi!("{}B"), self.0)?;
|
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,16 +227,15 @@ impl Command for MoveDown {
|
|||||||
/// A command that moves the terminal cursor a given number of columns to the left.
|
/// A command that moves the terminal cursor a given number of columns to the left.
|
||||||
///
|
///
|
||||||
/// # Notes
|
/// # Notes
|
||||||
///
|
/// * This command is 1 based, meaning `MoveLeft(1)` moves the cursor left one cell.
|
||||||
/// Commands must be executed/queued for execution otherwise they do nothing.
|
/// * Most terminals default 0 argument to 1.
|
||||||
|
/// * Commands must be executed/queued for execution otherwise they do nothing.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub struct MoveLeft(pub u16);
|
pub struct MoveLeft(pub u16);
|
||||||
|
|
||||||
impl Command for MoveLeft {
|
impl Command for MoveLeft {
|
||||||
fn write_ansi(&self, f: &mut impl fmt::Write) -> fmt::Result {
|
fn write_ansi(&self, f: &mut impl fmt::Write) -> fmt::Result {
|
||||||
if self.0 != 0 {
|
write!(f, csi!("{}D"), self.0)?;
|
||||||
write!(f, csi!("{}D"), self.0)?;
|
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user