Skip to content

Commit cae9b99

Browse files
committed
Fix move_cursor moving to last char of the line above all bars
The cursor needs to move to the first line (which is one less than the number of lines, as the cursor is still on the last line), and then also move to the front of that line (as it was on the last char of the last line).
1 parent 3d00eff commit cae9b99

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/draw_target.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,9 @@ impl DrawState {
482482
}
483483

484484
if !self.lines.is_empty() && self.move_cursor {
485-
term.move_cursor_up(last_line_count.as_usize())?;
485+
// Move up to first line (assuming the last line doesn't contain a '\n') and then move to then front of the line
486+
term.move_cursor_up(last_line_count.as_usize().saturating_sub(1))?;
487+
term.write_str("\r")?;
486488
} else {
487489
// Fork of console::clear_last_lines that assumes that the last line doesn't contain a '\n'
488490
let n = last_line_count.as_usize();

tests/render.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,8 @@ fn multi_progress_move_cursor() {
429429
pb1.tick();
430430
assert_eq!(
431431
in_mem.moves_since_last_check(),
432-
r#"Str("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 0/10")
432+
r#"Str("\r")
433+
Str("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 0/10")
433434
Str("")
434435
Flush
435436
"#
@@ -439,7 +440,7 @@ Flush
439440
pb2.tick();
440441
assert_eq!(
441442
in_mem.moves_since_last_check(),
442-
r#"Up(1)
443+
r#"Str("\r")
443444
Str("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 0/10")
444445
Str("")
445446
NewLine
@@ -452,7 +453,8 @@ Flush
452453
pb1.inc(1);
453454
assert_eq!(
454455
in_mem.moves_since_last_check(),
455-
r#"Up(2)
456+
r#"Up(1)
457+
Str("\r")
456458
Str("███████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 1/10")
457459
Str("")
458460
NewLine

0 commit comments

Comments
 (0)