diff options
| author | Amit Prasad <17amitprasad@gmail.com> | 2019-12-16 11:45:22 -0500 |
|---|---|---|
| committer | Amit Prasad <17amitprasad@gmail.com> | 2019-12-16 11:45:22 -0500 |
| commit | b9fd064d3069024b7d9084d3303e28fede3ad4b0 (patch) | |
| tree | 5dd9db795eb28b9b060f70a8f4669fbf1daa97e9 | |
| parent | c18f4014f969504deaeb692aa88660ee4cb10f3f (diff) | |
Started working on matching functions
| -rw-r--r-- | pywal/export.py | 28 | ||||
| -rw-r--r-- | pywal/util.py | 5 |
2 files changed, 32 insertions, 1 deletions
diff --git a/pywal/export.py b/pywal/export.py index 88c98a6..b175c11 100644 --- a/pywal/export.py +++ b/pywal/export.py @@ -3,6 +3,7 @@ Export colors in various formats. """ import logging import os +import re from .settings import CACHE_DIR, MODULE_DIR, CONF_DIR from . import util @@ -12,7 +13,32 @@ def template(colors, input_file, output_file=None): """Read template file, substitute markers and save the file elsewhere.""" 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: template_data = "".join(template_data).format(**colors) except ValueError: diff --git a/pywal/util.py b/pywal/util.py index e4b146a..2fe0762 100644 --- a/pywal/util.py +++ b/pywal/util.py @@ -57,6 +57,11 @@ class Color: """Strip '#' from color.""" 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): """Read data from a file and trim newlines.""" |
