summaryrefslogtreecommitdiff
path: root/pywal/set_colors.py
diff options
context:
space:
mode:
authorDylan Araps <dylan.araps@gmail.com>2017-06-26 12:09:35 +1000
committerDylan Araps <dylan.araps@gmail.com>2017-06-26 12:09:35 +1000
commit583a0c19ad2f67a54130a219eeeaccf53ea08ded (patch)
treea72b51a6cf219c46c55f8fe9033814c48d23d48b /pywal/set_colors.py
parentd17282cdc01a41cc70e0919ace55715eac3dd6d1 (diff)
General: Split wal into multiple files.
Diffstat (limited to 'pywal/set_colors.py')
-rw-r--r--pywal/set_colors.py92
1 files changed, 92 insertions, 0 deletions
diff --git a/pywal/set_colors.py b/pywal/set_colors.py
new file mode 100644
index 0000000..4b3c74f
--- /dev/null
+++ b/pywal/set_colors.py
@@ -0,0 +1,92 @@
+"""
+Send sequences to all open terminals.
+"""
+import os
+
+from pywal import settings as s
+from pywal import util
+
+
+def set_special(index, color):
+ """Build the escape sequence for special colors."""
+ s.ColorType.sequences.append(f"\\033]{index};{color}\\007")
+
+ if index == 10:
+ s.ColorType.xrdb.append(f"URxvt*foreground: {color}")
+ s.ColorType.xrdb.append(f"XTerm*foreground: {color}")
+
+ elif index == 11:
+ s.ColorType.xrdb.append(f"URxvt*background: {color}")
+ s.ColorType.xrdb.append(f"XTerm*background: {color}")
+
+ elif index == 12:
+ s.ColorType.xrdb.append(f"URxvt*cursorColor: {color}")
+ s.ColorType.xrdb.append(f"XTerm*cursorColor: {color}")
+
+ elif index == 66:
+ s.ColorType.xrdb.append(f"*.color{index}: {color}")
+ s.ColorType.xrdb.append(f"*color{index}: {color}")
+ s.ColorType.sequences.append(f"\\033]4;{index};{color}\\007")
+
+
+def set_color(index, color):
+ """Build the escape sequence we need for each color."""
+ s.ColorType.xrdb.append(f"*.color{index}: {color}")
+ s.ColorType.xrdb.append(f"*color{index}: {color}")
+ s.ColorType.sequences.append(f"\\033]4;{index};{color}\\007")
+ s.ColorType.shell.append(f"color{index}='{color}'")
+ s.ColorType.css.append(f"\t--color{index}: {color};")
+ s.ColorType.scss.append(f"$color{index}: {color};")
+
+ rgb = util.hex_to_rgb(color)
+ s.ColorType.putty.append(f"\"Colour{index}\"=\"{rgb}\"")
+
+
+def set_grey(colors):
+ """Set a grey color based on brightness of color0."""
+ return {
+ 0: "#666666",
+ 1: "#666666",
+ 2: "#757575",
+ 3: "#999999",
+ 4: "#999999",
+ 5: "#8a8a8a",
+ 6: "#a1a1a1",
+ 7: "#a1a1a1",
+ 8: "#a1a1a1",
+ 9: "#a1a1a1",
+ }.get(int(colors[0][1]), colors[7])
+
+
+def send_sequences(colors, vte):
+ """Send colors to all open terminals."""
+ set_special(10, colors[15])
+ set_special(11, colors[0])
+ set_special(12, colors[15])
+ set_special(13, colors[15])
+ set_special(14, colors[0])
+
+ # This escape sequence doesn"t work in VTE terminals.
+ if not vte:
+ set_special(708, colors[0])
+
+ # Create the sequences.
+ # pylint: disable=W0106
+ [set_color(num, color) for num, color in enumerate(colors)]
+
+ # Set a blank color that isn"t affected by bold highlighting.
+ set_special(66, colors[0])
+
+ # Make the terminal interpret escape sequences.
+ sequences = util.fix_escape("".join(s.ColorType.sequences))
+
+ # Get a list of terminals.
+ terminals = [f"/dev/pts/{term}" for term in os.listdir("/dev/pts/")
+ if len(term) < 4]
+ terminals.append(s.CACHE_DIR / "sequences")
+
+ # Send the sequences to all open terminals.
+ # pylint: disable=W0106
+ [util.save_file(sequences, term) for term in terminals]
+
+ print("colors: Set terminal colors")