xiwal

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

commit
26feb2ee9c8a121fe3b666cfec06a1b82b59fc4c
parent
53fa3d7e14da2b0b1dab9c0758d6b097cd779bae
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2026-02-19 12:30
use both normal and bright colors for 256 schema

Diffstat

M xiwal/scheme.py 35 ++++++++++++++++++++++++++++++++++-

1 files changed, 34 insertions, 1 deletions


diff --git a/xiwal/scheme.py b/xiwal/scheme.py

@@ -103,10 +103,43 @@ def _colors2scheme(colors):
  103   103     return list(scheme(subset, dominant))
  104   104 
  105   105 
   -1   106 def get_primary(black, white, dark, light):
   -1   107     """Find a primary so that dark and light can be mixed from it."""
   -1   108 
   -1   109     l, c, h = lch.mix(dark, light, 0.5)
   -1   110 
   -1   111     try:
   -1   112         l = (
   -1   113             (
   -1   114                 (white[1] - black[1]) * (dark[0] - black[0]) * (light[0] - white[0])
   -1   115                 + (dark[1] - black[1]) * (light[0] - white[0]) * black[0]
   -1   116                 - (light[1] - white[1]) * (dark[0] - black[0]) * white[0]
   -1   117             ) / (
   -1   118                 (dark[1] - black[1]) * (light[0] - white[0])
   -1   119                 - (light[1] - white[1]) * (dark[0] - black[0])
   -1   120             )
   -1   121         )
   -1   122         l = min(max(l, dark[0]), light[0])
   -1   123     except ZeroDivisionError:
   -1   124         pass
   -1   125 
   -1   126     try:
   -1   127         c = black[1] + (dark[1] - black[1]) * (l - black[0]) / (dark[0] - black[0])
   -1   128         c = min(max(c, dark[1], light[1]), 1)
   -1   129     except ZeroDivisionError:
   -1   130         pass
   -1   131 
   -1   132     return l, c, h
   -1   133 
   -1   134 
  106   135 def expand_to_256(s):
  107   136     # https://github.com/jake-stewart/color256/
  108   137     full = [*s]
  109    -1     base8 = [s[0], *[s[i] for i in range(1, 7)], s[15]]
   -1   138     base8 = [
   -1   139         s[0],
   -1   140         *[get_primary(s[0], s[15], s[i], s[i + 8]) for i in range(1, 7)],
   -1   141         s[15],
   -1   142     ]
  110   143 
  111   144     for r in range(6):
  112   145         c0 = lch.mix(base8[0], base8[1], r / 5)