Skip to content

Commit

Permalink
Fixed a bug that would cause an error creating a progress bar with no…
Browse files Browse the repository at this point in the history
… value set for width in systems without support for os.get_terminal_size().
  • Loading branch information
MPCodeWriter21 committed Jul 25, 2022
1 parent 2279533 commit 846022c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
5 changes: 5 additions & 0 deletions CHANGES-LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Help this project by [Donation](DONATE.md)
Changes log
-----------

### 2.3.3

Fixed a bug that would cause an error creating a progress bar with no value set for width in systems without support for
os.get_terminal_size().

### 2.3.2

Added `additional_variables` argument to `log21.ProgressBar` class. You can use it in order to add additional variables
Expand Down
18 changes: 3 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,10 @@ python setup.py install
Changes
-------

### 2.3.2
### 2.3.3

Added `additional_variables` argument to `log21.ProgressBar` class. You can use it in order to add additional variables
to the progress bar:

```python3
import log21, time

progress_bar = log21.ProgressBar(format_='Iteration: {i} {prefix}{bar}{suffix} {percentage}%', style='{',
additional_variables={"i": 0})

for i in range(100):
progress_bar(i + 1, 100, i=i)
time.sleep(0.1)
# Iteration: 99 |██████████████████████████████████████████████████████████████████████████████| 100%
```
Fixed a bug that would cause an error creating a progress bar with no value set for width in systems without support for
os.get_terminal_size().

[Full Changes Log](https://github.com/MPCodeWriter21/log21/blob/master/CHANGES-LOG.md)

Expand Down
10 changes: 9 additions & 1 deletion log21/ProgressBar.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,15 @@ def __init__(self, *args, width: int = None, show_percentage: bool = True, prefi
:param logger: The logger to use
:param additional_variables: Additional variables to use in the format and their default values
"""
self.width = width if width else _os.get_terminal_size().columns - 1
# Sets a default value for the width
if width is None:
try:
width = _os.get_terminal_size().columns - 1
except OSError:
width = 50
if width < 1:
width = 50
self.width = width
if self.width < 3:
raise ValueError('`width` must be greater than 1')
if not isinstance(fill, str):
Expand Down
2 changes: 1 addition & 1 deletion log21/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from log21.Formatters import ColorizingFormatter, DecolorizingFormatter
from log21.Colors import Colors, get_color, get_colors, ansi_escape, get_color_name, closest_color

__version__ = "2.3.2"
__version__ = "2.3.3"
__author__ = "CodeWriter21 (Mehrad Pooryoussof)"
__github__ = "Https://GitHub.com/MPCodeWriter21/log21"
__all__ = ['ColorizingStreamHandler', 'DecolorizingFileHandler', 'ColorizingFormatter', 'DecolorizingFormatter',
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
long_description = file.read()

DESCRIPTION = 'A simple logging package that helps you log colorized messages in Windows console.'
VERSION = '2.3.2'
VERSION = '2.3.3'

setup(
name='log21',
Expand Down

0 comments on commit 846022c

Please sign in to comment.