mirror of
https://github.com/dylanaraps/pywal.git
synced 2025-06-12 04:37:08 +02:00
Started working on matching functions
This commit is contained in:
parent
c18f4014f9
commit
b9fd064d30
@ -3,6 +3,7 @@ Export colors in various formats.
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
from .settings import CACHE_DIR, MODULE_DIR, CONF_DIR
|
from .settings import CACHE_DIR, MODULE_DIR, CONF_DIR
|
||||||
from . import util
|
from . import util
|
||||||
@ -12,7 +13,32 @@ def template(colors, input_file, output_file=None):
|
|||||||
"""Read template file, substitute markers and
|
"""Read template file, substitute markers and
|
||||||
save the file elsewhere."""
|
save the file elsewhere."""
|
||||||
template_data = util.read_file_raw(input_file)
|
template_data = util.read_file_raw(input_file)
|
||||||
|
matches = re.finditer(r"(?<=(?<!\{))(\{([^{}]+)\})(?=(?!\}))", "".join(template_data), re.MULTILINE)
|
||||||
|
print(colors)
|
||||||
|
for match in matches:
|
||||||
|
# Check that this color doesn't already exist
|
||||||
|
match_str = match.group(2)
|
||||||
|
color, _, funcs = match_str.partition(".")
|
||||||
|
#if len(funcs) != 0:
|
||||||
|
#print(funcs)
|
||||||
|
#print(colors[color].hex_color,input_file)
|
||||||
|
|
||||||
|
'''if match_str not in colors:
|
||||||
|
# Extract original color and functions
|
||||||
|
attr, _, funcs = match_str.partition(".")
|
||||||
|
original_color = colors[attr]
|
||||||
|
funcs = funcs.split(".")
|
||||||
|
# Apply every function to the original color
|
||||||
|
for func in funcs:
|
||||||
|
# Check if this sub-color has already been generated
|
||||||
|
if not hasattr(original_color, func):
|
||||||
|
# Generate new color using function from util.py
|
||||||
|
func, arg = func.strip(")").split("(")
|
||||||
|
arg = arg.split(",")
|
||||||
|
new_color = util.Color(
|
||||||
|
getattr(util, func)(original_color.hex_color, *arg))
|
||||||
|
setattr(original_color, func, new_color)
|
||||||
|
original_color = getattr(original_color, func)'''
|
||||||
try:
|
try:
|
||||||
template_data = "".join(template_data).format(**colors)
|
template_data = "".join(template_data).format(**colors)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
@ -57,6 +57,11 @@ class Color:
|
|||||||
"""Strip '#' from color."""
|
"""Strip '#' from color."""
|
||||||
return self.hex_color[1:]
|
return self.hex_color[1:]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def lighten(self,percent):
|
||||||
|
"""Lighten color by percent"""
|
||||||
|
return lighten_color(self.hex_color,percent/100)
|
||||||
|
|
||||||
|
|
||||||
def read_file(input_file):
|
def read_file(input_file):
|
||||||
"""Read data from a file and trim newlines."""
|
"""Read data from a file and trim newlines."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user