Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. fn ansi_esc(input: &str) -> String {
  2. format!("\x1b[{}", input)
  3. }
  4.  
  5. fn ansi_escape(message: &str) {
  6. let out = ansi_esc(message);
  7. // Use println to reproduce the issue
  8. println!("{}", out);
  9. // Use print to fix the issue
  10. // print!("{}", out);
  11. }
  12.  
  13. fn ansi_set_position(line: usize, column: usize) {
  14. let message = format!("{};{}H", line + 1, column + 1);
  15. ansi_escape(message.as_slice());
  16. }
  17.  
  18. fn main() {
  19. // my screen height is 45
  20. let number_greater_than_your_screen_height = 46us;
  21. for i in 0..number_greater_than_your_screen_height {
  22. ansi_set_position(i, 0);
  23. ansi_escape("2K");
  24. ansi_set_position(i, 0);
  25. println!("{}", i);
  26. }
  27. }
  28.  
  29. // What it looks like to reproduce the issue:
  30. // 40
  31. // 41
  32. // 42
  33. //
  34. // 43
  35. //
  36. //
  37. //
  38. // 44
  39. //
  40. //
  41. //
  42. // 45
  43.  
  44. // What it looks like to fix the issue:
  45. // 40
  46. // 41
  47. // 42
  48. // 43
  49. // 44
  50. // 45
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement