Skip to content
This repository was archived by the owner on Nov 30, 2023. It is now read-only.

Use backspace (\b) instead of carriage return (\r) #4

Closed
wants to merge 1 commit into from
Closed

Use backspace (\b) instead of carriage return (\r) #4

wants to merge 1 commit into from

Conversation

jlowin
Copy link

@jlowin jlowin commented Jan 14, 2014

tqdm uses \r to clear the most recently printed line. However, if the console width is less than the length of the string, then the string is printed on multiple lines and \r doesn't work -- it actually leaves artifacts behind.

By using backspace \b for each printed character, tqdm can clear output over multiple lines.

Note this problem can arise either because the string is long or the console width has been made artificially short.

Example:

long_desc = 'A very long' + '.' * 100 + 'description!'
for i in tqdm.tqdm(xrange(10000), desc=long_desc):
    time.sleep(0.0001)

If the printed string is longer than the console window, it is wrapped onto a new line and \r will fail to erase it, creating artifacts -- for example, if a long description is passed to tqdm(). Using backspaces (\b) instead will clear multiple lines.
@noamraph
Copy link
Owner

noamraph commented Feb 4, 2014

Thanks! That's a good idea!
I want to merge it once I add '\b' support to DreamPie.

@kmike kmike mentioned this pull request Apr 16, 2015
@jlowin jlowin closed this Mar 29, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants