Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: dylanaraps/pywal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.1.6
Choose a base ref
...
head repository: dylanaraps/pywal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0.2.0
Choose a head ref
Loading
Showing with 671 additions and 586 deletions.
  1. +3 −0 .gitignore
  2. +2 −2 .travis.yml
  3. +4 −0 CHANGELOG.md
  4. +50 −0 CONTRIBUTING.md
  5. +7 −3 README.md
  6. +5 −0 pywal/__init__.py
  7. +111 −0 pywal/__main__.py
  8. +56 −0 pywal/export_colors.py
  9. +78 −0 pywal/format_color.py
  10. +120 −0 pywal/gen_colors.py
  11. +80 −0 pywal/set_colors.py
  12. +12 −0 pywal/settings.py
  13. +42 −0 pywal/util.py
  14. +86 −0 pywal/wallpaper.py
  15. +15 −4 setup.py
  16. +0 −577 wal
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
dist/*
pywal.egg-info/*
*.pyc
subprocess
re
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -6,5 +6,5 @@ install:
- pip install flake8 pylint

script:
- flake8 wal
- pylint wal
- flake8 pywal setup.py
- pylint --ignore-imports=yes pywal setup.py
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 0.1.7

- Fixed `color66` appearing in export files. #6
- Convert the script to a module. #7 - @danielx
50 changes: 50 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Contributing

Welcome to `pywal`, here's how you can contribute.


### Environment Details

- Linux
- Python `3.6`


### Development Dependencies

All contributions and changes to `wal` must pass both `flake8` and `pylint` linters unless you have ample reason for disabling a specific message. Travis.ci will automatically run the tests every time you push a new commit to a Pull Request on the repo.

```py
pip install flake8 pylint
```


### Tests

Tests haven't been written yet.


### Commit Message Style

I'm not fussed if you don't follow this one too closely as I'm guilty of forgetting at times. The commit style that should be used on this repo is as follows:

```sh
# topic: Short sentence about changes. Closes #issue_number
# Example:
git commit -m "export: Added export format for emacs. Closes #11"
```


### Comment Style

All comments must start with a capital letter and end with a full stop `.`.


### Running `pywal`

You can run `pywal` without properly installing it by using the following command:

```sh
# From the repo directory.
python -m pywal
```

10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
* [Terminal Emulator](#terminal-emulator)
* [Installation](#installation)
* [Pip install](#pip-install)
* [Manual install](#manual-install)
* [Manual/Git install](#manualgit-install)
* [Setup](#setup)
* [Applying the theme to new terminals.](#applying-the-theme-to-new-terminals)
* [Making the colorscheme persist on reboot.](#making-the-colorscheme-persist-on-reboot)
@@ -68,9 +68,13 @@ If your terminal's background color is now red, your terminal will work with `wa
pip install pywal
```

### Manual install
### Manual/Git install

Just grab the script (`wal`) and add it to your path.
```sh
git clone https://github.com/dylanaraps/pywal
cd pywal
pip install .
```


## Setup
5 changes: 5 additions & 0 deletions pywal/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""
wal - Generate and change colorschemes on the fly.
Created by Dylan Araps.
"""
from pywal.settings import __version__ # noqa: F401
111 changes: 111 additions & 0 deletions pywal/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
"""
wal - Generate and change colorschemes on the fly.
Created by Dylan Araps.
"""
import argparse
import os
import shutil
import sys

from pywal.settings import CACHE_DIR, __version__
from pywal import export_colors
from pywal import gen_colors
from pywal import set_colors
from pywal import wallpaper
from pywal import util


def get_args():
"""Get the script arguments."""
description = "wal - Generate colorschemes on the fly"
arg = argparse.ArgumentParser(description=description)

# Add the args.
arg.add_argument("-c", action="store_true",
help="Delete all cached colorschemes.")

arg.add_argument("-i", metavar="\"/path/to/img.jpg\"",
help="Which image or directory to use.")

arg.add_argument("-n", action="store_true",
help="Skip setting the wallpaper.")

arg.add_argument("-o", metavar="\"script_name\"",
help="External script to run after \"wal\".")

arg.add_argument("-q", action="store_true",
help="Quiet mode, don\"t print anything and \
don't display notifications.")

arg.add_argument("-r", action="store_true",
help="Reload current colorscheme.")

arg.add_argument("-t", action="store_true",
help="Fix artifacts in VTE Terminals. \
(Termite, xfce4-terminal)")

arg.add_argument("-v", action="store_true",
help="Print \"wal\" version.")

return arg.parse_args()


def process_args(args):
"""Process args."""
# If no args were passed.
if not len(sys.argv) > 1:
print("error: wal needs to be given arguments to run.\n"
" Refer to \"wal -h\" for more info.")
exit(1)

# -q
if args.q:
sys.stdout = sys.stderr = open(os.devnull, "w")

# -c
if args.c:
shutil.rmtree(CACHE_DIR / "schemes")
util.create_dir(CACHE_DIR / "schemes")

# -r
if args.r:
set_colors.reload_colors(args.t)

# -v
if args.v:
print(f"wal {__version__}")
exit(0)

# -i
if args.i:
image = gen_colors.get_image(args.i)

# Create a list of hex colors.
colors_plain = gen_colors.get_colors(image, args.q)
colors_plain[8] = set_colors.set_grey(colors_plain)

if not args.n:
wallpaper.set_wallpaper(image)

# Set the colors.
set_colors.send_sequences(colors_plain, args.t)
export_colors.export_colors(colors_plain)

# -o
if args.o:
util.disown(args.o)


def main():
"""Main script function."""
util.create_dir(CACHE_DIR / "schemes")
args = get_args()
process_args(args)

# This saves 10ms.
# pylint: disable=W0212
# os._exit(0)


if __name__ == "__main__":
main()
56 changes: 56 additions & 0 deletions pywal/export_colors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""
Export colors in various formats.
"""
import shutil
import subprocess

from pywal.settings import CACHE_DIR
from pywal import util
from pywal import format_color


def save_colors(colors, export_file, message):
"""Export colors to var format."""
colors = "".join(colors)
util.save_file(colors, CACHE_DIR / export_file)
print(f"export: exported {message}.")


def reload_xrdb(export_file):
"""Merge the colors into the X db so new terminals use them."""
if shutil.which("xrdb"):
subprocess.call(["xrdb", "-merge", CACHE_DIR / export_file])


def reload_i3():
"""Reload i3 colors."""
if shutil.which("i3-msg"):
util.disown("i3-msg", "reload")


def export_colors(colors):
"""Export colors in various formats."""
plain_colors = format_color.plain(colors)
save_colors(plain_colors, "colors", "plain hex colors")

# Shell based colors.
shell_colors = format_color.shell(colors)
save_colors(shell_colors, "colors.sh", "shell variables")

# Web based colors.
css_colors = format_color.css(colors)
save_colors(css_colors, "colors.css", "css variables")
scss_colors = format_color.scss(colors)
save_colors(scss_colors, "colors.scss", "scss variables")

# Text editor based colors.
putty_colors = format_color.putty(colors)
save_colors(putty_colors, "colors-putty.reg", "putty theme")

# X based colors.
xrdb_colors = format_color.xrdb(colors)
save_colors(xrdb_colors, "xcolors", "xrdb colors")

# i3 colors.
reload_xrdb("xcolors")
reload_i3()
78 changes: 78 additions & 0 deletions pywal/format_color.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
"""
Convert colors to various formats.
"""
from pywal import util


def plain(colors):
"""Convert colors to plain hex."""
return [f"{color}\n" for color in colors]


def shell(colors):
"""Convert colors to shell variables."""
return [f"color{index}='{color}'\n"
for index, color in enumerate(colors)]


def css(colors):
"""Convert colors to css variables."""
css_colors = [":root {\n"]
css_colors.extend([f"\t--color{index}: {color};\n"
for index, color in enumerate(colors)])
css_colors.append("}\n")
return css_colors


def scss(colors):
"""Convert colors to scss variables."""
return [f"$color{index}: {color};\n"
for index, color in enumerate(colors)]


def putty(colors):
"""Convert colors to putty theme."""
rgb = util.hex_to_rgb
putty_colors = [
"Windows Registry Editor Version 5.00\n\n",
"[HKEY_CURRENT_USER\\Software\\SimonTatham\\PuTTY\\Sessions\\Wal]\n",
]
putty_colors.extend([f"\"colour{index}\"=\"{rgb(color)}\"\n"
for index, color in enumerate(colors)])

return putty_colors


def xrdb(colors):
"""Convert colors to xrdb format."""
x_colors = []
x_colors.append(f"URxvt*foreground: {colors[15]}\n")
x_colors.append(f"XTerm*foreground: {colors[15]}\n")
x_colors.append(f"URxvt*background: {colors[0]}\n")
x_colors.append(f"XTerm*background: {colors[0]}\n")
x_colors.append(f"URxvt*cursorColor: {colors[15]}\n")
x_colors.append(f"XTerm*cursorColor: {colors[15]}\n")

# Colors 0-15.
x_colors.extend([f"*.color{index}: {color}\n*color{index}: {color}\n"
for index, color in enumerate(colors)])

x_colors.append(f"*.color66: {colors[0]}\n*color66: {colors[0]}\n")

# Rofi colors.
x_colors.append(f"rofi.color-window: {colors[0]}, "
f"{colors[0]}, {colors[10]}\n")
x_colors.append(f"rofi.color-normal: {colors[0]}, "
f"{colors[15]}, {colors[0]}, "
f"{colors[10]}, {colors[0]}\n")
x_colors.append(f"rofi.color-active: {colors[0]}, "
f"{colors[15]}, {colors[0]}, "
f"{colors[10]}, {colors[0]}\n")
x_colors.append(f"rofi.color-urgent: {colors[0]}, "
f"{colors[9]}, {colors[0]}, "
f"{colors[9]}, {colors[15]}\n")

# Emacs colors.
x_colors.append(f"emacs*background: {colors[0]}\n")
x_colors.append(f"emacs*foreground: {colors[15]}\n")
return x_colors
Loading