Skip to content

Commit

Permalink
Upgrade crossterm dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
atanunq committed Oct 20, 2022
1 parent a39e50f commit e55243f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exclude = [".github"]

[dependencies]
termcolor = "1.1"
crossterm = "0.23"
crossterm = "0.25"
ansi_colours = "1.0"
image = "0.24"
base64 = "0.13"
Expand Down
37 changes: 27 additions & 10 deletions src/printer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,23 @@ fn adjust_offset(stdout: &mut impl Write, config: &Config) -> ViuResult {
"absolute_offset is true but y offset is negative".to_owned(),
));
}
} else if config.y < 0 {
// MoveUp if negative
execute!(stdout, MoveToPreviousLine(-config.y as u16))?;
execute!(stdout, MoveRight(config.x))?;
} else {
// Move down y lines
for _ in 0..config.y {
// writeln! is used instead of MoveDown to force scrolldown
// observed when config.y > 0 and cursor is on the last terminal line
writeln!(stdout)?;
if config.y < 0 {
// MoveUp if negative
execute!(stdout, MoveToPreviousLine(-config.y as u16))?;
} else {
// Move down y lines
for _ in 0..config.y {
// writeln! is used instead of MoveDown to force scrolldown
// observed when config.y > 0 and cursor is on the last terminal line
writeln!(stdout)?;
}
}

// Some terminals interpret 0 as 1, see MoveRight documentation
if config.x > 0 {
execute!(stdout, MoveRight(config.x))?;
}
execute!(stdout, MoveRight(config.x))?;
}
Ok(())
}
Expand Down Expand Up @@ -404,6 +409,18 @@ mod tests {
assert_eq!((80, 12), fit_dimensions(80, 24, 80, 24));
}

#[test]
fn test_zero_offset() {
let config = Config {
absolute_offset: false,
x: 0,
y: 0,
..Default::default()
};
// Should not move at all
test_adjust_offset_output(&config, "");
}

#[test]
fn test_adjust_offset_absolute() {
let mut config = Config {
Expand Down

0 comments on commit e55243f

Please sign in to comment.