From 6afcb2c5a2cd5e935f75d5f34f52a6e2e04c8d33 Mon Sep 17 00:00:00 2001 From: Noah Yoshida Date: Tue, 29 May 2018 20:13:10 -0700 Subject: vscode template json file added --- pywal/export.py | 1 + 1 file changed, 1 insertion(+) (limited to 'pywal/export.py') diff --git a/pywal/export.py b/pywal/export.py index 993e528..c67cca0 100644 --- a/pywal/export.py +++ b/pywal/export.py @@ -44,6 +44,7 @@ def get_export_type(export_type): "shell": "colors.sh", "sway": "colors-sway", "tty": "colors-tty.sh", + "vscode": "colors-vscode.json", "xresources": "colors.Xresources", "yaml": "colors.yml", }.get(export_type, export_type) -- cgit v1.2.3 From b9fd064d3069024b7d9084d3303e28fede3ad4b0 Mon Sep 17 00:00:00 2001 From: Amit Prasad <17amitprasad@gmail.com> Date: Mon, 16 Dec 2019 11:45:22 -0500 Subject: Started working on matching functions --- pywal/export.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'pywal/export.py') 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"(?<=(? Date: Tue, 17 Dec 2019 20:29:04 -0500 Subject: Added ability to modify colors using methods ( .lighten(%), .darken(%), .saturate(%) for now) --- pywal/export.py | 59 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 27 deletions(-) (limited to 'pywal/export.py') diff --git a/pywal/export.py b/pywal/export.py index b175c11..ae619cd 100644 --- a/pywal/export.py +++ b/pywal/export.py @@ -13,38 +13,43 @@ 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"(?<=(? 1: + args = func_split[1].split(",") + else: + args = [] + name = func_split[0] + if name[0] == '.': + name = name[1:] + x = getattr(colors[color], name) + if callable(x): + new_color = x(*args) + if func[0] != '.': + to_replace += "." + to_replace += func + ")" + else: + pass + if not new_color is None: + cname = "color" + new_color.strip + template_data[i] = line.replace(to_replace, cname) + colors[cname] = new_color try: template_data = "".join(template_data).format(**colors) except ValueError: logging.error("Syntax error in template file '%s'.", input_file) return - util.save_file(template_data, output_file) -- cgit v1.2.3 From f0692c31eb91f0c6e5f2f5c8fdf4737808784362 Mon Sep 17 00:00:00 2001 From: Amit Prasad <17amitprasad@gmail.com> Date: Wed, 18 Dec 2019 13:28:13 -0500 Subject: Commented and minimize. --- pywal/export.py | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) (limited to 'pywal/export.py') diff --git a/pywal/export.py b/pywal/export.py index ae619cd..f7b9de8 100644 --- a/pywal/export.py +++ b/pywal/export.py @@ -17,33 +17,34 @@ def template(colors, input_file, output_file=None): line = template_data[i] matches = re.finditer(r"(?<=(? 1: - args = func_split[1].split(",") - else: - args = [] - name = func_split[0] - if name[0] == '.': - name = name[1:] - x = getattr(colors[color], name) - if callable(x): - new_color = x(*args) - if func[0] != '.': - to_replace += "." - to_replace += func + ")" - else: - pass - if not new_color is None: + args = [] + if len(func_split) > 1: args = func_split[1].split(",") + fname = func_split[0] + if fname[0] == '.': fname = fname[1:] + f = getattr(new_color, fname) + + # If the function is callable, call it + if callable(f): + new_color = f(*args) + #add to the string that will replace the function calls with the generated function. + if func[0] != '.': replace_str += "." + replace_str += func + ")" + #If the color was changed, replace the template with a unique identifier for the new color. + if not new_color is colors[color]: cname = "color" + new_color.strip - template_data[i] = line.replace(to_replace, cname) + template_data[i] = line.replace(replace_str, cname) colors[cname] = new_color try: template_data = "".join(template_data).format(**colors) -- cgit v1.2.3 From c29151de464ee9267872c48115fc79bc7a0075b6 Mon Sep 17 00:00:00 2001 From: Amit Prasad <17amitprasad@gmail.com> Date: Fri, 20 Dec 2019 09:44:19 -0500 Subject: Beautify --- pywal/export.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'pywal/export.py') diff --git a/pywal/export.py b/pywal/export.py index f7b9de8..4c0649f 100644 --- a/pywal/export.py +++ b/pywal/export.py @@ -19,29 +19,35 @@ def template(colors, input_file, output_file=None): for match in matches: # Get the color, and the functions associated with it color, _, funcs = match.group(2).partition(".") - #Check that functions are needed for this color + # Check that functions are needed for this color if len(funcs) != 0: - #Build up a string which will be replaced when the color is done processing + # Build up a string which will be replaced when the color is done processing replace_str = color - #The modified color + # The modified color new_color = colors[color] - #Execute each function to be done - for func in filter(None,funcs.split(")")): - ### Get function name and arguments + # Execute each function to be done + for func in filter(None, funcs.split(")")): + # Get function name and arguments func_split = func.split("(") args = [] - if len(func_split) > 1: args = func_split[1].split(",") + if len(func_split) > 1: + args = func_split[1].split(",") fname = func_split[0] - if fname[0] == '.': fname = fname[1:] + if fname[0] == '.': + fname = fname[1:] + if not hasattr(new_color, fname): + logging.error( + "Syntax error in template file '%s' on line '%s'", input_file, i) f = getattr(new_color, fname) # If the function is callable, call it if callable(f): new_color = f(*args) - #add to the string that will replace the function calls with the generated function. - if func[0] != '.': replace_str += "." + # add to the string that will replace the function calls with the generated function. + if func[0] != '.': + replace_str += "." replace_str += func + ")" - #If the color was changed, replace the template with a unique identifier for the new color. + # If the color was changed, replace the template with a unique identifier for the new color. if not new_color is colors[color]: cname = "color" + new_color.strip template_data[i] = line.replace(replace_str, cname) -- cgit v1.2.3 From d4bd389b438df7bc4d3f302d44e23c9bbdaba8ec Mon Sep 17 00:00:00 2001 From: Amit Prasad <17amitprasad@gmail.com> Date: Fri, 20 Dec 2019 11:34:57 -0500 Subject: Cleaned up code for pylint --- pywal/export.py | 76 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 38 insertions(+), 38 deletions(-) (limited to 'pywal/export.py') diff --git a/pywal/export.py b/pywal/export.py index 4c0649f..d9ff16d 100644 --- a/pywal/export.py +++ b/pywal/export.py @@ -5,53 +5,53 @@ import logging import os import re -from .settings import CACHE_DIR, MODULE_DIR, CONF_DIR from . import util +from .settings import CACHE_DIR, CONF_DIR, MODULE_DIR 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) - for i in range(len(template_data)): - line = template_data[i] - matches = re.finditer(r"(?<=(? 1: - args = func_split[1].split(",") - fname = func_split[0] - if fname[0] == '.': - fname = fname[1:] - if not hasattr(new_color, fname): - logging.error( - "Syntax error in template file '%s' on line '%s'", input_file, i) - f = getattr(new_color, fname) - - # If the function is callable, call it - if callable(f): - new_color = f(*args) - # add to the string that will replace the function calls with the generated function. - if func[0] != '.': - replace_str += "." - replace_str += func + ")" - # If the color was changed, replace the template with a unique identifier for the new color. - if not new_color is colors[color]: - cname = "color" + new_color.strip - template_data[i] = line.replace(replace_str, cname) - colors[cname] = new_color + if len(funcs) == 0: + continue + # Build up a string which will be replaced with the new color + replace_str = cname + # Color to be modified copied into new one + new_color = util.Color(colors[cname].hex_color) + # Execute each function to be done + for func in filter(None, funcs.split(")")): + # Get function name and arguments + func = func.split("(") + fname = func[0] + if fname[0] == '.': + fname = fname[1:] + if not hasattr(new_color, fname): + logging.error( + "Syntax error in template file '%s' on line '%s'", + input_file, i) + function = getattr(new_color, fname) + + # If the function is callable, call it + if callable(function): + if len(func) > 1: + new_color = function(*func[1].split(",")) + else: + new_color = function() + # string to replace generated colors + if func[0] != '.': + replace_str += "." + replace_str += "(".join(func) + ")" + # If the color was changed, replace with a unique identifier. + if new_color is not colors[cname]: + template_data[i] = l.replace( + replace_str, "color" + new_color.strip) + colors["color" + new_color.strip] = new_color try: template_data = "".join(template_data).format(**colors) except ValueError: -- cgit v1.2.3