mirror of
https://github.com/caelestia-dots/cli.git
synced 2026-06-05 23:09:27 -05:00
scheme: auto adjust
This commit is contained in:
Executable
+27
@@ -0,0 +1,27 @@
|
||||
#!/bin/python3
|
||||
|
||||
import sys
|
||||
from colorsys import rgb_to_hls, hls_to_rgb
|
||||
|
||||
def hex_to_rgb(hex: str) -> tuple[int, int, int]:
|
||||
"""Convert a hex string to an RGB tuple in the range [0, 1]."""
|
||||
return tuple(int(hex[i:i+2], 16) / 255 for i in (0, 2, 4))
|
||||
|
||||
def hex_to_hls(hex: str) -> tuple[float, float, float]:
|
||||
return rgb_to_hls(*hex_to_rgb(hex))
|
||||
|
||||
def adjust_saturation(hex: str, amount: float,) -> str:
|
||||
h, l, s = hex_to_hls(hex)
|
||||
s = max(0, min(1, s + amount))
|
||||
return "".join(f"{round(i * 255):02X}" for i in hls_to_rgb(h, l, s))
|
||||
|
||||
if __name__ == "__main__":
|
||||
light = sys.argv[1] == "light"
|
||||
|
||||
added_sat = 0.25 if light else 0.1
|
||||
|
||||
for colour in sys.argv[3].split(" ")[1:]:
|
||||
print(adjust_saturation(colour, added_sat))
|
||||
|
||||
for layer in sys.argv[4:]:
|
||||
print(layer.split(" ")[0])
|
||||
+6
-12
@@ -11,9 +11,6 @@ set -l src (dirname (status filename))
|
||||
|
||||
. $src/../util.fish
|
||||
|
||||
set -l colour_names rosewater flamingo pink mauve red maroon peach yellow green teal sky sapphire blue lavender
|
||||
set -l layer_names text subtext1 subtext0 overlay2 overlay1 overlay0 surface2 surface1 surface0 base mantle crust
|
||||
|
||||
test -f "$argv[1]" && set -l img "$argv[1]" || set -l img $CACHE/wallpaper/current
|
||||
set -l img (realpath $img)
|
||||
|
||||
@@ -29,14 +26,11 @@ end
|
||||
|
||||
test "$(cat $CACHE/scheme/current.txt)" = dynamic && gsettings set org.gnome.desktop.interface color-scheme \'prefer-$colour_scheme\'
|
||||
|
||||
set -l colours_raw (okolors $img -k 15 -w 0 -l $light_vals)
|
||||
set -l colours (string split ' ' $colours_raw[2])[2..]
|
||||
set -l layers (nl-echo $colours_raw | cut -f 1 -d ' ')[3..]
|
||||
# 2nd line except first element is the palette
|
||||
# The first element in lines 3+ are the layers
|
||||
set -l names rosewater flamingo pink mauve red maroon peach yellow green teal sky sapphire blue lavender text subtext1 subtext0 overlay2 overlay1 overlay0 surface2 surface1 surface0 base mantle crust
|
||||
set -l colours ($src/autoadjust.py $colour_scheme (okolors $img -k 15 -w 0 -l $light_vals))
|
||||
|
||||
for i in (seq 1 (count $colour_names))
|
||||
echo "$colour_names[$i] $colours[$i]"
|
||||
end
|
||||
|
||||
for i in (seq 1 (count $layer_names))
|
||||
echo "$layer_names[$i] $layers[$i]"
|
||||
for i in (seq 1 (count $colours))
|
||||
echo "$names[$i] $colours[$i]"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user