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