@@ -909,6 +909,75 @@ 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+
921+ class GranularBar (AutoWidthWidgetBase ):
922+ '''A progressbar that can display progress at a sub-character granularity
923+ by using multiple marker characters.
924+
925+ Examples of markers:
926+ - Smooth: ` ▏▎▍▌▋▊▉█` (default)
927+ - Bar: ` ▁▂▃▄▅▆▇█`
928+ - Snake: ` ▖▌▛█`
929+ - Fade in: ` ░▒▓█`
930+ - Dots: ` ⡀⡄⡆⡇⣇⣧⣷⣿`
931+ - Growing circles: ` .oO`
932+
933+ The markers can be accessed through GranularMarkers. GranularMarkers.dots
934+ for example
935+ '''
936+
937+ def __init__ (self , markers = GranularMarkers .smooth , left = '|' , right = '|' ,
938+ ** kwargs ):
939+ '''Creates a customizable progress bar.
940+
941+ markers - string of characters to use as granular progress markers. The
942+ first character should represent 0% and the last 100%.
943+ Ex: ` .oO`.
944+ left - string or callable object to use as a left border
945+ right - string or callable object to use as a right border
946+ '''
947+ self .markers = markers
948+ self .left = string_or_lambda (left )
949+ self .right = string_or_lambda (right )
950+
951+ AutoWidthWidgetBase .__init__ (self , ** kwargs )
952+
953+ def __call__ (self , progress , data , width ):
954+ left = converters .to_unicode (self .left (progress , data , width ))
955+ right = converters .to_unicode (self .right (progress , data , width ))
956+ width -= progress .custom_len (left ) + progress .custom_len (right )
957+
958+ if progress .max_value is not base .UnknownLength \
959+ and progress .max_value > 0 :
960+ percent = progress .value / progress .max_value
961+ else :
962+ percent = 0
963+
964+ num_chars = percent * width
965+
966+ marker = self .markers [- 1 ] * int (num_chars )
967+
968+ marker_idx = int ((num_chars % 1 ) * (len (self .markers ) - 1 ))
969+ if marker_idx :
970+ marker += self .markers [marker_idx ]
971+
972+ marker = converters .to_unicode (marker )
973+
974+ # Make sure we ignore invisible characters when filling
975+ width += len (marker ) - progress .custom_len (marker )
976+ marker = marker .ljust (width , self .markers [0 ])
977+
978+ return left + marker + right
979+
980+
912981class FormatLabelBar (FormatLabel , Bar ):
913982 '''A bar which has a formatted label in the center.'''
914983 def __init__ (self , format , ** kwargs ):
0 commit comments