Skip to content

Commit c6323cc

Browse files
author
Olivier Brunel
committed
Add remaining bar character
1 parent 949cdf0 commit c6323cc

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

ProgressBar.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@
33
# TO USE IN YOUR CODE
44
#from folder.ProgressBar import ProgressBar
55

6+
# Class: ProgressBar
7+
# Role: Set progress bar parameters and define its printing functions
68
class ProgressBar:
79
def __init__(self,
810
pretext=r"", # Text to print before the bar
911
progresschar=r"█", # Character to show progress
12+
remainingbarchar=r" ", # Character to fill the remaining bar with
1013
loadingchars=r"█▓▒░▒▓", # Last character of bar moving as bar loads (moves even if no progress)
11-
startendchar=r"||", # Characters going around the bar
14+
startendchar=r"||", # The two characters going around the bar
1215
barwidth=int(os.get_terminal_size().columns/2), # Length of the bar in characters (does not include what's around the bar)
1316
displaypercentage=False, # Show percentage as well or not
1417
displaycount=False # Show count as well or not
1518
):
1619
self.pretext = str(pretext)
1720
self.progresschar = str(progresschar)
21+
self.remainingbarchar = str(remainingbarchar)
1822
self.loadingchars = loadingchars
1923
self.startendchar = str(startendchar)
2024
self.barwidth = int(barwidth)
2125
self.displaypercentage = displaypercentage
2226
self.displaycount = displaycount
2327

24-
# loadingchars ideas
25-
# characters = "-/|\"
26-
# characters = ["-_="]
27-
2828
# Private
2929
self.loadingcharsindex = 0
3030
self.firstprint = True
@@ -87,7 +87,7 @@ def print(self,number,max):
8787
self.loadingcharsindex = (self.loadingcharsindex+1) % len(self.loadingchars)
8888
remainingbar -= 1
8989
#Add remaining gap
90-
barstring += remainingbar*" "
90+
barstring += remainingbar*self.remainingbarchar
9191
#End char
9292
if self.startendchar:
9393
if len(self.startendchar) >= 2:

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ for i in range(0,max)
3737
You can give the following optional arguments to the ProgressBar constructor:
3838
- pretext: Text to print before the bar (default "")
3939
- progresschar: Character to show progress (default '█')
40+
- remainingbarchar: Character to fill the remaining bar with (default ' ')
4041
- loadingchars: Last character of bar moving as bar loads (moves even if no progress) (default "█▓▒░▒▓")
41-
- startendchar: Characters going around the bar (default "||")
42+
- startendchar: The two characters going around the bar (default "||")
4243
- barwidth: Length of the bar in characters (does not include optionally printed pretext, progresschar, percentage and count) (default terminal width/2)
4344
- displaypercentage: Show percentage as well or not (default False)
4445
- displaycount: Show count as well or not (default False)

0 commit comments

Comments
 (0)