Skip to content

Commit

Permalink
Fix move_cursor moving to last char of the line above all bars
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
SuperTux88 authored and djc committed Jun 13, 2024
1 parent 648226b commit 24eaf46
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/draw_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,9 @@ impl DrawState {
}

if !self.lines.is_empty() && self.move_cursor {
term.move_cursor_up(last_line_count.as_usize())?;
// Move up to first line (assuming the last line doesn't contain a '\n') and then move to then front of the line
term.move_cursor_up(last_line_count.as_usize().saturating_sub(1))?;
term.write_str("\r")?;
} else {
// Fork of console::clear_last_lines that assumes that the last line doesn't contain a '\n'
let n = last_line_count.as_usize();
Expand Down
8 changes: 5 additions & 3 deletions tests/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,8 @@ fn multi_progress_move_cursor() {
pb1.tick();
assert_eq!(
in_mem.moves_since_last_check(),
r#"Str("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 0/10")
r#"Str("\r")
Str("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 0/10")
Str("")
Flush
"#
Expand All @@ -439,7 +440,7 @@ Flush
pb2.tick();
assert_eq!(
in_mem.moves_since_last_check(),
r#"Up(1)
r#"Str("\r")
Str("░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 0/10")
Str("")
NewLine
Expand All @@ -452,7 +453,8 @@ Flush
pb1.inc(1);
assert_eq!(
in_mem.moves_since_last_check(),
r#"Up(2)
r#"Up(1)
Str("\r")
Str("███████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 1/10")
Str("")
NewLine
Expand Down

0 comments on commit 24eaf46

Please sign in to comment.