Skip to content

Commit 4a0523a

Browse files
committed
0.2.0 runtime attributes
1 parent 49b51e2 commit 4a0523a

File tree

21 files changed

+101
-27
lines changed

21 files changed

+101
-27
lines changed

README.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,5 +215,14 @@ RGB tuples must be in format 0-255 and must not contain alpha part.
215215
RGB tuples are only supported in Truecolor terminals.
216216
They might display differently/incorrectly in other terminals.
217217

218+
Runtime attributes
219+
==================
220+
221+
While your bar is running, you can easily access some of its attributes:
222+
223+
- ``ProgressBar.eta`` - current ETA in seconds
224+
- ``ProgressBar.percentage`` - current percentage
225+
- ``ProgressBar.items_done`` - number of items already done
226+
218227

219228
.. |spinner-line| image:: line-spinner.gif

build/build/lib/fancybar/progressbar.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def parse_hex(h):
7979
(scol & 0xFF00) >> 8,
8080
(scol & 0xFF),
8181
(col & 0xFF) / 255,
82-
)
82+
)
8383
elif l == 3: # short form, no alpha
8484
return 17 * ((col & 0xF00) >> 8), 17 * ((col & 0xF0) >> 4), 17 * (col & 0xF)
8585
elif l == 4: # short form, alpha
@@ -111,7 +111,7 @@ def _color_range(start_r, start_g, start_b, end_r, end_g, end_b, length):
111111

112112
def _generate_gradient_colors(startcol, endcol, length):
113113
col_r = _color_range(*startcol, *endcol, length)
114-
cur=startcol
114+
cur = startcol
115115
prev = 0, 0, 0
116116
i = 0
117117
curr_frame = ""
@@ -124,11 +124,11 @@ def _generate_gradient_colors(startcol, endcol, length):
124124
if i % 2 == 1:
125125
nxt = cur
126126
cur = prev
127-
prev_frame = curr_frame = prev_frame + GRADIENT_TEMPLATE.format(*cur,*nxt)
127+
prev_frame = curr_frame = prev_frame + GRADIENT_TEMPLATE.format(*cur, *nxt)
128128

