Skip to content

Commit 4228693

Browse files
committed
Added class for easy granular marker configuration
1 parent 13a1d7a commit 4228693

4 files changed

Lines changed: 20 additions & 5 deletions

File tree

examples.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,10 @@ def multi_progress_bar_example(left=True):
176176
bar.update(progress, jobs=jobs, force=True)
177177
time.sleep(0.02)
178178

179+
179180
@example
180181
def granular_progress_example():
181-
widgets=[
182+
widgets = [
182183
progressbar.GranularBar(markers=" ▏▎▍▌▋▊▉█", left='', right='|'),
183184
progressbar.GranularBar(markers=" ▁▂▃▄▅▆▇█", left='', right='|'),
184185
progressbar.GranularBar(markers=" ▖▌▛█", left='', right='|'),

progressbar/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def __init__(self, target, capturing=False, listeners=set()):
192192
self.listeners = listeners
193193
self.needs_clear = False
194194

195-
def isatty(self):
195+
def isatty(self): # pragma: no cover
196196
return self.target.isatty()
197197

198198
def write(self, value):

progressbar/widgets.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,15 @@ def get_values(self, progress, data):
909909
return ranges
910910

911911

912+
class GranularMarkers:
913+
smooth = ' ▏▎▍▌▋▊▉█'
914+
bar = ' ▁▂▃▄▅▆▇█'
915+
snake = ' ▖▌▛█'
916+
fade_in = ' ░▒▓█'
917+
dots = ' ⡀⡄⡆⡇⣇⣧⣷⣿'
918+
growing_circles = ' .oO'
919+
920+
912921
class GranularBar(AutoWidthWidgetBase):
913922
'''A progressbar that can display progress at a sub-character granularity
914923
by using multiple marker characters.
@@ -920,14 +929,18 @@ class GranularBar(AutoWidthWidgetBase):
920929
- Fade in: ` ░▒▓█`
921930
- Dots: ` ⡀⡄⡆⡇⣇⣧⣷⣿`
922931
- Growing circles: ` .oO`
932+
933+
The markers can be accessed through GranularMarkers. GranularMarkers.dots
934+
for example
923935
'''
924936

925-
def __init__(self, markers=' ▏▎▍▌▋▊▉█', left='|', right='|', **kwargs):
937+
def __init__(self, markers=GranularMarkers.smooth, left='|', right='|',
938+
**kwargs):
926939
'''Creates a customizable progress bar.
927940
928941
markers - string of characters to use as granular progress markers. The
929942
first character should represent 0% and the last 100%.
930-
Ex: ` .oO`
943+
Ex: ` .oO`.
931944
left - string or callable object to use as a left border
932945
right - string or callable object to use as a right border
933946
'''

tests/test_monitor_progress.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ def test_granular_bar(testdir):
213213
items=list(range(5)),
214214
)))
215215
pprint.pprint(result.stderr.lines, width=70)
216-
assert result.stderr.lines == [u'',
216+
assert result.stderr.lines == [
217+
u'',
217218
u'| |',
218219
u'|OOOOOOOOOOO. |',
219220
u'|OOOOOOOOOOOOOOOOOOOOOOO |',

0 commit comments

Comments
 (0)