Skip to content

Commit

Permalink
support hex colours
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Sep 27, 2020
1 parent afe9ad8 commit 8baa057
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.rst
Expand Up @@ -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
~~~~~~~~~~~~~~~~~
Expand Down
20 changes: 10 additions & 10 deletions tqdm/std.py
Expand Up @@ -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

Expand Down Expand Up @@ -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
-------
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tqdm/tqdm.1
Expand Up @@ -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
Expand Down

0 comments on commit 8baa057

Please sign in to comment.