mirror of
https://github.com/verigak/progress.git
synced 2025-12-08 19:33:24 +00:00
Compare commits
73 Commits
1.1
...
200e1f44da
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
200e1f44da | ||
|
|
715467d4d0 | ||
|
|
1f658bc627 | ||
|
|
eebaa99c82 | ||
|
|
52de04b95d | ||
|
|
bdce3afb5e | ||
|
|
0a5fc077b2 | ||
|
|
3beeeb7716 | ||
|
|
e3dbaf52e1 | ||
|
|
ca6310204e | ||
|
|
b8fdfc782d | ||
|
|
0faea87060 | ||
|
|
64671e1ceb | ||
|
|
12e46ed702 | ||
|
|
d325dab247 | ||
|
|
e5c2368c6b | ||
|
|
03d4adbf73 | ||
|
|
42fd17f67c | ||
|
|
0d93258f52 | ||
|
|
4af220e573 | ||
|
|
25cefd12db | ||
|
|
1ed414290f | ||
|
|
f6390b76f2 | ||
|
|
80a91b9c78 | ||
|
|
57a36d49f2 | ||
|
|
efeb57282b | ||
|
|
61627a8642 | ||
|
|
c1e07104e1 | ||
|
|
326413a271 | ||
|
|
1b326504ce | ||
|
|
b95b764e37 | ||
|
|
2eeff94083 | ||
|
|
8cf7faa4e3 | ||
|
|
4b7c9388f4 | ||
|
|
d9d40736d6 | ||
|
|
d407334bcf | ||
|
|
086cfd5599 | ||
|
|
6553b7b207 | ||
|
|
1f19b5b61c | ||
|
|
f5c911ed83 | ||
|
|
5d52c5b299 | ||
|
|
a83f91f4b8 | ||
|
|
292a031c4b | ||
|
|
83f3b79137 | ||
|
|
84c3b9197a | ||
|
|
715a2e130f | ||
|
|
33ab0be1ec | ||
|
|
91d9d3cb05 | ||
|
|
6661bcbe1d | ||
|
|
d440d5bbaf | ||
|
|
7ecf7594a4 | ||
|
|
92665ef189 | ||
|
|
c5043685c5 | ||
|
|
f1f6ea57da | ||
|
|
0b668811f9 | ||
|
|
e61e49bbf4 | ||
|
|
61ac9b6980 | ||
|
|
0435756cf7 | ||
|
|
ded975221b | ||
|
|
5e45abaa95 | ||
|
|
80b54c1228 | ||
|
|
36ba012ffb | ||
|
|
f1bfb28df9 | ||
|
|
ee7831362c | ||
|
|
85b59e0a1d | ||
|
|
94ff8dd979 | ||
|
|
288ddf1ec5 | ||
|
|
723024a296 | ||
|
|
a5981103cf | ||
|
|
120b3e53b1 | ||
|
|
8b02a5b59f | ||
|
|
e5cffc8c72 | ||
|
|
41d5f916c1 |
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
|||||||
# Copyright (c) 2012 Giorgos Verigakis <verigak@gmail.com>
|
# Copyright (c) 2012 Georgios Verigakis <verigak@gmail.com>
|
||||||
#
|
#
|
||||||
# Permission to use, copy, modify, and distribute this software for any
|
# Permission to use, copy, modify, and distribute this software for any
|
||||||
# purpose with or without fee is hereby granted, provided that the above
|
# purpose with or without fee is hereby granted, provided that the above
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
include README.rst LICENSE
|
|
||||||
123
README.rst
123
README.rst
@@ -1,19 +1,31 @@
|
|||||||
Easy progress reporting for Python
|
Easy progress reporting for Python
|
||||||
==================================
|
==================================
|
||||||
|
|
||||||
|
|pypi|
|
||||||
|
|
||||||
|
|demo|
|
||||||
|
|
||||||
|
.. |pypi| image:: https://img.shields.io/pypi/v/progress.svg
|
||||||
|
:target: https://pypi.org/project/progress/
|
||||||
|
.. |demo| image:: https://raw.github.com/verigak/progress/master/demo.gif
|
||||||
|
:alt: Demo
|
||||||
|
|
||||||
Bars
|
Bars
|
||||||
----
|
----
|
||||||
|
|
||||||
There are 6 progress bars to choose from:
|
There are 7 progress bars to choose from:
|
||||||
|
|
||||||
- Bar
|
- ``Bar``
|
||||||
- ChargingBar
|
- ``ChargingBar``
|
||||||
- FillingSquaresBar
|
- ``FillingSquaresBar``
|
||||||
- FillingCirclesBar
|
- ``FillingCirclesBar``
|
||||||
- IncrementalBar
|
- ``IncrementalBar``
|
||||||
- ShadyBar
|
- ``PixelBar``
|
||||||
|
- ``ShadyBar``
|
||||||
|
|
||||||
To use them, just call ``next`` to advance and ``finish`` to finish. ::
|
To use them, just call ``next`` to advance and ``finish`` to finish:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
from progress.bar import Bar
|
from progress.bar import Bar
|
||||||
|
|
||||||
@@ -23,18 +35,33 @@ To use them, just call ``next`` to advance and ``finish`` to finish. ::
|
|||||||
bar.next()
|
bar.next()
|
||||||
bar.finish()
|
bar.finish()
|
||||||
|
|
||||||
|
or use any bar of this class as a context manager:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
from progress.bar import Bar
|
||||||
|
|
||||||
|
with Bar('Processing', max=20) as bar:
|
||||||
|
for i in range(20):
|
||||||
|
# Do some work
|
||||||
|
bar.next()
|
||||||
|
|
||||||
The result will be a bar like the following: ::
|
The result will be a bar like the following: ::
|
||||||
|
|
||||||
Processing |############# | 42/100
|
Processing |############# | 42/100
|
||||||
|
|
||||||
To simplify the common case where the work is done in an iterator, you can
|
To simplify the common case where the work is done in an iterator, you can
|
||||||
use the ``iter`` method. ::
|
use the ``iter`` method:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
for i in Bar('Processing').iter(it):
|
for i in Bar('Processing').iter(it):
|
||||||
# Do some work
|
# Do some work
|
||||||
|
|
||||||
Progress bars are very customizable, you can change their width, their fill
|
Progress bars are very customizable, you can change their width, their fill
|
||||||
character, their suffix and more. ::
|
character, their suffix and more:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
bar = Bar('Loading', fill='@', suffix='%(percent)d%%')
|
bar = Bar('Loading', fill='@', suffix='%(percent)d%%')
|
||||||
|
|
||||||
@@ -44,48 +71,82 @@ This will produce a bar like the following: ::
|
|||||||
|
|
||||||
You can use a number of template arguments in ``message`` and ``suffix``:
|
You can use a number of template arguments in ``message`` and ``suffix``:
|
||||||
|
|
||||||
========= =============================
|
========== ================================
|
||||||
Name Value
|
Name Value
|
||||||
========= =============================
|
========== ================================
|
||||||
index current value
|
index current value
|
||||||
max maximum value
|
max maximum value
|
||||||
remaining max - index
|
remaining max - index
|
||||||
progress index / max
|
progress index / max
|
||||||
percent progress * 100
|
percent progress * 100
|
||||||
avg rolling average time per item (in seconds)
|
avg simple moving average time per item (in seconds)
|
||||||
eta avg * remaining
|
elapsed elapsed time in seconds
|
||||||
========= =============================
|
elapsed_td elapsed as a timedelta (useful for printing as a string)
|
||||||
|
eta avg * remaining
|
||||||
|
eta_td eta as a timedelta (useful for printing as a string)
|
||||||
|
========== ================================
|
||||||
|
|
||||||
Instead of passing all configuration options on instatiation, you can create
|
Instead of passing all configuration options on instantiation, you can create
|
||||||
your custom subclass. ::
|
your custom subclass:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
class FancyBar(Bar):
|
class FancyBar(Bar):
|
||||||
message = 'Loading'
|
message = 'Loading'
|
||||||
fill = '*'
|
fill = '*'
|
||||||
suffix = '%(percent).1f%% - %(eta)ds'
|
suffix = '%(percent).1f%% - %(eta)ds'
|
||||||
|
|
||||||
|
You can also override any of the arguments or create your own:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
class SlowBar(Bar):
|
||||||
|
suffix = '%(remaining_hours)d hours remaining'
|
||||||
|
@property
|
||||||
|
def remaining_hours(self):
|
||||||
|
return self.eta // 3600
|
||||||
|
|
||||||
|
|
||||||
Spinners
|
Spinners
|
||||||
========
|
========
|
||||||
|
|
||||||
For actions with an unknown number of steps you can use a spinner. ::
|
For actions with an unknown number of steps you can use a spinner:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
from progress.spinner import Spinner
|
from progress.spinner import Spinner
|
||||||
|
|
||||||
spinner = Spinner('Loading ')
|
spinner = Spinner('Loading ')
|
||||||
while state != 'FINISHED':
|
while state != 'FINISHED':
|
||||||
# Do some work
|
# Do some work
|
||||||
spinner.next()
|
spinner.next()
|
||||||
|
|
||||||
There are 4 predefined spinners:
|
There are 5 predefined spinners:
|
||||||
|
|
||||||
|
- ``Spinner``
|
||||||
|
- ``PieSpinner``
|
||||||
|
- ``MoonSpinner``
|
||||||
|
- ``LineSpinner``
|
||||||
|
- ``PixelSpinner``
|
||||||
|
|
||||||
|
Installation
|
||||||
|
============
|
||||||
|
|
||||||
|
Download from PyPi
|
||||||
|
|
||||||
|
.. code-block:: shell
|
||||||
|
|
||||||
|
pip install progress
|
||||||
|
|
||||||
- Spinner
|
|
||||||
- PieSpinner
|
|
||||||
- MoonSpinner
|
|
||||||
- LineSpinner
|
|
||||||
|
|
||||||
Other
|
Other
|
||||||
=====
|
=====
|
||||||
|
|
||||||
Thera are a number of other classes available too, please check the source or
|
There are a number of other classes available too, please check the source or
|
||||||
subclass one of them to create your own.
|
subclass one of them to create your own.
|
||||||
|
|
||||||
|
|
||||||
|
License
|
||||||
|
=======
|
||||||
|
|
||||||
|
progress is licensed under ISC
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# Copyright (c) 2012 Giorgos Verigakis <verigak@gmail.com>
|
# Copyright (c) 2012 Georgios Verigakis <verigak@gmail.com>
|
||||||
#
|
#
|
||||||
# Permission to use, copy, modify, and distribute this software for any
|
# Permission to use, copy, modify, and distribute this software for any
|
||||||
# purpose with or without fee is hereby granted, provided that the above
|
# purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -12,41 +12,77 @@
|
|||||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
from __future__ import division
|
from __future__ import division, print_function
|
||||||
|
|
||||||
|
from collections import deque
|
||||||
|
from datetime import timedelta
|
||||||
from math import ceil
|
from math import ceil
|
||||||
from sys import stderr
|
from sys import stderr
|
||||||
from time import time
|
try:
|
||||||
|
from time import monotonic
|
||||||
|
except ImportError:
|
||||||
|
from time import time as monotonic
|
||||||
|
|
||||||
|
|
||||||
__version__ = '1.1'
|
__version__ = '1.6.1'
|
||||||
|
|
||||||
|
HIDE_CURSOR = '\x1b[?25l'
|
||||||
|
SHOW_CURSOR = '\x1b[?25h'
|
||||||
|
|
||||||
|
|
||||||
class Infinite(object):
|
class Infinite(object):
|
||||||
file = stderr
|
file = stderr
|
||||||
|
sma_window = 10 # Simple Moving Average window
|
||||||
|
check_tty = True
|
||||||
|
hide_cursor = True
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, message='', **kwargs):
|
||||||
self.ctx = {}
|
|
||||||
for key, val in kwargs.items():
|
|
||||||
if hasattr(self, key):
|
|
||||||
setattr(self, key, val)
|
|
||||||
else:
|
|
||||||
self.ctx[key] = val
|
|
||||||
|
|
||||||
self.index = 0
|
self.index = 0
|
||||||
|
self.start_ts = monotonic()
|
||||||
self.avg = 0
|
self.avg = 0
|
||||||
self._ts = time()
|
self._avg_update_ts = self.start_ts
|
||||||
|
self._ts = self.start_ts
|
||||||
|
self._xput = deque(maxlen=self.sma_window)
|
||||||
|
for key, val in kwargs.items():
|
||||||
|
setattr(self, key, val)
|
||||||
|
|
||||||
def update_stats(self):
|
self._max_width = 0
|
||||||
# Calculate moving average
|
self._hidden_cursor = False
|
||||||
now = time()
|
self.message = message
|
||||||
dt = now - self._ts
|
|
||||||
self.avg = (dt + self.index * self.avg) / (self.index + 1) if self.avg else dt
|
|
||||||
self._ts = now
|
|
||||||
|
|
||||||
kv = [(key, val) for key, val in self.__dict__.items()
|
if self.file and self.is_tty():
|
||||||
if not key.startswith('_')]
|
if self.hide_cursor:
|
||||||
self.ctx.update(kv)
|
print(HIDE_CURSOR, end='', file=self.file)
|
||||||
|
self._hidden_cursor = True
|
||||||
|
self.writeln('')
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
if self._hidden_cursor:
|
||||||
|
print(SHOW_CURSOR, end='', file=self.file)
|
||||||
|
|
||||||
|
def __getitem__(self, key):
|
||||||
|
if key.startswith('_'):
|
||||||
|
return None
|
||||||
|
return getattr(self, key, None)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def elapsed(self):
|
||||||
|
return int(monotonic() - self.start_ts)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def elapsed_td(self):
|
||||||
|
return timedelta(seconds=self.elapsed)
|
||||||
|
|
||||||
|
def update_avg(self, n, dt):
|
||||||
|
if n > 0:
|
||||||
|
xput_len = len(self._xput)
|
||||||
|
self._xput.append(dt / n)
|
||||||
|
now = monotonic()
|
||||||
|
# update when we're still filling _xput, then after every second
|
||||||
|
if (xput_len < self.sma_window or
|
||||||
|
now - self._avg_update_ts > 1):
|
||||||
|
self.avg = sum(self._xput) / len(self._xput)
|
||||||
|
self._avg_update_ts = now
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
pass
|
pass
|
||||||
@@ -54,68 +90,89 @@ class Infinite(object):
|
|||||||
def start(self):
|
def start(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def writeln(self, line):
|
||||||
|
if self.file and self.is_tty():
|
||||||
|
width = len(line)
|
||||||
|
if width < self._max_width:
|
||||||
|
# Add padding to cover previous contents
|
||||||
|
line += ' ' * (self._max_width - width)
|
||||||
|
else:
|
||||||
|
self._max_width = width
|
||||||
|
print('\r' + line, end='', file=self.file)
|
||||||
|
self.file.flush()
|
||||||
|
|
||||||
def finish(self):
|
def finish(self):
|
||||||
pass
|
if self.file and self.is_tty():
|
||||||
|
print(file=self.file)
|
||||||
|
if self._hidden_cursor:
|
||||||
|
print(SHOW_CURSOR, end='', file=self.file)
|
||||||
|
self._hidden_cursor = False
|
||||||
|
|
||||||
|
def is_tty(self):
|
||||||
|
try:
|
||||||
|
return self.file.isatty() if self.check_tty else True
|
||||||
|
except AttributeError:
|
||||||
|
msg = "%s has no attribute 'isatty'. Try setting check_tty=False." % self
|
||||||
|
raise AttributeError(msg)
|
||||||
|
|
||||||
def next(self, n=1):
|
def next(self, n=1):
|
||||||
|
now = monotonic()
|
||||||
|
dt = now - self._ts
|
||||||
|
self.update_avg(n, dt)
|
||||||
|
self._ts = now
|
||||||
self.index = self.index + n
|
self.index = self.index + n
|
||||||
self.update_stats()
|
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def iter(self, it):
|
def iter(self, it):
|
||||||
for x in it:
|
self.iter_value = None
|
||||||
yield x
|
with self:
|
||||||
self.next()
|
for x in it:
|
||||||
|
self.iter_value = x
|
||||||
|
yield x
|
||||||
|
self.next()
|
||||||
|
del self.iter_value
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
self.start()
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||||
self.finish()
|
self.finish()
|
||||||
|
|
||||||
|
|
||||||
class Progress(Infinite):
|
class Progress(Infinite):
|
||||||
backtrack = False
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(Progress, self).__init__(*args, **kwargs)
|
super(Progress, self).__init__(*args, **kwargs)
|
||||||
self.max = kwargs.get('max', 100)
|
self.max = kwargs.get('max', 100)
|
||||||
self.eta = 0
|
|
||||||
|
|
||||||
def update_stats(self):
|
@property
|
||||||
self.progress = min(1, self.index / self.max)
|
def eta(self):
|
||||||
self.percent = self.progress * 100
|
return int(ceil(self.avg * self.remaining))
|
||||||
self.remaining = self.max - self.index
|
|
||||||
|
|
||||||
# Calculate moving average
|
@property
|
||||||
now = time()
|
def eta_td(self):
|
||||||
if self.delta:
|
return timedelta(seconds=self.eta)
|
||||||
dt = (now - self._ts) / self.delta
|
|
||||||
self.avg = (dt + self.index * self.avg) / (self.index + 1) if self.avg else dt
|
|
||||||
self.eta = int(ceil(self.avg * self.remaining))
|
|
||||||
self._ts = now
|
|
||||||
|
|
||||||
kv = [(key, val) for key, val in self.__dict__.items()
|
@property
|
||||||
if not key.startswith('_')]
|
def percent(self):
|
||||||
self.ctx.update(kv)
|
return self.progress * 100
|
||||||
|
|
||||||
|
@property
|
||||||
|
def progress(self):
|
||||||
|
if self.max == 0:
|
||||||
|
return 0
|
||||||
|
return min(1, self.index / self.max)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def remaining(self):
|
||||||
|
return max(self.max - self.index, 0)
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self.delta = 0
|
|
||||||
self.update_stats()
|
|
||||||
self.update()
|
|
||||||
|
|
||||||
def next(self, n=1):
|
|
||||||
prev = self.index
|
|
||||||
self.index = min(self.index + n, self.max)
|
|
||||||
self.delta = self.index - prev
|
|
||||||
self.update_stats()
|
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def goto(self, index):
|
def goto(self, index):
|
||||||
index = min(index, self.max)
|
incr = index - self.index
|
||||||
delta = index - self.index
|
self.next(incr)
|
||||||
if delta <= 0 and not self.backtrack:
|
|
||||||
return
|
|
||||||
|
|
||||||
self.index = index
|
|
||||||
self.delta = delta
|
|
||||||
self.update_stats()
|
|
||||||
self.update()
|
|
||||||
|
|
||||||
def iter(self, it):
|
def iter(self, it):
|
||||||
try:
|
try:
|
||||||
@@ -123,7 +180,10 @@ class Progress(Infinite):
|
|||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
for x in it:
|
self.iter_value = None
|
||||||
yield x
|
with self:
|
||||||
self.next()
|
for x in it:
|
||||||
self.finish()
|
self.iter_value = x
|
||||||
|
yield x
|
||||||
|
self.next()
|
||||||
|
del self.iter_value
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright (c) 2012 Giorgos Verigakis <verigak@gmail.com>
|
# Copyright (c) 2012 Georgios Verigakis <verigak@gmail.com>
|
||||||
#
|
#
|
||||||
# Permission to use, copy, modify, and distribute this software for any
|
# Permission to use, copy, modify, and distribute this software for any
|
||||||
# purpose with or without fee is hereby granted, provided that the above
|
# purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -14,28 +14,31 @@
|
|||||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
from . import Progress
|
from . import Progress
|
||||||
from .helpers import WritelnMixin
|
from .colors import color
|
||||||
|
|
||||||
|
|
||||||
class Bar(WritelnMixin, Progress):
|
class Bar(Progress):
|
||||||
width = 32
|
width = 32
|
||||||
message = ''
|
|
||||||
suffix = '%(index)d/%(max)d'
|
suffix = '%(index)d/%(max)d'
|
||||||
bar_prefix = ' |'
|
bar_prefix = ' |'
|
||||||
bar_suffix = '| '
|
bar_suffix = '| '
|
||||||
empty_fill = ' '
|
empty_fill = ' '
|
||||||
fill = '#'
|
fill = '#'
|
||||||
hide_cursor = True
|
color = None
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
filled_length = int(self.width * self.progress)
|
filled_length = int(self.width * self.progress)
|
||||||
empty_length = self.width - filled_length
|
empty_length = self.width - filled_length
|
||||||
|
|
||||||
message = self.message % self.ctx
|
message = self.message % self
|
||||||
bar = self.fill * filled_length
|
bar = color(self.fill * filled_length, fg=self.color)
|
||||||
empty = self.empty_fill * empty_length
|
empty = self.empty_fill * empty_length
|
||||||
suffix = self.suffix % self.ctx
|
suffix = self.suffix % self
|
||||||
line = ''.join([message, self.bar_prefix, bar, empty, self.bar_suffix,
|
line = ''.join([message, self.bar_prefix, bar, empty, self.bar_suffix,
|
||||||
suffix])
|
suffix])
|
||||||
self.writeln(line)
|
self.writeln(line)
|
||||||
@@ -45,39 +48,46 @@ class ChargingBar(Bar):
|
|||||||
suffix = '%(percent)d%%'
|
suffix = '%(percent)d%%'
|
||||||
bar_prefix = ' '
|
bar_prefix = ' '
|
||||||
bar_suffix = ' '
|
bar_suffix = ' '
|
||||||
empty_fill = u'∙'
|
empty_fill = '∙'
|
||||||
fill = u'█'
|
fill = '█'
|
||||||
|
|
||||||
|
|
||||||
class FillingSquaresBar(ChargingBar):
|
class FillingSquaresBar(ChargingBar):
|
||||||
empty_fill = u'▢'
|
empty_fill = '▢'
|
||||||
fill = u'▣'
|
fill = '▣'
|
||||||
|
|
||||||
|
|
||||||
class FillingCirclesBar(ChargingBar):
|
class FillingCirclesBar(ChargingBar):
|
||||||
empty_fill = u'◯'
|
empty_fill = '◯'
|
||||||
fill = u'◉'
|
fill = '◉'
|
||||||
|
|
||||||
|
|
||||||
class IncrementalBar(Bar):
|
class IncrementalBar(Bar):
|
||||||
phases = (u' ', u'▏', u'▎', u'▍', u'▌', u'▋', u'▊', u'▉', u'█')
|
if sys.platform.startswith('win'):
|
||||||
|
phases = (u' ', u'▌', u'█')
|
||||||
|
else:
|
||||||
|
phases = (' ', '▏', '▎', '▍', '▌', '▋', '▊', '▉', '█')
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
nphases = len(self.phases)
|
nphases = len(self.phases)
|
||||||
expanded_length = int(nphases * self.width * self.progress)
|
filled_len = self.width * self.progress
|
||||||
filled_length = int(self.width * self.progress)
|
nfull = int(filled_len) # Number of full chars
|
||||||
empty_length = self.width - filled_length
|
phase = int((filled_len - nfull) * nphases) # Phase of last char
|
||||||
phase = expanded_length - (filled_length * nphases)
|
nempty = self.width - nfull # Number of empty chars
|
||||||
|
|
||||||
message = self.message % self.ctx
|
message = self.message % self
|
||||||
bar = self.phases[-1] * filled_length
|
bar = color(self.phases[-1] * nfull, fg=self.color)
|
||||||
current = self.phases[phase] if phase > 0 else ''
|
current = self.phases[phase] if phase > 0 else ''
|
||||||
empty = self.empty_fill * max(0, empty_length - len(current))
|
empty = self.empty_fill * max(0, nempty - len(current))
|
||||||
suffix = self.suffix % self.ctx
|
suffix = self.suffix % self
|
||||||
line = ''.join([message, self.bar_prefix, bar, current, empty,
|
line = ''.join([message, self.bar_prefix, bar, current, empty,
|
||||||
self.bar_suffix, suffix])
|
self.bar_suffix, suffix])
|
||||||
self.writeln(line)
|
self.writeln(line)
|
||||||
|
|
||||||
|
|
||||||
|
class PixelBar(IncrementalBar):
|
||||||
|
phases = ('⡀', '⡄', '⡆', '⡇', '⣇', '⣧', '⣷', '⣿')
|
||||||
|
|
||||||
|
|
||||||
class ShadyBar(IncrementalBar):
|
class ShadyBar(IncrementalBar):
|
||||||
phases = (u' ', u'░', u'▒', u'▓', u'█')
|
phases = (' ', '░', '▒', '▓', '█')
|
||||||
|
|||||||
79
progress/colors.py
Normal file
79
progress/colors.py
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Copyright (c) 2020 Georgios Verigakis <verigak@gmail.com>
|
||||||
|
#
|
||||||
|
# Permission to use, copy, modify, and distribute this software for any
|
||||||
|
# purpose with or without fee is hereby granted, provided that the above
|
||||||
|
# copyright notice and this permission notice appear in all copies.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
|
|
||||||
|
COLORS = ('black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan',
|
||||||
|
'white')
|
||||||
|
STYLES = ('bold', 'faint', 'italic', 'underline', 'blink', 'blink2',
|
||||||
|
'negative', 'concealed', 'crossed')
|
||||||
|
|
||||||
|
|
||||||
|
def color(s, fg=None, bg=None, style=None):
|
||||||
|
sgr = []
|
||||||
|
|
||||||
|
if fg:
|
||||||
|
if fg in COLORS:
|
||||||
|
sgr.append(str(30 + COLORS.index(fg)))
|
||||||
|
elif isinstance(fg, int) and 0 <= fg <= 255:
|
||||||
|
sgr.append('38;5;%d' % int(fg))
|
||||||
|
else:
|
||||||
|
raise Exception('Invalid color "%s"' % fg)
|
||||||
|
|
||||||
|
if bg:
|
||||||
|
if bg in COLORS:
|
||||||
|
sgr.append(str(40 + COLORS.index(bg)))
|
||||||
|
elif isinstance(bg, int) and 0 <= bg <= 255:
|
||||||
|
sgr.append('48;5;%d' % bg)
|
||||||
|
else:
|
||||||
|
raise Exception('Invalid color "%s"' % bg)
|
||||||
|
|
||||||
|
if style:
|
||||||
|
for st in style.split('+'):
|
||||||
|
if st in STYLES:
|
||||||
|
sgr.append(str(1 + STYLES.index(st)))
|
||||||
|
else:
|
||||||
|
raise Exception('Invalid style "%s"' % st)
|
||||||
|
|
||||||
|
if sgr:
|
||||||
|
prefix = '\x1b[' + ';'.join(sgr) + 'm'
|
||||||
|
suffix = '\x1b[0m'
|
||||||
|
return prefix + s + suffix
|
||||||
|
else:
|
||||||
|
return s
|
||||||
|
|
||||||
|
|
||||||
|
# Foreground shortcuts
|
||||||
|
black = partial(color, fg='black')
|
||||||
|
red = partial(color, fg='red')
|
||||||
|
green = partial(color, fg='green')
|
||||||
|
yellow = partial(color, fg='yellow')
|
||||||
|
blue = partial(color, fg='blue')
|
||||||
|
magenta = partial(color, fg='magenta')
|
||||||
|
cyan = partial(color, fg='cyan')
|
||||||
|
white = partial(color, fg='white')
|
||||||
|
|
||||||
|
# Style shortcuts
|
||||||
|
bold = partial(color, style='bold')
|
||||||
|
faint = partial(color, style='faint')
|
||||||
|
italic = partial(color, style='italic')
|
||||||
|
underline = partial(color, style='underline')
|
||||||
|
blink = partial(color, style='blink')
|
||||||
|
blink2 = partial(color, style='blink2')
|
||||||
|
negative = partial(color, style='negative')
|
||||||
|
concealed = partial(color, style='concealed')
|
||||||
|
crossed = partial(color, style='crossed')
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright (c) 2012 Giorgos Verigakis <verigak@gmail.com>
|
# Copyright (c) 2012 Georgios Verigakis <verigak@gmail.com>
|
||||||
#
|
#
|
||||||
# Permission to use, copy, modify, and distribute this software for any
|
# Permission to use, copy, modify, and distribute this software for any
|
||||||
# purpose with or without fee is hereby granted, provided that the above
|
# purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -14,34 +14,34 @@
|
|||||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
from . import Infinite, Progress
|
from . import Infinite, Progress
|
||||||
from .helpers import WriteMixin
|
|
||||||
|
|
||||||
|
|
||||||
class Counter(WriteMixin, Infinite):
|
class Counter(Infinite):
|
||||||
message = ''
|
|
||||||
hide_cursor = True
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
self.write(str(self.index))
|
message = self.message % self
|
||||||
|
line = ''.join([message, str(self.index)])
|
||||||
|
self.writeln(line)
|
||||||
|
|
||||||
|
|
||||||
class Countdown(WriteMixin, Progress):
|
class Countdown(Progress):
|
||||||
hide_cursor = True
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
self.write(str(self.remaining))
|
message = self.message % self
|
||||||
|
line = ''.join([message, str(self.remaining)])
|
||||||
|
self.writeln(line)
|
||||||
|
|
||||||
|
|
||||||
class Stack(WriteMixin, Progress):
|
class Stack(Progress):
|
||||||
phases = (u' ', u'▁', u'▂', u'▃', u'▄', u'▅', u'▆', u'▇', u'█')
|
phases = (' ', '▁', '▂', '▃', '▄', '▅', '▆', '▇', '█')
|
||||||
hide_cursor = True
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
nphases = len(self.phases)
|
nphases = len(self.phases)
|
||||||
i = min(nphases - 1, int(self.progress * nphases))
|
i = min(nphases - 1, int(self.progress * nphases))
|
||||||
self.write(self.phases[i])
|
message = self.message % self
|
||||||
|
line = ''.join([message, self.phases[i]])
|
||||||
|
self.writeln(line)
|
||||||
|
|
||||||
|
|
||||||
class Pie(Stack):
|
class Pie(Stack):
|
||||||
phases = (u'○', u'◔', u'◑', u'◕', u'●')
|
phases = ('○', '◔', '◑', '◕', '●')
|
||||||
|
|||||||
@@ -1,91 +0,0 @@
|
|||||||
# Copyright (c) 2012 Giorgos Verigakis <verigak@gmail.com>
|
|
||||||
#
|
|
||||||
# Permission to use, copy, modify, and distribute this software for any
|
|
||||||
# purpose with or without fee is hereby granted, provided that the above
|
|
||||||
# copyright notice and this permission notice appear in all copies.
|
|
||||||
#
|
|
||||||
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
|
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
|
|
||||||
HIDE_CURSOR = '\x1b[?25l'
|
|
||||||
SHOW_CURSOR = '\x1b[?25h'
|
|
||||||
|
|
||||||
|
|
||||||
class WriteMixin(object):
|
|
||||||
hide_cursor = False
|
|
||||||
|
|
||||||
def __init__(self, message=None, **kwargs):
|
|
||||||
super(WriteMixin, self).__init__(**kwargs)
|
|
||||||
self._width = 0
|
|
||||||
if message:
|
|
||||||
self.message = message
|
|
||||||
|
|
||||||
if self.file.isatty():
|
|
||||||
if self.hide_cursor:
|
|
||||||
print(HIDE_CURSOR, end='', file=self.file)
|
|
||||||
print(self.message, end='', file=self.file)
|
|
||||||
self.file.flush()
|
|
||||||
|
|
||||||
def write(self, s):
|
|
||||||
if self.file.isatty():
|
|
||||||
b = '\b' * self._width
|
|
||||||
c = s.encode('utf8').ljust(self._width)
|
|
||||||
print(b + c, end='', file=self.file)
|
|
||||||
self._width = max(self._width, len(s))
|
|
||||||
self.file.flush()
|
|
||||||
|
|
||||||
def finish(self):
|
|
||||||
if self.file.isatty() and self.hide_cursor:
|
|
||||||
print(SHOW_CURSOR, end='', file=self.file)
|
|
||||||
|
|
||||||
|
|
||||||
class WritelnMixin(object):
|
|
||||||
hide_cursor = False
|
|
||||||
|
|
||||||
def __init__(self, message=None, **kwargs):
|
|
||||||
super(WritelnMixin, self).__init__(**kwargs)
|
|
||||||
if message:
|
|
||||||
self.message = message
|
|
||||||
|
|
||||||
if self.file.isatty() and self.hide_cursor:
|
|
||||||
print(HIDE_CURSOR, end='', file=self.file)
|
|
||||||
|
|
||||||
def clearln(self):
|
|
||||||
if self.file.isatty():
|
|
||||||
print('\r\x1b[K', end='', file=self.file)
|
|
||||||
|
|
||||||
def writeln(self, line):
|
|
||||||
if self.file.isatty():
|
|
||||||
self.clearln()
|
|
||||||
print(line.encode('utf8'), end='', file=self.file)
|
|
||||||
self.file.flush()
|
|
||||||
|
|
||||||
def finish(self):
|
|
||||||
if self.file.isatty():
|
|
||||||
print(file=self.file)
|
|
||||||
if self.hide_cursor:
|
|
||||||
print(SHOW_CURSOR, end='', file=self.file)
|
|
||||||
|
|
||||||
|
|
||||||
from signal import signal, SIGINT
|
|
||||||
from sys import exit
|
|
||||||
|
|
||||||
|
|
||||||
class SigIntMixin(object):
|
|
||||||
"""Registers a signal handler that calls finish on SIGINT"""
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
super(SigIntMixin, self).__init__(*args, **kwargs)
|
|
||||||
signal(SIGINT, self._sigint_handler)
|
|
||||||
|
|
||||||
def _sigint_handler(self, signum, frame):
|
|
||||||
self.finish()
|
|
||||||
exit(0)
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright (c) 2012 Giorgos Verigakis <verigak@gmail.com>
|
# Copyright (c) 2012 Georgios Verigakis <verigak@gmail.com>
|
||||||
#
|
#
|
||||||
# Permission to use, copy, modify, and distribute this software for any
|
# Permission to use, copy, modify, and distribute this software for any
|
||||||
# purpose with or without fee is hereby granted, provided that the above
|
# purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -14,27 +14,32 @@
|
|||||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
from . import Infinite
|
from . import Infinite
|
||||||
from .helpers import WriteMixin
|
|
||||||
|
|
||||||
|
|
||||||
class Spinner(WriteMixin, Infinite):
|
class Spinner(Infinite):
|
||||||
message = ''
|
|
||||||
phases = ('-', '\\', '|', '/')
|
phases = ('-', '\\', '|', '/')
|
||||||
hide_cursor = True
|
hide_cursor = True
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
i = self.index % len(self.phases)
|
i = self.index % len(self.phases)
|
||||||
self.write(self.phases[i])
|
message = self.message % self
|
||||||
|
line = ''.join([message, self.phases[i]])
|
||||||
|
self.writeln(line)
|
||||||
|
|
||||||
|
|
||||||
class PieSpinner(Spinner):
|
class PieSpinner(Spinner):
|
||||||
phases = [u'◷', u'◶', u'◵', u'◴']
|
phases = ['◷', '◶', '◵', '◴']
|
||||||
|
|
||||||
|
|
||||||
class MoonSpinner(Spinner):
|
class MoonSpinner(Spinner):
|
||||||
phases = [u'◑', u'◒', u'◐', u'◓']
|
phases = ['◑', '◒', '◐', '◓']
|
||||||
|
|
||||||
|
|
||||||
class LineSpinner(Spinner):
|
class LineSpinner(Spinner):
|
||||||
phases = [u'⎺', u'⎻', u'⎼', u'⎽', u'⎼', u'⎻']
|
phases = ['⎺', '⎻', '⎼', '⎽', '⎼', '⎻']
|
||||||
|
|
||||||
|
|
||||||
|
class PixelSpinner(Spinner):
|
||||||
|
phases = ['⣾', '⣷', '⣯', '⣟', '⡿', '⢿', '⣻', '⣽']
|
||||||
|
|||||||
39
pyproject.toml
Normal file
39
pyproject.toml
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
[build-system]
|
||||||
|
requires = ["setuptools >= 77.0.3"]
|
||||||
|
build-backend = "setuptools.build_meta"
|
||||||
|
|
||||||
|
[project]
|
||||||
|
name = "progress"
|
||||||
|
dynamic = ["version"]
|
||||||
|
description = "Easy to use progress bars"
|
||||||
|
readme = "README.rst"
|
||||||
|
authors = [{ name = "Georgios Verigakis", email = "verigak@gmail.com" }]
|
||||||
|
maintainers = [{ name = "Georgios Verigakis", email = "verigak@gmail.com" }]
|
||||||
|
license = "ISC"
|
||||||
|
license-files = ["LICENSE"]
|
||||||
|
requires-python = ">=3.6"
|
||||||
|
|
||||||
|
keywords = ["progress", "bar"]
|
||||||
|
classifiers = [
|
||||||
|
"Environment :: Console",
|
||||||
|
"Intended Audience :: Developers",
|
||||||
|
"Programming Language :: Python :: 3.6",
|
||||||
|
"Programming Language :: Python :: 3.7",
|
||||||
|
"Programming Language :: Python :: 3.8",
|
||||||
|
"Programming Language :: Python :: 3.9",
|
||||||
|
"Programming Language :: Python :: 3.10",
|
||||||
|
"Programming Language :: Python :: 3.11",
|
||||||
|
"Programming Language :: Python :: 3.12",
|
||||||
|
"Programming Language :: Python :: 3.13",
|
||||||
|
]
|
||||||
|
|
||||||
|
[project.urls]
|
||||||
|
Homepage = "https://github.com/verigak/progress/"
|
||||||
|
Repository = "https://github.com/verigak/progress.git"
|
||||||
|
Issues = "https://github.com/verigak/progress/issues"
|
||||||
|
|
||||||
|
[tool.setuptools]
|
||||||
|
packages = ["progress"]
|
||||||
|
|
||||||
|
[tool.setuptools.dynamic]
|
||||||
|
version = {attr = "progress.__version__"}
|
||||||
26
setup.py
26
setup.py
@@ -1,26 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
from setuptools import setup
|
|
||||||
|
|
||||||
import progress
|
|
||||||
|
|
||||||
|
|
||||||
setup(
|
|
||||||
name='progress',
|
|
||||||
version=progress.__version__,
|
|
||||||
description='Easy to use progress bars',
|
|
||||||
long_description=open('README.rst').read(),
|
|
||||||
author='Giorgos Verigakis',
|
|
||||||
author_email='verigak@gmail.com',
|
|
||||||
url='http://github.com/verigak/progress/',
|
|
||||||
license='ISC',
|
|
||||||
packages=['progress'],
|
|
||||||
classifiers=[
|
|
||||||
'Environment :: Console',
|
|
||||||
'Intended Audience :: Developers',
|
|
||||||
'License :: OSI Approved :: ISC License (ISCL)',
|
|
||||||
'Programming Language :: Python :: 2.6',
|
|
||||||
'Programming Language :: Python :: 2.7',
|
|
||||||
'Programming Language :: Python :: 3.3'
|
|
||||||
]
|
|
||||||
)
|
|
||||||
@@ -2,35 +2,51 @@
|
|||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
from random import randint
|
import random
|
||||||
from time import sleep
|
import time
|
||||||
|
|
||||||
from progress.bar import (Bar, ChargingBar, FillingSquaresBar,
|
from progress.bar import (Bar, ChargingBar, FillingSquaresBar,
|
||||||
FillingCirclesBar, IncrementalBar, ShadyBar)
|
FillingCirclesBar, IncrementalBar, PixelBar,
|
||||||
from progress.spinner import Spinner, PieSpinner, MoonSpinner, LineSpinner
|
ShadyBar)
|
||||||
|
from progress.spinner import (Spinner, PieSpinner, MoonSpinner, LineSpinner,
|
||||||
|
PixelSpinner)
|
||||||
from progress.counter import Counter, Countdown, Stack, Pie
|
from progress.counter import Counter, Countdown, Stack, Pie
|
||||||
|
from progress.colors import bold
|
||||||
|
|
||||||
|
|
||||||
for bar in (Bar, ChargingBar, FillingSquaresBar, FillingCirclesBar):
|
def sleep():
|
||||||
for i in bar(bar.__name__).iter(range(100)):
|
t = 0.01
|
||||||
sleep(0.04)
|
t += t * random.uniform(-0.1, 0.1) # Add some variance
|
||||||
|
time.sleep(t)
|
||||||
|
|
||||||
for bar in (IncrementalBar, ShadyBar):
|
|
||||||
for i in bar(bar.__name__).iter(range(200)):
|
|
||||||
sleep(0.02)
|
|
||||||
|
|
||||||
for spin in (Spinner, PieSpinner, MoonSpinner, LineSpinner):
|
for bar_cls in (Bar, ChargingBar, FillingSquaresBar, FillingCirclesBar):
|
||||||
for i in spin(spin.__name__ + ' ').iter(range(30)):
|
suffix = '%(index)d/%(max)d [%(elapsed)d / %(eta)d / %(eta_td)s] (%(iter_value)s)'
|
||||||
sleep(0.1)
|
bar = bar_cls(bar_cls.__name__, suffix=suffix)
|
||||||
print()
|
for i in bar.iter(range(200, 400)):
|
||||||
|
sleep()
|
||||||
|
|
||||||
|
for bar_cls in (IncrementalBar, PixelBar, ShadyBar):
|
||||||
|
suffix = '%(percent)d%% [%(elapsed_td)s / %(eta)d / %(eta_td)s]'
|
||||||
|
with bar_cls(bar_cls.__name__, suffix=suffix, max=200) as bar:
|
||||||
|
for i in range(200):
|
||||||
|
bar.next()
|
||||||
|
sleep()
|
||||||
|
|
||||||
|
bar = IncrementalBar(bold('Colored'), color='green')
|
||||||
|
for i in bar.iter(range(200)):
|
||||||
|
sleep()
|
||||||
|
|
||||||
|
for spin in (Spinner, PieSpinner, MoonSpinner, LineSpinner, PixelSpinner):
|
||||||
|
for i in spin(spin.__name__ + ' %(index)d ').iter(range(100)):
|
||||||
|
sleep()
|
||||||
|
|
||||||
for singleton in (Counter, Countdown, Stack, Pie):
|
for singleton in (Counter, Countdown, Stack, Pie):
|
||||||
for i in singleton(singleton.__name__ + ' ').iter(range(100)):
|
for i in singleton(singleton.__name__ + ' ').iter(range(100)):
|
||||||
sleep(0.04)
|
sleep()
|
||||||
print()
|
|
||||||
|
|
||||||
bar = IncrementalBar('Random', backtrack=True, suffix='')
|
bar = IncrementalBar('Random', suffix='%(index)d')
|
||||||
for i in range(100):
|
for i in range(100):
|
||||||
bar.goto(randint(0, 100))
|
bar.goto(random.randint(0, 100))
|
||||||
sleep(0.1)
|
sleep()
|
||||||
bar.finish()
|
bar.finish()
|
||||||
|
|||||||
Reference in New Issue
Block a user