From dd8b64eebc243a654dc940866440aef52681082c Mon Sep 17 00:00:00 2001 From: Timon Date: Thu, 30 Jun 2022 20:58:26 +0200 Subject: [PATCH] Fix MoveToPrevious/Next Line to be 1-based. --- examples/interactive-demo/src/test/cursor.rs | 17 +++++++++-------- src/cursor.rs | 4 ++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/examples/interactive-demo/src/test/cursor.rs b/examples/interactive-demo/src/test/cursor.rs index a7c03a4d..71238f34 100644 --- a/examples/interactive-demo/src/test/cursor.rs +++ b/examples/interactive-demo/src/test/cursor.rs @@ -39,8 +39,8 @@ fn test_move_cursor_to_previous_line(w: &mut W) -> Result<()> where W: Write, { - draw_cursor_box(w, "MoveToPreviousLine (2)", |_, _| { - cursor::MoveToPreviousLine(2) + draw_cursor_box(w, "MoveToPreviousLine (1)", |_, _| { + cursor::MoveToPreviousLine(1) }) } @@ -48,15 +48,15 @@ fn test_move_cursor_to_next_line(w: &mut W) -> Result<()> where 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: &mut W) -> Result<()> where W: Write, { - draw_cursor_box(w, "MoveToColumn (2)", |center_x, _| { - cursor::MoveToColumn(center_x + 2) + draw_cursor_box(w, "MoveToColumn (1)", |center_x, _| { + cursor::MoveToColumn(center_x + 1) }) } @@ -140,7 +140,7 @@ where cursor::MoveTo(0, 0), style::SetForegroundColor(style::Color::Red), 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 )) )?; @@ -157,7 +157,7 @@ where queue!( w, cursor::MoveTo(column, row), - style::PrintStyledContent("▓".red()) + style::PrintStyledContent("▓".red()), )?; } else { queue!( @@ -172,7 +172,8 @@ where queue!( w, cursor::MoveTo(center_x, center_y), - style::PrintStyledContent("▀".red().on_white()) + style::PrintStyledContent("▀".red().on_white()), + cursor::MoveTo(center_x, center_y), )?; queue!( w, diff --git a/src/cursor.rs b/src/cursor.rs index a777ec9c..b25b3674 100644 --- a/src/cursor.rs +++ b/src/cursor.rs @@ -83,7 +83,7 @@ pub struct MoveToNextLine(pub u16); impl Command for MoveToNextLine { fn write_ansi(&self, f: &mut impl fmt::Write) -> fmt::Result { - write!(f, csi!("{}E"), self.0 + 1)?; + write!(f, csi!("{}E"), self.0)?; Ok(()) } @@ -108,7 +108,7 @@ pub struct MoveToPreviousLine(pub u16); impl Command for MoveToPreviousLine { fn write_ansi(&self, f: &mut impl fmt::Write) -> fmt::Result { - write!(f, csi!("{}F"), self.0 + 1)?; + write!(f, csi!("{}F"), self.0)?; Ok(()) }