Fix multi-line prompts clearing too many lines
Ensure 0 previous rows are removed when calling refresh on a freshly
created State. Before, 0+ rows were removed on an initial State
refresh. If the prompt had a newline in it, a positive number of rows
were removed, clearing past output in stdout.
Fix #109
diff --git a/src/lib.rs b/src/lib.rs
index ea6e614..2562b68 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -104,7 +104,7 @@
prompt_size: prompt_size,
line: LineBuffer::with_capacity(capacity),
cursor: prompt_size,
- old_rows: prompt_size.row,
+ old_rows: 0,
history_index: history_index,
saved_line_for_history: LineBuffer::with_capacity(capacity),
byte_buffer: [0; 4],
diff --git a/src/tty/unix.rs b/src/tty/unix.rs
index 070d3e7..f1d435c 100644
--- a/src/tty/unix.rs
+++ b/src/tty/unix.rs
@@ -361,7 +361,9 @@
// calculate the desired position of the cursor
let cursor = self.calculate_position(&line[..line.pos()], prompt_size);
- let cursor_row_movement = old_rows - current_row;
+ // self.old_rows < self.cursor.row if the prompt spans multiple lines and if this is the
+ // default State.
+ let cursor_row_movement = old_rows.checked_sub(current_row).unwrap_or(0);
// move the cursor down as required
if cursor_row_movement > 0 {
write!(ab, "\x1b[{}B", cursor_row_movement).unwrap();