Exemplo n.º 1
0
    def get_bar(self):
        """
        calculate and return progress bar string
        """
        # Get terminal size
        try:
            width, height = console.get_terminal_size()
        except IOError:
            # Fallback to default values
            width, height = (80, 37)

        # Bar should be half a terminal width
        self.bar_width = width / 2

        # Calculate step size
        part_size = float(self.bar_width) / float(self.main.items_count)
        bar_size = int(part_size * self.main.items_done)

        info = {
            'bar_start': self.bar_start,
            'progress_start': self.progress_start,
            'bar': '%s%s' % (bar_size * self.progress_part, self.progress_end),
            'bar_width': self.bar_width,
            'bar_end': self.bar_end
        }
        render = '{bar_start}{progress_start}{bar:<{bar_width}}{bar_end}'.format(
            **info)

        return render
Exemplo n.º 2
0
    def get_bar(self):
        """
        calculate and return progress bar string
        """
        # Get terminal size
        try:
            width, height = console.get_terminal_size()
        except IOError:
            # Fallback to default values
            width, height = (80, 37)

        # Bar should be half a terminal width
        self.bar_width = width / 2

        # Calculate step size
        part_size = float(self.bar_width) / float(self.main.items_count)
        bar_size  = int(part_size * self.main.items_done)

        info = {
            'bar_start' : self.bar_start,
            'progress_start' : self.progress_start,
            'bar' : '%s%s' % (bar_size * self.progress_part, self.progress_end),
            'bar_width': self.bar_width,
            'bar_end' : self.bar_end
        }
        render = '{bar_start}{progress_start}{bar:<{bar_width}}{bar_end}'.format(**info)

        return render
Exemplo n.º 3
0
    def run(self):
        """
        Run thread
        While we have undone items, print progressbar
        """
        while self.items_done < self.items_count:
            # Cleanup to fix progress after terminal resize
            try:
                width, height = console.get_terminal_size()
            except IOError:
                # Fallback to default values
                width, height = (80, 37)
            sys.stdout.write('\r%s' % (width * ' '))

            # Write progress
            sys.stdout.write('\r %s' % self.get_progress())
            sys.stdout.flush()
            time.sleep(self.speed)
Exemplo n.º 4
0
    def run(self):
        """
        Run thread
        While we have undone items, print progressbar
        """
        while self.items_done < self.items_count:
            # Cleanup to fix progress after terminal resize
            try:
                width, height = console.get_terminal_size()
            except IOError:
                # Fallback to default values
                width, height = (80, 37)
            sys.stdout.write('\r%s' % (width * ' '))

            # Write progress
            sys.stdout.write('\r %s' % self.get_progress())
            sys.stdout.flush()
            time.sleep(self.speed)