aboutsummaryrefslogtreecommitdiff
path: root/pixelterm/xtermcolors.py
diff options
context:
space:
mode:
authorjaseg <s@jaseg.de>2013-09-16 15:33:01 +0200
committerjaseg <s@jaseg.de>2013-09-16 15:33:01 +0200
commit82cac0a5a211d573190253d3b40f89892bda713f (patch)
treeba67fa903d6b78c182df8b155e30ca46565e360b /pixelterm/xtermcolors.py
parented223febd651ea32bf784fb054ecb5082276cc6b (diff)
downloadpixelterm-82cac0a5a211d573190253d3b40f89892bda713f.tar.gz
pixelterm-82cac0a5a211d573190253d3b40f89892bda713f.tar.bz2
pixelterm-82cac0a5a211d573190253d3b40f89892bda713f.zip
Fixed script installation
Diffstat (limited to 'pixelterm/xtermcolors.py')
-rw-r--r--pixelterm/xtermcolors.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/pixelterm/xtermcolors.py b/pixelterm/xtermcolors.py
new file mode 100644
index 0000000..36cddc6
--- /dev/null
+++ b/pixelterm/xtermcolors.py
@@ -0,0 +1,21 @@
+
+xterm_colors = []
+
+# This is ripped out of pygments
+# I leave out the 16 standard colors since people tend to re-define them to their liking.
+
+# colors 16..232: the 6x6x6 color cube
+_valuerange = (0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff)
+for i in range(217):
+ r = _valuerange[(i // 36) % 6]
+ g = _valuerange[(i // 6) % 6]
+ b = _valuerange[i % 6]
+ xterm_colors.append((r, g, b))
+
+# colors 233..253: grayscale
+for i in range(1, 24):
+ v = 8 + i * 10
+ xterm_colors.append((v, v, v))
+
+def closest_color(r, g, b):
+ return 16+min([ ((r-rt)**2+(g-gt)**2+(b-bt)**2, i) for i,(rt,gt,bt) in enumerate(xterm_colors) ])[1]