mirror of
https://github.com/dylanaraps/pywal.git
synced 2025-06-20 17:47:44 +02:00
colors: Add support for importing colors in a json format.
This commit is contained in:
parent
06d726a66c
commit
1734129dea
@ -101,8 +101,9 @@ def process_args(args):
|
|||||||
|
|
||||||
# -f
|
# -f
|
||||||
elif args.f:
|
elif args.f:
|
||||||
colors_plain = util.read_file(args.f)
|
colors_plain = util.read_file_json(args.f)
|
||||||
set_colors.send_sequences(colors_plain, args.t)
|
set_colors.send_sequences(colors_plain, args.t)
|
||||||
|
quit()
|
||||||
export_colors.export_colors(colors_plain)
|
export_colors.export_colors(colors_plain)
|
||||||
|
|
||||||
# -o
|
# -o
|
||||||
|
@ -37,19 +37,26 @@ def set_grey(colors):
|
|||||||
|
|
||||||
def send_sequences(colors, vte):
|
def send_sequences(colors, vte):
|
||||||
"""Send colors to all open terminals."""
|
"""Send colors to all open terminals."""
|
||||||
sequences = [set_color(num, color) for num, color in enumerate(colors)]
|
|
||||||
sequences.append(set_special(10, colors[15]))
|
# Colors 0-15.
|
||||||
sequences.append(set_special(11, colors[0]))
|
sequences = [set_color(num, color)
|
||||||
sequences.append(set_special(12, colors[15]))
|
for num, color in enumerate(colors["colors"].values())]
|
||||||
sequences.append(set_special(13, colors[15]))
|
|
||||||
sequences.append(set_special(14, colors[0]))
|
# Special colors.
|
||||||
|
sequences.append(set_special(10, colors["special"]["foreground"]))
|
||||||
|
sequences.append(set_special(11, colors["special"]["background"]))
|
||||||
|
sequences.append(set_special(12, colors["special"]["cursor"]))
|
||||||
|
|
||||||
|
# TODO: Figure out what these change.
|
||||||
|
# sequences.append(set_special(13, colors["foreground"]))
|
||||||
|
# sequences.append(set_special(14, colors["background"]))
|
||||||
|
|
||||||
# Set a blank color that isn"t affected by bold highlighting.
|
# Set a blank color that isn"t affected by bold highlighting.
|
||||||
sequences.append(set_color(66, colors[0]))
|
sequences.append(set_color(66, colors["special"]["background"]))
|
||||||
|
|
||||||
# This escape sequence doesn"t work in VTE terminals.
|
# This escape sequence doesn"t work in VTE terminals.
|
||||||
if not vte:
|
if not vte:
|
||||||
sequences.append(set_special(708, colors[0]))
|
sequences.append(set_special(708, colors["special"]["background"]))
|
||||||
|
|
||||||
# Get a list of terminals.
|
# Get a list of terminals.
|
||||||
terminals = [f"/dev/pts/{term}" for term in os.listdir("/dev/pts/")
|
terminals = [f"/dev/pts/{term}" for term in os.listdir("/dev/pts/")
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"""
|
"""
|
||||||
Misc helper functions.
|
Misc helper functions.
|
||||||
"""
|
"""
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
import subprocess
|
import subprocess
|
||||||
@ -13,6 +14,13 @@ def read_file(input_file):
|
|||||||
return colors
|
return colors
|
||||||
|
|
||||||
|
|
||||||
|
def read_file_json(input_file):
|
||||||
|
"""Read colors from a json file."""
|
||||||
|
with open(input_file) as json_file:
|
||||||
|
colors = json.load(json_file)
|
||||||
|
return colors
|
||||||
|
|
||||||
|
|
||||||
def save_file(colors, export_file):
|
def save_file(colors, export_file):
|
||||||
"""Write the colors to the file."""
|
"""Write the colors to the file."""
|
||||||
with open(export_file, "w") as file:
|
with open(export_file, "w") as file:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user