Giter Site home page Giter Site logo

Comments (3)

dylanaraps avatar dylanaraps commented on May 22, 2024

This is dead simple and doesn't require anything external: https://stackoverflow.com/a/6385940

(That method also works well with #16 since the colors are now stored in dicts.)

from pywal.

dylanaraps avatar dylanaraps commented on May 22, 2024

Actually, a better method is probably something like this:

def template(colors, input_file, export_file):
    """Read template file, substitute markers and
        save the file elsewhere."""

    # Import the template.
    with open(input_file) as file:
        template_data = file.readlines()

    # Format the markers.
    template_data = "".join(template_data).format(*colors)

    # Export the template.
    with open(export_file, "w") as file:
        file.write(template_data)

Since the function is rather generic we can loop it over the template directory removing the need for the export_colors.py and format_colors.py files. Adding a new export file will be as easy as adding a new file to the templates directory, wal will see it on next run and update the cache dir.

The markers are rather verbose now {index} but the change to json and dicts will most likely fix this. https://stackoverflow.com/questions/5952344/how-do-i-format-a-string-using-a-dictionary-in-python-3-x

Example template file:

/* '{}' need to be escaped if they're not markers. 
   You can escape them by doubling them '{{', '}}' */
:root {{
	--color0: {0};
	--color1: {1};
	--color2: {2};
	--color3: {3};
	--color4: {4};
	--color5: {5};
	--color6: {6};
	--color7: {7};
	--color8: {8};
	--color9: {9};
	--color10: {10};
	--color11: {11};
	--color12: {12};
	--color13: {13};
	--color14: {14};
	--color15: {15};
}}

from pywal.

dylanaraps avatar dylanaraps commented on May 22, 2024

See #18

from pywal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.