xiwal

Generate terminal color schemes
git clone https://git.ce9e.org/xiwal.git

commit
f9dafb6dca0fc126a3ba2164b0e0ced26a219fae
parent
cc517405234c5152f16e8d3ce80d823efc1f2e0e
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2019-11-15 08:18
more flexible hex parsing

Diffstat

M wal/lch.py 14 +++++++++++---

1 files changed, 11 insertions, 3 deletions


diff --git a/wal/lch.py b/wal/lch.py

@@ -105,9 +105,17 @@ def format_hex(rgb):
  105   105 
  106   106 
  107   107 def parse_hex(s):
  108    -1 	r = int(s[1:3], 16)
  109    -1 	g = int(s[3:5], 16)
  110    -1 	b = int(s[5:7], 16)
   -1   108 	s = s.lstrip('#')
   -1   109 	if len(s) == 6:
   -1   110 		r = int(s[0:2], 16)
   -1   111 		g = int(s[2:4], 16)
   -1   112 		b = int(s[4:6], 16)
   -1   113 	elif len(s) == 3:
   -1   114 		r = int(s[0], 16) * 17
   -1   115 		g = int(s[1], 16) * 17
   -1   116 		b = int(s[2], 16) * 17
   -1   117 	else:
   -1   118 		raise ValueError('Invalid hex color: %s' % s)
  111   119 	return r, g, b
  112   120 
  113   121