From 8c1d1bb05b69b623bf7d41d970021a85c1c00a6d Mon Sep 17 00:00:00 2001 From: Robert Straw Date: Wed, 11 Jan 2023 22:06:53 -0600 Subject: [PATCH] (linetest) fix off by one error This has been here for a while: the "move to column" escape code is supposed to be zero-based, but empirically that does not seem to be the case on the several terminal emulators I've tested. (i.e. col(0) and col(1) are equivalent operations.) We can remove the erroneous padding from the relative position we compute, pass it to "move to row and column," and it does what you would expect. --- linetest/src/shell/ui/buffer.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/linetest/src/shell/ui/buffer.rs b/linetest/src/shell/ui/buffer.rs index 288cf36..a3b8aeb 100644 --- a/linetest/src/shell/ui/buffer.rs +++ b/linetest/src/shell/ui/buffer.rs @@ -350,12 +350,12 @@ impl InputBuffer { // render the current viewport & update the cursor let beg = self.start; let end = cmp::min(self.buffer.len(), self.end); - let relative_cursor_pos = (self.pos - self.start) + prompt.len() + 1; + let relative_cursor_pos = (self.pos - self.start) + prompt.len(); assert!(relative_cursor_pos <= u16::MAX.into()); stdout .queue(Print(&self.buffer[beg..end]))? - .queue(cursor::MoveToColumn(relative_cursor_pos as u16))?; + .queue(cursor::MoveTo(relative_cursor_pos as u16, row))?; Ok(()) } -- 2.45.2