def __init__(self, term=None, max_value=100, width="25%", title_pos="left", title="Progress", num_rep="fraction", indent=0, filled_color=2, empty_color=7, back_color=None, filled_char=u' ', empty_char=u' ', start_char=u'', end_char=u'', fallback=True, fallback_empty_char=u'◯', fallback_filled_char=u'◉', force_color=None): self.cursor = Cursor(term) self.term = self.cursor.term self._measure_terminal() self._width_str = width self._max_value = max_value ensure(title_pos in ["left", "right", "above", "below"], ValueError, "Invalid choice for title position.") self._title_pos = title_pos self._title = title ensure(num_rep in ["fraction", "percentage"], ValueError, "num_rep must be either 'fraction' or 'percentage'.") self._num_rep = num_rep ensure(indent < self.columns, ValueError, "Indent must be smaller than terminal width.") self._indent = indent self._start_char = start_char self._end_char = end_char # Setup callables and characters depending on if terminal has # has color support if force_color is not None: supports_colors = force_color else: supports_colors = self._supports_colors(term=self.term, raise_err=not fallback, colors=(filled_color, empty_color)) if supports_colors: self._filled_char = filled_char self._empty_char = empty_char self._filled = self._get_format_callable(term=self.term, color=filled_color, back_color=back_color) self._empty = self._get_format_callable(term=self.term, color=empty_color, back_color=back_color) else: self._empty_char = fallback_empty_char self._filled_char = fallback_filled_char self._filled = self._empty = lambda s: s ensure( self.full_line_width <= self.columns, WidthOverflowError, "Attempting to initialize Bar with full_line_width {}; " "terminal has width of only {}.".format(self.full_line_width, self.columns))
def __init__(self, term=None, indent=4): self.cursor = Cursor(term) self.indent = indent