129129
else:
130130
nxt = 0, 0, 0
131-
prev= cur
131+
prev = cur
132132
curr_frame += GRADIENT_TEMPLATE.format(*cur, *nxt)
133133
i += 1
134134
yield curr_frame
@@ -249,6 +249,8 @@ def __init__(
249249
self.start_time = None
250250
self.list = bartype(length, **kwargs).frames
251251
self.item_name = item_name
252+
self.eta = None
253+
self.percentage = None
252254
self.spinner = Spinner(spinner, speed=spinner_speed)
253255
self.percentage_fg_color = percentage_fg_color
254256
self.spinner_fg_color = spinner_fg_color
@@ -292,9 +294,11 @@ def update(self):
292294
self.percentage = (self.items_done / self.items) * 100
293295
iterations = self.items_done / (time.time() - self.start_time)
294296
self.eta = round((self.items - self.items_done) / iterations)
295-
string = f"\r {color_fg(self.spinner_fg_color)}{color_bg(self.spinner_bg_color)}{sf}{sfpad}{END}"+\
296-
f"<{self.items_done}/{self.items}> {color_fg(self.percentage_fg_color)}{color_bg(self.percentage_bg_color)}{self.percentage:.1f}%{END}"+\
297-
f"|{image}| ({iterations:.2f} {self.item_name}/s) ({self.eta//60:0>2}:{self.eta%60:0>2}eta) "
297+
string = (
298+
f"\r {color_fg(self.spinner_fg_color)}{color_bg(self.spinner_bg_color)}{sf}{sfpad}{END}"
299+
+ f"<{self.items_done}/{self.items}> {color_fg(self.percentage_fg_color)}{color_bg(self.percentage_bg_color)}{self.percentage:.1f}%{END}"
300+
+ f"|{image}| ({iterations:.2f} {self.item_name}/s) ({self.eta//60:0>2}:{self.eta%60:0>2}eta) "
301+
)
298302

299303
sys.stdout.write(string)
300304
sys.stdout.flush()
11.9 KB
Binary file not shown.

build/dist/fancybar-0.2.0.tar.gz

14.9 KB
Binary file not shown.

build/fancybar.egg-info/PKG-INFO

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 2.1
22
Name: fancybar
3-
Version: 0.1.3
3+
Version: 0.2.0
44
Summary: A highly customizable terminal progress bar library
55
Home-page: https://github.com/jenca-adam/fancybar
66
Author: Adam Jenca
@@ -81,7 +81,7 @@ There are currently the following bar types:
8181

8282
- classic
8383

84-
.. image:: https://fancybar.readthedocs.io/en/latest/_images/bartype_classic.gif
84+
.. image:https://fancybar.readthedocs.io/en/latest/_images/colors.gif: https://fancybar.readthedocs.io/en/latest/_images/bartype_classic.gif
8585

8686
This bar type uses character '#' (U+0023 NUMBER SIGN) and filler ' ' (U+0020 SPACE).
8787
This bar type should work on any terminal.
@@ -233,6 +233,16 @@ RGB tuples must be in format 0-255 and must not contain alpha part.
233233
RGB tuples are only supported in Truecolor terminals.
234234
They might display differently/incorrectly in other terminals.
235235

236+
Runtime attributes
237+
==================
238+
239+
While your bar is running, you can easily access some of its attributes:
240+
241+
- ``ProgressBar.eta`` - current ETA in seconds
242+
- ``ProgressBar.percentage`` - current percentage
243+
- ``ProgressBar.items_done`` - number of items already done
244+
245+
236246

237247
.. |spinner-line| image:: line-spinner.gif
238248

build/setup.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
setuptools.setup(
44
name="fancybar",
55
description="A highly customizable terminal progress bar library",
6-
version="0.1.3",
6+
version="0.2.0",
77
long_description="""
88
99
.. figure:: https://fancybar.readthedocs.io/en/latest/_images/fancybar-logo.png
@@ -69,7 +69,7 @@
6969
7070
- classic
7171
72-
.. image:: https://fancybar.readthedocs.io/en/latest/_images/bartype_classic.gif
72+
.. image:https://fancybar.readthedocs.io/en/latest/_images/colors.gif: https://fancybar.readthedocs.io/en/latest/_images/bartype_classic.gif
7373
7474
This bar type uses character '#' (U+0023 NUMBER SIGN) and filler ' ' (U+0020 SPACE).
7575
This bar type should work on any terminal.
@@ -221,6 +221,16 @@
221221
RGB tuples are only supported in Truecolor terminals.
222222
They might display differently/incorrectly in other terminals.
223223
224+
Runtime attributes
225+
==================
226+
227+
While your bar is running, you can easily access some of its attributes:
228+
229+
- ``ProgressBar.eta`` - current ETA in seconds
230+
- ``ProgressBar.percentage`` - current percentage
231+
- ``ProgressBar.items_done`` - number of items already done
232+
233+
224234
225235
.. |spinner-line| image:: line-spinner.gif
226236
2.94 KB
Binary file not shown.

docs/build/doctrees/index.doctree

1.78 KB
Binary file not shown.

docs/build/html/.buildinfo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Sphinx build info version 1
22
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
3-
config: 6d620043fc3ea0de1ce1389126ddb08c
3+
config: 9a70ab5e65c746a4da81ba1ae409dc56
44
tags: 645f666f9bcd5a90fca523b33c5a78b7

docs/build/html/_sources/index.rst.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ Spinners
168168
.. image:: spinners.gif
169169

170170
All spinners are on the GIF above.
171-
The spinners not shown are not shown because of the asciinema charset limitations. To get a more acute representation of the spinners, clone the repository and run ``python3 spinner_test.py``.
171+
The spinners not shown are not shown because of the asciinema charset limitations. To get a more acute representation of the spinners, clone the repository and run ``python3 showcases/spinner_test.py``.
172172
The default spinner is |spinner-line|.
173173
You can choose a spinner by setting the argument ``spinner`` of ``ProgressBar`` to its name. See :ref:`Entry Points`
174174

@@ -237,5 +237,14 @@ RGB tuples must be in format 0-255 and must not contain alpha part.
237237
RGB tuples are only supported in Truecolor terminals.
238238
They might display differently/incorrectly in other terminals.
239239

240+
Runtime attributes
241+
==================
242+
243+
While your bar is running, you can easily access some of its attributes:
244+
245+
- ``ProgressBar.eta`` - current ETA in seconds
246+
- ``ProgressBar.percentage`` - current percentage
247+
- ``ProgressBar.items_done`` - number of items already done
248+
240249

241250
.. |spinner-line| image:: line-spinner.gif

0 commit comments

Comments
 (0)