IDLE doesn’t respond to \r
the way a terminal should. You can run it at the command prompt with py yourscript.py
or use an IDE that either has an integrated terminal (like VSCode) or one which has a shell that responds to \r
and other ANSI terminal control codes (like Thonny). Otherwise your code is quite good.