Terminal Output Overwrite


#1

Is it possible to overwrite or clear an output on the terminal in Rust?

I’m just wondering. Thanks! :grin:


#2

For clearing the current line, I’ve used a hack with ANSI escape codes.

I tried with various readline-like libraries, but was unsuccessful at the time. I might have missed something obvious though.


#3

term has a delete_line method to clear the current line.

https://stebalien.github.io/doc/term/term/trait.Terminal.html#tymethod.delete_line


#4

If you just want to overwrite the last line (e.g. to update a status message), the easiest way is to write a '\r' which will put the cursor at the beginning of the line.


#5

Thanks, that was what I was looking for!:slight_smile: