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

Commit

Permalink
Beautify
Browse files Browse the repository at this point in the history
  • Loading branch information
AmitPr committed Dec 20, 2019
1 parent c089604 commit c29151d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ The goal of Pywal was to be as out of the way as possible. It doesn't modify any

Terminal emulators and TTYs have their color-schemes updated in real-time with no delay. With minimal configuration this functionality can be extended to almost anything running on your system.

### More: \[[Installation](https://github.com/dylanaraps/pywal/wiki/Installation)\] \[[Getting Started](https://github.com/dylanaraps/pywal/wiki/Getting-Started)\] \[[Customization](https://github.com/dylanaraps/pywal/wiki/Customization)\] \[[Wiki](https://github.com/dylanaraps/pywal/wiki)\] \[[Screenshots](https://www.reddit.com/r/unixporn/search?q=wal&restrict_sr=on&sort=relevance&t=all)\]
### More: \[[Installation](https://github.com/dylanaraps/pywal/wiki/Installation)] \[[Getting Started](https://github.com/dylanaraps/pywal/wiki/Getting-Started)] \[[Customization](https://github.com/dylanaraps/pywal/wiki/Customization)] \[[Wiki](https://github.com/dylanaraps/pywal/wiki)] \[[Screenshots](https://www.reddit.com/r/unixporn/search?q=wal&restrict_sr=on&sort=relevance&t=all)]
28 changes: 17 additions & 11 deletions pywal/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion pywal/templates/functest

This file was deleted.

19 changes: 10 additions & 9 deletions pywal/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def xrgba(self):
def rgba(self):
"""Convert a hex color to rgba."""
return "rgba(%s,%s,%s,%s)" % (*hex_to_rgb(self.hex_color),
int(self.alpha_num)/100)
int(self.alpha_num) / 100)

@property
def alpha(self):
Expand All @@ -58,24 +58,25 @@ def strip(self):
"""Strip '#' from color."""
return self.hex_color[1:]

def lighten(self,percent):
def lighten(self, percent):
"""Lighten color by percent"""
return Color(lighten_color(self.hex_color,float(re.sub(r'[\D\.]','',percent))/100))
return Color(lighten_color(self.hex_color, float(re.sub(r'[\D\.]', '', percent)) / 100))

def darken(self,percent):
def darken(self, percent):
"""Darken color by percent"""
return Color(darken_color(self.hex_color,float(re.sub(r'[\D\.]','',percent))/100))
return Color(darken_color(self.hex_color, float(re.sub(r'[\D\.]', '', percent)) / 100))

def saturate(self,percent):
def saturate(self, percent):
"""Saturate a color"""
return Color(saturate_color(self.hex_color,float(re.sub(r'[\D\.]','',percent))/100))
return Color(saturate_color(self.hex_color, float(re.sub(r'[\D\.]', '', percent)) / 100))


def read_file(input_file):
"""Read data from a file and trim newlines."""
with open(input_file, "r") as file:
return file.read().splitlines()


def read_file_json(input_file):
"""Read data from a json file."""
with open(input_file, "r") as json_file:
Expand Down Expand Up @@ -168,11 +169,11 @@ def blend_color(color, color2):
def saturate_color(color, amount):
"""Saturate a hex color."""
r, g, b = hex_to_rgb(color)
r, g, b = [x/255.0 for x in (r, g, b)]
r, g, b = [x / 255.0 for x in (r, g, b)]
h, l, s = colorsys.rgb_to_hls(r, g, b)
s = amount
r, g, b = colorsys.hls_to_rgb(h, l, s)
r, g, b = [x*255.0 for x in (r, g, b)]
r, g, b = [x * 255.0 for x in (r, g, b)]

return rgb_to_hex((int(r), int(g), int(b)))

Expand Down

0 comments on commit c29151d

Please sign in to comment.