AnswerDotAI / AnswerDotAI/fastprogress

Progress bar not clearing line in Console mode

Open
#106 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
1.1k
Forks
104
Avg merge
1m
Merged PRs (30d)
1

Description

In console mode, when adding a progress comment, the previous line is not completely cleared thus causing the leftover ending to remain. for example:

```python
from fastprogress import progress_bar
from pathlib import Path
import time

files = list(Path('/etc').glob('*'))
pb = progress_bar(files)

for fn in pb:
pb.comment = f'{fn.stem}'
time.sleep(0.1)
```

console output:

|█████████████----| 77.69% [188/242 00:18<00:05 login]es]]e]te].conf]

I managed to root-cause the issue and solved it by updating [`on_update`](https://github.com/fastai/fastprogress/blob/3264b4da7edd7b0061b0ace0d44e8fabc29652f3/fastprogress/fastprogress.py#L257) and padding with empty spaces to max_len

modify:
```python
if len(to_write) > self.max_len: self.max_len=len(to_write)
```
to
```python
if len(to_write) > self.max_len: self.max_len=len(to_write)
else: to_write += ' ' * (self.max_len - len(to_write))
```

is this the proper way to fix it?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.