Terminal Output Overwrite

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

I'm just wondering. Thanks! :grin:

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.

1 Like

term has a delete_line method to clear the current line.

1 Like

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.

2 Likes

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