Skip to content

Commit 846022c

Browse files
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().
1 parent 2279533 commit 846022c

5 files changed

Lines changed: 19 additions & 18 deletions

File tree

CHANGES-LOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ Help this project by [Donation](DONATE.md)
66
Changes log
77
-----------
88

9+
### 2.3.3
10+
11+
Fixed a bug that would cause an error creating a progress bar with no value set for width in systems without support for
12+
os.get_terminal_size().
13+
914
### 2.3.2
1015

1116
Added `additional_variables` argument to `log21.ProgressBar` class. You can use it in order to add additional variables

README.md

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,10 @@ python setup.py install
5353
Changes
5454
-------
5555

56-
### 2.3.2
56+
### 2.3.3
5757

58-
Added `additional_variables` argument to `log21.ProgressBar` class. You can use it in order to add additional variables
59-
to the progress bar:
60-
61-
```python3
62-
import log21, time
63-
64-
progress_bar = log21.ProgressBar(format_='Iteration: {i} {prefix}{bar}{suffix} {percentage}%', style='{',
65-
additional_variables={"i": 0})
66-
67-
for i in range(100):
68-
progress_bar(i + 1, 100, i=i)
69-
time.sleep(0.1)
70-
# Iteration: 99 |██████████████████████████████████████████████████████████████████████████████| 100%
71-
```
58+
Fixed a bug that would cause an error creating a progress bar with no value set for width in systems without support for
59+
os.get_terminal_size().
7260

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

log21/ProgressBar.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,15 @@ def __init__(self, *args, width: int = None, show_percentage: bool = True, prefi
5858
:param logger: The logger to use
5959
:param additional_variables: Additional variables to use in the format and their default values
6060
"""
61-
self.width = width if width else _os.get_terminal_size().columns - 1
61+
# Sets a default value for the width
62+
if width is None:
63+
try:
64+
width = _os.get_terminal_size().columns - 1
65+
except OSError:
66+
width = 50
67+
if width < 1:
68+
width = 50
69+
self.width = width
6270
if self.width < 3:
6371
raise ValueError('`width` must be greater than 1')
6472
if not isinstance(fill, str):

log21/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from log21.Formatters import ColorizingFormatter, DecolorizingFormatter
2222
from log21.Colors import Colors, get_color, get_colors, ansi_escape, get_color_name, closest_color
2323

24-
__version__ = "2.3.2"
24+
__version__ = "2.3.3"
2525
__author__ = "CodeWriter21 (Mehrad Pooryoussof)"
2626
__github__ = "Https://GitHub.com/MPCodeWriter21/log21"
2727
__all__ = ['ColorizingStreamHandler', 'DecolorizingFileHandler', 'ColorizingFormatter', 'DecolorizingFormatter',

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
long_description = file.read()
88

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

1212
setup(
1313
name='log21',

0 commit comments

Comments
 (0)