From 8baa057e6074196cc57c4e03fba8df8674407bd3 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Sun, 27 Sep 2020 19:37:50 +0100 Subject: [PATCH] support hex colours --- README.rst | 4 ++-- tqdm/std.py | 20 ++++++++++---------- tqdm/tqdm.1 | 6 +++--- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README.rst b/README.rst index 11624441f..17cf93614 100644 --- a/README.rst +++ b/README.rst @@ -460,8 +460,8 @@ Parameters The screen height. If specified, hides nested bars outside this bound. If unspecified, attempts to use environment height. The fallback is 20. -* colour : str or tuple, optional - Bar colour. May be RGB tuple: ``(0, 255, 0) == "GREEN"``. +* colour : str, optional + Bar colour (e.g. ``'green'``, ``'#00ff00'``). Extra CLI Options ~~~~~~~~~~~~~~~~~ diff --git a/tqdm/std.py b/tqdm/std.py index b8a496a81..217e809db 100644 --- a/tqdm/std.py +++ b/tqdm/std.py @@ -166,16 +166,16 @@ def colour(self, value): self._colour = None return try: - if len(value) == 3: - self._colour = self.COLOUR_RGB % value - elif value.upper() in self.COLOURS: + if value.upper() in self.COLOURS: self._colour = self.COLOURS[value.upper()] + elif value[0] == '#' and len(value) == 7: + self._colour = self.COLOUR_RGB % tuple( + int(i, 16) for i in (value[1:3], value[3:5], value[5:7])) else: raise KeyError except (KeyError, AttributeError): - warn(("Unknown colour (%s); valid choices:" - " [(0-255, 0-255, 0-255), %s]") % ( - value, ", ".join(self.COLOURS)), + warn("Unknown colour (%s); valid choices: [hex (#00ff00), %s]" % ( + value, ", ".join(self.COLOURS)), TqdmWarning, stacklevel=2) self._colour = None @@ -399,8 +399,8 @@ def format_meter(n, total, elapsed, ncols=None, prefix='', ascii=False, [default: 1000], ignored unless `unit_scale` is True. initial : int or float, optional The initial counter value [default: 0]. - colour : str or tuple, optional - Bar colour. May be RGB tuple: `(0, 255, 0) == "GREEN"`. + colour : str, optional + Bar colour (e.g. `'green'`, `'#00ff00'`). Returns ------- @@ -944,8 +944,8 @@ def __init__(self, iterable=None, desc=None, total=None, leave=True, The screen height. If specified, hides nested bars outside this bound. If unspecified, attempts to use environment height. The fallback is 20. - colour : str or tuple, optional - Bar colour. May be RGB tuple: `(0, 255, 0) == "GREEN"`. + colour : str, optional + Bar colour (e.g. `'green'`, `'#00ff00'`). gui : bool, optional WARNING: internal parameter - do not use. Use tqdm.gui.tqdm(...) instead. If set, will attempt to use diff --git a/tqdm/tqdm.1 b/tqdm/tqdm.1 index ab2e7c963..672cd2bfd 100644 --- a/tqdm/tqdm.1 +++ b/tqdm/tqdm.1 @@ -228,9 +228,9 @@ The fallback is 20. .RE .TP .B \-\-colour=\f[I]colour\f[] -str or tuple, optional. -Bar colour. -May be RGB tuple: \f[C](0,\ 255,\ 0)\ ==\ "GREEN"\f[]. +str, optional. +Bar colour (e.g. +\f[C]\[aq]green\[aq]\f[], \f[C]\[aq]#00ff00\[aq]\f[]). .RS .RE .TP