thocoo / gamma-desk

Gamma Desk
Apache License 2.0
3 stars 1 forks source link

Print is 'growing' when using \r for example for a progress bar #8

Closed louvervecken closed 2 years ago

louvervecken commented 3 years ago

When executing this in the Gamma Desk console it looks like the printed string is being padded with one space character every iteration. So in the end the printed string is over 100 characters long. You would not notice this directly were it not for the horizontal scroll bar moving together with the string getting longer and the text of interest moving out of view.

import time
for i in range(100):
  time.sleep(0.1)
  print(f"\r test {i}", end='\r')

I came across this when adding some kind of progress bar.

thocoo commented 3 years ago

I fixed it by reverting another bugfix, which I don't remember what the problem was. Comments said that '\r' at beginning of print text would set the output panel in some bad mode. But I can't reproduce that error. So I just revert the bugix. Now, the '\r' behaves as expected. Note that you can just use end=''. No need to have a '\r' at the end.