Skip to content

Instantly share code, notes, and snippets.

@carols10cents
Last active August 29, 2015 14:14
Show Gist options
  • Select an option

  • Save carols10cents/c87ef14458d0f3531931 to your computer and use it in GitHub Desktop.

Select an option

Save carols10cents/c87ef14458d0f3531931 to your computer and use it in GitHub Desktop.
fn ansi_esc(input: &str) -> String {
format!("\x1b[{}", input)
}
fn ansi_escape(message: &str) {
let out = ansi_esc(message);
// Use println to reproduce the issue
println!("{}", out);
// Use print to fix the issue
// print!("{}", out);
}
fn ansi_set_position(line: usize, column: usize) {
let message = format!("{};{}H", line + 1, column + 1);
ansi_escape(message.as_slice());
}
fn main() {
// my screen height is 45
let number_greater_than_your_screen_height = 46us;
for i in 0..number_greater_than_your_screen_height {
ansi_set_position(i, 0);
ansi_escape("2K");
ansi_set_position(i, 0);
println!("{}", i);
}
}
// What it looks like to reproduce the issue:
// 40
// 41
// 42
//
// 43
//
//
//
// 44
//
//
//
// 45
// What it looks like to fix the issue:
// 40
// 41
// 42
// 43
// 44
// 45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment