@@ -1720,7 +1720,7 @@ class bar:
17201720
17211721 width (int): The width of the bar in characters when value is 1.
17221722
1723- full_width (bool):
1723+ pad (bool):
17241724 Whether bar should be rendered to fill the whole width using
17251725 trailing spaces. This is useful if anything follows the bar on its
17261726 line, such as if you wish to mark the end of the bar.
@@ -1736,15 +1736,15 @@ class bar:
17361736 Common values are '➔', '∎', '►', '▞', '▋▍▎▏' or '>>>'.
17371737
17381738 When rendered within a string you can specify a format that overrides the
1739- above arguments. The format strings take the form *WFCO * where:
1739+ above arguments. The format strings take the form *WPCO * where:
17401740
17411741 - *W* is an integer that overrides *width*.
1742- - *F * is either 'f ' or 'F ' overrides *full_width *; is true if capitalized.
1742+ - *P * is either 'p ' or 'P ' overrides *pad *; is true if capitalized.
17431743 - *C* is a simple real number, 1 or greater.
17441744 - *O* is an arbitrary string that becomes the overflow marker.
17451745
1746- The format fields are optional, but if one is given, the one listed before
1747- it must also be given .
1746+ The format fields are optional, but if you want to specify *W* and *C* you
1747+ also need to also specify *P* to separate them .
17481748
17491749 **Examples**::
17501750
@@ -1753,7 +1753,7 @@ class bar:
17531753 >>> assets = {'property': 13_194, 'cash': 2846, 'equities': 19_301}
17541754 >>> total = sum(assets.values())
17551755 >>> for key, value in assets.items():
1756- ... display(f"{key:>8}: ❭{bar(value/total):60F }❬")
1756+ ... display(f"{key:>8}: ❭{bar(value/total):60P }❬")
17571757 property: ❭██████████████████████▍ ❬
17581758 cash: ❭████▊ ❬
17591759 equities: ❭████████████████████████████████▊ ❬
@@ -1763,32 +1763,32 @@ class bar:
17631763 maximum life the overflow marker is added to the end of the bar, which adds
17641764 a few vertical bars, a newline, and 20 spaced of indent.
17651765
1766- >>> hours = dict(drill01 =6, drill02 =34, drill03 =89, drill04 =57)
1766+ >>> hours = dict(unit_1 =6, unit_2 =34, unit_3 =89, unit_4 =57)
17671767 >>> max_life = 40
17681768 >>> for name, life in hours.items():
1769- ... print(f"{bar(life/max_life):20F2 ▋▍▎▏\n }", name)
1770- ███ drill01
1771- █████████████████ drill02
1769+ ... print(f"{bar(life/max_life):20P2 ▋▍▎▏\n }", name)
1770+ ███ unit_1
1771+ █████████████████ unit_2
17721772 ████████████████████████████████████████▋▍▎▏
1773- drill03
1774- ████████████████████████████▌ drill04
1773+ unit_3
1774+ ████████████████████████████▌ unit_4
17751775
17761776 """
1777- def __init__ (self , value , width = 72 , full_width = False , clip = 1 , overflow = False ):
1777+ def __init__ (self , value , width = 72 , pad = False , clip = 1 , overflow = False ):
17781778 self .value = value
17791779 self .width = width
1780- self .full_width = full_width
1780+ self .pad = pad
17811781 self .clip = clip
17821782 self .overflow = overflow or ''
17831783
1784- def render (self , value = None , width = None , full_width = None , clip = None , overflow = None ):
1784+ def render (self , value = None , width = None , pad = None , clip = None , overflow = None ):
17851785 """Render bar to string
17861786
17871787 Arguments given override those specified when class was instantiated.
17881788 """
17891789 value = self .value if value is None else value
17901790 width = self .width if width is None else width
1791- full_width = self .full_width if full_width is None else full_width
1791+ pad = self .pad if pad is None else pad
17921792 clip = self .clip if clip is None else clip
17931793 overflow = self .overflow if overflow is None else overflow
17941794
@@ -1800,31 +1800,31 @@ def render(self, value=None, width=None, full_width=None, clip=None, overflow=No
18001800 else :
18011801 last = BAR_CHARS [frac - 1 :frac ]
18021802 bar = buckets * BAR_CHARS [- 1 ] + last
1803- if full_width :
1803+ if pad :
18041804 bar += (width - len (bar ))* ' '
18051805 return bar
18061806
18071807 def __format__ (self , formatter ):
1808- # format strings take the form WFCO where:
1808+ # format strings take the form WPCO where:
18091809 # W is an integer indicating desired width
1810- # F is either 'f ' or 'F ' for full_width , cap is true
1810+ # P is either 'p ' or 'P ' for pad , cap is true
18111811 # C is a simple real number, 1 or greater.
18121812 # O is an arbitrary string that will be used as overflow marker
1813- value = width = full_width = clip = overflow = None
1813+ value = width = pad = clip = overflow = None
18141814 if formatter :
1815- match = re .match (r'(\d*)([fF ]?)(\d\.?\d*)?(.*)\Z' , formatter , re .S )
1815+ match = re .match (r'(\d*)([pP ]?)(\d\.?\d*)?(.*)\Z' , formatter , re .S )
18161816 try :
18171817 if match [1 ]:
18181818 width = int (match [1 ])
1819- if 'f ' in match [2 ]:
1820- full_width = False
1821- if 'F ' in match [2 ]:
1822- full_width = True
1819+ if 'p ' in match [2 ]:
1820+ pad = False
1821+ if 'P ' in match [2 ]:
1822+ pad = True
18231823 clip = float (match [3 ]) if match [3 ] else None
18241824 overflow = match [4 ] or None
18251825 except (TypeError , ValueError ):
18261826 warn ('invalid format string' )
1827- return self .render (value , width , full_width , clip , overflow )
1827+ return self .render (value , width , pad , clip , overflow )
18281828
18291829 def __str__ (self ):
18301830 return self .render ()
0 commit comments