cli is a box ( docs ) which seems to work very well to solve this very problem. It also comes with some other common goodies, such as progress bars and style invitations.
cli::clear should be the function you want.
The main difficulty with using something like repetition:
println!("\r");
is that it will not be compatible with the OS, but when using cli :: clear should be as long as the OS is supported. Another nice thing about using cli is that it is a higher level of abstraction that clearly conveys your actual meaning.
You want to clear the terminal.
You are not trying to re-receive a carriage return.
There are other routines for such things. Namely, a progress bar, which is the problem you are trying to solve.
source share