Exemple #1
0
    def __format__(self, width):
        if not width:
            width = 50

        bar_width = int(width) - 2
        tmp = (((self.counter * 100.0) / self.total) * bar_width) / 100
        bar = self.filler[-1] * int(tmp)
        rest = tmp % 1
        if rest:
            bar += self.filler[int((tmp % 1) * len(self.filler))]

        return Formatter().format(self.template, bar=bar, bar_width=bar_width)
Exemple #2
0
 def __init__(self,
              total,
              template='{i}/{total} {bar:fill}',
              out=sys.stdout):
     self.total = total
     self.template = text_type(template)
     self.enabled_widgets = list(self._get_widgets())
     self.terminal_width = get_terminal_width()
     self.fmt = Formatter(self.terminal_width)
     self.start_time = time.time()
     self.counter = 1
     self.out = out
     self.render()
Exemple #3
0
def bar(iterator, template='{i}/{total} {bar:fill}', total=None):
    if total is None:
        total = len(iterator)

    # Make sure that template is unicode
    template = str(template)

    enabled_widgets = list(get_widgets(template, iterator, total))
    terminal_width = get_terminal_width()
    fmt = Formatter(terminal_width)
    start_time = time.time()

    for i, value in enumerate(iterator):
        elapsed = time.time() - start_time
        kwargs = {w.name: w(i + 1, total, elapsed) for w in enabled_widgets}
        iprint(fmt.format(template, **kwargs))

        yield value
Exemple #4
0
 def setUp(self):
     self.formatter = Formatter()