mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-08 06:25:37 -05:00
Custom py ghostty generator
This commit is contained in:
74
matugen/b16.py
Executable file
74
matugen/b16.py
Executable file
@@ -0,0 +1,74 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import colorsys
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def hex_to_rgb(hex_color):
|
||||||
|
hex_color = hex_color.lstrip('#')
|
||||||
|
return tuple(int(hex_color[i:i+2], 16)/255.0 for i in (0, 2, 4))
|
||||||
|
|
||||||
|
def rgb_to_hex(r, g, b):
|
||||||
|
return f"#{int(r*255):02x}{int(g*255):02x}{int(b*255):02x}"
|
||||||
|
|
||||||
|
def generate_palette(base_color, is_light=False):
|
||||||
|
r, g, b = hex_to_rgb(base_color)
|
||||||
|
h, s, v = colorsys.rgb_to_hsv(r, g, b)
|
||||||
|
|
||||||
|
palette = []
|
||||||
|
|
||||||
|
if is_light:
|
||||||
|
palette.append("#f8f8f8")
|
||||||
|
else:
|
||||||
|
palette.append("#1a1a1a")
|
||||||
|
|
||||||
|
red_h = h * 0.15
|
||||||
|
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(red_h, 0.5, 0.88)))
|
||||||
|
|
||||||
|
green_h = h + 0.25 if h < 0.75 else h - 0.75
|
||||||
|
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(green_h, s * 0.6, v * 1.1)))
|
||||||
|
|
||||||
|
yellow_h = h + 0.15 if h < 0.85 else h - 0.85
|
||||||
|
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(yellow_h, s * 0.5, v * 1.3)))
|
||||||
|
|
||||||
|
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(h, s * 0.8, v * 1.2)))
|
||||||
|
|
||||||
|
mag_h = h - 0.08 if h > 0.08 else h + 0.08
|
||||||
|
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(mag_h, s * 0.9, v * 1.1)))
|
||||||
|
|
||||||
|
cyan_h = h + 0.08
|
||||||
|
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(cyan_h, s * 0.7, v * 1.15)))
|
||||||
|
|
||||||
|
if is_light:
|
||||||
|
palette.append("#2e2e2e")
|
||||||
|
palette.append("#4a4a4a")
|
||||||
|
else:
|
||||||
|
palette.append("#abb2bf")
|
||||||
|
palette.append("#5c6370")
|
||||||
|
|
||||||
|
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(red_h, 0.4, 0.94)))
|
||||||
|
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(green_h, s * 0.5, v * 1.3)))
|
||||||
|
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(yellow_h, s * 0.4, v * 1.4)))
|
||||||
|
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(h, s * 0.7, min(v * 1.4, 1.0))))
|
||||||
|
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(mag_h, s * 0.8, min(v * 1.3, 1.0))))
|
||||||
|
palette.append(rgb_to_hex(*colorsys.hsv_to_rgb(cyan_h, s * 0.6, min(v * 1.3, 1.0))))
|
||||||
|
|
||||||
|
if is_light:
|
||||||
|
palette.append("#1a1a1a")
|
||||||
|
else:
|
||||||
|
palette.append("#ffffff")
|
||||||
|
|
||||||
|
return palette
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
if len(sys.argv) < 2 or len(sys.argv) > 3:
|
||||||
|
print("Usage: b16.py <hex_color> [--light]", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
base = sys.argv[1]
|
||||||
|
if not base.startswith('#'):
|
||||||
|
base = '#' + base
|
||||||
|
|
||||||
|
is_light = len(sys.argv) == 3 and sys.argv[2] == "--light"
|
||||||
|
colors = generate_palette(base, is_light)
|
||||||
|
|
||||||
|
for i, color in enumerate(colors):
|
||||||
|
print(f"palette = {i}={color}")
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
[templates.fastfetch]
|
|
||||||
input_path = './matugen/templates/fastfetch-colors.jsonc'
|
|
||||||
output_path = '~/.config/fastfetch/colors.jsonc'
|
|
||||||
@@ -1,7 +1,3 @@
|
|||||||
[templates.ghostty-dark]
|
[templates.ghostty]
|
||||||
input_path = './matugen/templates/ghostty-colors-dark.conf'
|
input_path = './matugen/templates/ghostty.conf'
|
||||||
output_path = '~/.config/ghostty/config-dankcolors'
|
|
||||||
|
|
||||||
[templates.ghostty-light]
|
|
||||||
input_path = './matugen/templates/ghostty-colors-light.conf'
|
|
||||||
output_path = '~/.config/ghostty/config-dankcolors'
|
output_path = '~/.config/ghostty/config-dankcolors'
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
{
|
|
||||||
"$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json",
|
|
||||||
"display": {
|
|
||||||
"color": {
|
|
||||||
"keys": "{{colors.primary.default.hex}}",
|
|
||||||
"title": "{{colors.on_surface.default.hex}}",
|
|
||||||
"separator": "{{colors.outline.default.hex}}",
|
|
||||||
"output": "{{colors.secondary.default.hex}}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
background = {{colors.surface.default.hex}}
|
|
||||||
foreground = {{colors.on_surface.default.hex}}
|
|
||||||
cursor-color = {{colors.primary.default.hex}}
|
|
||||||
selection-background = {{colors.surface_container.default.hex}}
|
|
||||||
selection-foreground = {{colors.on_surface.default.hex}}
|
|
||||||
palette = 0={{colors.surface.default.hex}}
|
|
||||||
palette = 1={{colors.inverse_primary.default.hex}}
|
|
||||||
palette = 2={{colors.primary_container.default.hex}}
|
|
||||||
palette = 3={{colors.secondary_container.default.hex}}
|
|
||||||
palette = 4={{colors.primary.default.hex}}
|
|
||||||
palette = 5={{colors.secondary.default.hex}}
|
|
||||||
palette = 6={{colors.secondary_container.default.hex}}
|
|
||||||
palette = 7={{colors.on_surface.default.hex}}
|
|
||||||
palette = 8={{colors.outline.default.hex}}
|
|
||||||
palette = 9={{colors.error_container.default.hex}}
|
|
||||||
palette = 10={{colors.primary_fixed.default.hex}}
|
|
||||||
palette = 11={{colors.secondary_fixed.default.hex}}
|
|
||||||
palette = 12={{colors.surface_variant.default.hex}}
|
|
||||||
palette = 13={{colors.primary_fixed_dim.default.hex}}
|
|
||||||
palette = 14={{colors.inverse_surface.default.hex}}
|
|
||||||
palette = 15={{colors.on_background.default.hex}}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
background = {{colors.surface.default.hex}}
|
|
||||||
foreground = {{colors.on_surface.default.hex}}
|
|
||||||
cursor-color = {{colors.primary.default.hex}}
|
|
||||||
selection-background = {{colors.surface_container.default.hex}}
|
|
||||||
selection-foreground = {{colors.on_surface.default.hex}}
|
|
||||||
palette = 0={{colors.surface.default.hex}}
|
|
||||||
palette = 1={{colors.error.default.hex}}
|
|
||||||
palette = 2={{colors.primary.default.hex}}
|
|
||||||
palette = 3={{colors.secondary.default.hex}}
|
|
||||||
palette = 4={{colors.tertiary.default.hex}}
|
|
||||||
palette = 5={{colors.primary_container.default.hex}}
|
|
||||||
palette = 6={{colors.secondary_container.default.hex}}
|
|
||||||
palette = 7={{colors.on_surface.default.hex}}
|
|
||||||
palette = 8={{colors.outline.default.hex}}
|
|
||||||
palette = 9={{colors.error_container.default.hex}}
|
|
||||||
palette = 10={{colors.tertiary_container.default.hex}}
|
|
||||||
palette = 11={{colors.outline_variant.default.hex}}
|
|
||||||
palette = 12={{colors.on_surface_variant.default.hex}}
|
|
||||||
palette = 13={{colors.shadow.default.hex}}
|
|
||||||
palette = 14={{colors.inverse_surface.default.hex}}
|
|
||||||
palette = 15={{colors.on_background.default.hex}}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
background = {{colors.surface.default.hex}}
|
|
||||||
foreground = {{colors.on_surface.default.hex}}
|
|
||||||
cursor-color = {{colors.primary.default.hex}}
|
|
||||||
selection-background = {{colors.surface_container.default.hex}}
|
|
||||||
selection-foreground = {{colors.on_surface.default.hex}}
|
|
||||||
palette = 0={{colors.surface.default.hex}}
|
|
||||||
palette = 1={{colors.error.default.hex}}
|
|
||||||
palette = 2={{colors.primary.default.hex}}
|
|
||||||
palette = 3={{colors.secondary.default.hex}}
|
|
||||||
palette = 4={{colors.tertiary.default.hex}}
|
|
||||||
palette = 5={{colors.on_primary_fixed.default.hex}}
|
|
||||||
palette = 6={{colors.secondary_container.default.hex}}
|
|
||||||
palette = 7={{colors.on_surface.default.hex}}
|
|
||||||
palette = 8={{colors.outline.default.hex}}
|
|
||||||
palette = 9={{colors.error_container.default.hex}}
|
|
||||||
palette = 10={{colors.tertiary_fixed.default.hex}}
|
|
||||||
palette = 11={{colors.secondary_fixed.default.hex}}
|
|
||||||
palette = 12={{colors.tertiary_fixed.default.hex}}
|
|
||||||
palette = 13={{colors.primary_fixed_dim.default.hex}}
|
|
||||||
palette = 14={{colors.inverse_surface.default.hex}}
|
|
||||||
palette = 15={{colors.on_background.default.hex}}
|
|
||||||
5
matugen/templates/ghostty.conf
Normal file
5
matugen/templates/ghostty.conf
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
background = {{colors.surface.default.hex}}
|
||||||
|
foreground = {{colors.on_surface.default.hex}}
|
||||||
|
cursor-color = {{colors.primary.default.hex}}
|
||||||
|
selection-background = {{colors.surface_container.default.hex}}
|
||||||
|
selection-foreground = {{colors.on_surface.default.hex}}
|
||||||
@@ -100,11 +100,6 @@ build_content_config() {
|
|||||||
if command -v ghostty >/dev/null 2>&1; then
|
if command -v ghostty >/dev/null 2>&1; then
|
||||||
echo " - Including ghostty config (ghostty found)"
|
echo " - Including ghostty config (ghostty found)"
|
||||||
cat "$shell_dir/matugen/configs/ghostty.toml" >> "$temp_config"
|
cat "$shell_dir/matugen/configs/ghostty.toml" >> "$temp_config"
|
||||||
if [ "$is_light" = "true" ]; then
|
|
||||||
sed -i '/\[templates\.ghostty-dark\]/,/^$/d' "$temp_config"
|
|
||||||
else
|
|
||||||
sed -i '/\[templates\.ghostty-light\]/,/^$/d' "$temp_config"
|
|
||||||
fi
|
|
||||||
sed -i "s|input_path = './matugen/templates/|input_path = '$shell_dir/matugen/templates/|g" "$temp_config"
|
sed -i "s|input_path = './matugen/templates/|input_path = '$shell_dir/matugen/templates/|g" "$temp_config"
|
||||||
echo "" >> "$temp_config"
|
echo "" >> "$temp_config"
|
||||||
else
|
else
|
||||||
@@ -119,15 +114,6 @@ build_content_config() {
|
|||||||
else
|
else
|
||||||
echo " - Skipping dgop config (dgop not found)"
|
echo " - Skipping dgop config (dgop not found)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if command -v fastfetch >/dev/null 2>&1; then
|
|
||||||
echo " - Including fastfetch config (fastfetch found)"
|
|
||||||
cat "$shell_dir/matugen/configs/fastfetch.toml" >> "$temp_config"
|
|
||||||
sed -i "s|input_path = './matugen/templates/|input_path = '$shell_dir/matugen/templates/|g" "$temp_config"
|
|
||||||
echo "" >> "$temp_config"
|
|
||||||
else
|
|
||||||
echo " - Skipping fastfetch config (fastfetch not found)"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ "$MODE" = "generate" ]; then
|
if [ "$MODE" = "generate" ]; then
|
||||||
@@ -164,24 +150,30 @@ else
|
|||||||
MATUGEN_MODE="-m dark"
|
MATUGEN_MODE="-m dark"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
EXTRACTED_PRIMARY=""
|
||||||
|
|
||||||
if [ "$MODE" = "generate" ]; then
|
if [ "$MODE" = "generate" ]; then
|
||||||
echo "Generating matugen themes from wallpaper: $INPUT_SOURCE"
|
echo "Generating matugen themes from wallpaper: $INPUT_SOURCE"
|
||||||
echo "Using dynamic config: $TEMP_CONFIG"
|
echo "Using dynamic config: $TEMP_CONFIG"
|
||||||
|
|
||||||
if ! matugen -v -c "$TEMP_CONFIG" image "$INPUT_SOURCE" $MATUGEN_MODE; then
|
if ! MATUGEN_OUTPUT=$(matugen -v -c "$TEMP_CONFIG" image "$INPUT_SOURCE" $MATUGEN_MODE 2>&1); then
|
||||||
echo "Failed to generate themes with matugen" >&2
|
echo "Failed to generate themes with matugen" >&2
|
||||||
|
echo "$MATUGEN_OUTPUT"
|
||||||
rm -f "$TEMP_CONFIG"
|
rm -f "$TEMP_CONFIG"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
EXTRACTED_PRIMARY=$(echo "$MATUGEN_OUTPUT" | grep -oP 'Primary: \K#[0-9a-fA-F]{6}' | head -1)
|
||||||
elif [ "$MODE" = "generate-color" ]; then
|
elif [ "$MODE" = "generate-color" ]; then
|
||||||
echo "Generating matugen themes from color: $INPUT_SOURCE"
|
echo "Generating matugen themes from color: $INPUT_SOURCE"
|
||||||
echo "Using dynamic config: $TEMP_CONFIG"
|
echo "Using dynamic config: $TEMP_CONFIG"
|
||||||
|
|
||||||
if ! matugen -v -c "$TEMP_CONFIG" color hex "$INPUT_SOURCE" $MATUGEN_MODE; then
|
if ! MATUGEN_OUTPUT=$(matugen -v -c "$TEMP_CONFIG" color hex "$INPUT_SOURCE" $MATUGEN_MODE 2>&1); then
|
||||||
echo "Failed to generate themes with matugen" >&2
|
echo "Failed to generate themes with matugen" >&2
|
||||||
|
echo "$MATUGEN_OUTPUT"
|
||||||
rm -f "$TEMP_CONFIG"
|
rm -f "$TEMP_CONFIG"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
EXTRACTED_PRIMARY=$(echo "$MATUGEN_OUTPUT" | grep -oP 'Primary: \K#[0-9a-fA-F]{6}' | head -1)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
TEMP_CONTENT_CONFIG="/tmp/matugen-content-config-$$.toml"
|
TEMP_CONTENT_CONFIG="/tmp/matugen-content-config-$$.toml"
|
||||||
@@ -190,9 +182,44 @@ build_content_config "$TEMP_CONTENT_CONFIG" "$IS_LIGHT" "$SHELL_DIR"
|
|||||||
if [ -s "$TEMP_CONTENT_CONFIG" ] && grep -q '\[templates\.' "$TEMP_CONTENT_CONFIG"; then
|
if [ -s "$TEMP_CONTENT_CONFIG" ] && grep -q '\[templates\.' "$TEMP_CONTENT_CONFIG"; then
|
||||||
echo "Running content-specific theme generation..."
|
echo "Running content-specific theme generation..."
|
||||||
if [ "$MODE" = "generate" ]; then
|
if [ "$MODE" = "generate" ]; then
|
||||||
matugen -v -c "$TEMP_CONTENT_CONFIG" -t scheme-fidelity image "$INPUT_SOURCE" $MATUGEN_MODE
|
matugen -v -c "$TEMP_CONTENT_CONFIG" -t scheme-content image "$INPUT_SOURCE" $MATUGEN_MODE
|
||||||
elif [ "$MODE" = "generate-color" ]; then
|
elif [ "$MODE" = "generate-color" ]; then
|
||||||
matugen -v -c "$TEMP_CONTENT_CONFIG" -t scheme-fidelity color hex "$INPUT_SOURCE" $MATUGEN_MODE
|
matugen -v -c "$TEMP_CONTENT_CONFIG" -t scheme-content color hex "$INPUT_SOURCE" $MATUGEN_MODE
|
||||||
|
fi
|
||||||
|
|
||||||
|
if command -v ghostty >/dev/null 2>&1; then
|
||||||
|
echo "Generating base16 palette for ghostty..."
|
||||||
|
|
||||||
|
PRIMARY_COLOR="$EXTRACTED_PRIMARY"
|
||||||
|
if [ -z "$PRIMARY_COLOR" ]; then
|
||||||
|
PRIMARY_COLOR="#6b5f8e"
|
||||||
|
echo "Warning: Could not extract primary color, using fallback: $PRIMARY_COLOR"
|
||||||
|
fi
|
||||||
|
|
||||||
|
B16_ARGS="$PRIMARY_COLOR"
|
||||||
|
if [ "$IS_LIGHT" = "true" ]; then
|
||||||
|
B16_ARGS="$B16_ARGS --light"
|
||||||
|
fi
|
||||||
|
|
||||||
|
B16_OUTPUT=$("$SHELL_DIR/matugen/b16.py" $B16_ARGS)
|
||||||
|
|
||||||
|
if [ $? -eq 0 ] && [ -n "$B16_OUTPUT" ]; then
|
||||||
|
TEMP_GHOSTTY="/tmp/ghostty-config-$$.conf"
|
||||||
|
echo "$B16_OUTPUT" > "$TEMP_GHOSTTY"
|
||||||
|
echo "" >> "$TEMP_GHOSTTY"
|
||||||
|
|
||||||
|
if [ -f "$CONFIG_DIR/ghostty/config-dankcolors" ]; then
|
||||||
|
cat "$CONFIG_DIR/ghostty/config-dankcolors" >> "$TEMP_GHOSTTY"
|
||||||
|
else
|
||||||
|
echo "Warning: $CONFIG_DIR/ghostty/config-dankcolors not found"
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p "$CONFIG_DIR/ghostty"
|
||||||
|
mv "$TEMP_GHOSTTY" "$CONFIG_DIR/ghostty/config-dankcolors"
|
||||||
|
echo "Base16 palette prepended to ghostty config"
|
||||||
|
else
|
||||||
|
echo "Warning: Failed to generate base16 palette"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "No content-specific tools found, skipping content generation"
|
echo "No content-specific tools found, skipping content generation"
|
||||||
@@ -220,4 +247,3 @@ command -v qt5ct >/dev/null 2>&1 && [ -f "$CONFIG_DIR/qt5ct/colors/matugen.conf"
|
|||||||
command -v qt6ct >/dev/null 2>&1 && [ -f "$CONFIG_DIR/qt6ct/colors/matugen.conf" ] && echo " - Qt6ct themes"
|
command -v qt6ct >/dev/null 2>&1 && [ -f "$CONFIG_DIR/qt6ct/colors/matugen.conf" ] && echo " - Qt6ct themes"
|
||||||
command -v ghostty >/dev/null 2>&1 && [ -f "$CONFIG_DIR/ghostty/config-dankcolors" ] && echo " - Ghostty terminal"
|
command -v ghostty >/dev/null 2>&1 && [ -f "$CONFIG_DIR/ghostty/config-dankcolors" ] && echo " - Ghostty terminal"
|
||||||
command -v dgop >/dev/null 2>&1 && [ -f "$CONFIG_DIR/dgop/colors.json" ] && echo " - Dgop colors"
|
command -v dgop >/dev/null 2>&1 && [ -f "$CONFIG_DIR/dgop/colors.json" ] && echo " - Dgop colors"
|
||||||
command -v fastfetch >/dev/null 2>&1 && [ -f "$CONFIG_DIR/fastfetch/colors.jsonc" ] && echo " - Fastfetch colors"
|
|
||||||
Reference in New Issue
Block a user