Exemplo n.º 1
0
def get_colors(img, quiet):
    """Generate a colorscheme using imagemagick."""
    # Cache the wallpaper name.
    util.save_file(img, CACHE_DIR / "wal")

    # Cache the sequences file.
    cache_file = pathlib.Path(CACHE_DIR / "schemes" / img.replace("/", "_"))

    if cache_file.is_file():
        colors = util.read_file(cache_file)
        print("colors: Found cached colorscheme.")

    else:
        print("colors: Generating a colorscheme...")
        if not quiet:
            util.disown("notify-send", "wal: Generating a colorscheme...")

        # Generate the colors.
        colors = gen_colors(img)
        colors = sort_colors(colors)

        # Cache the colorscheme.
        util.save_file("\n".join(colors), cache_file)

        print("colors: Generated colorscheme")
        if not quiet:
            util.disown("notify-send", "wal: Generation complete.")

    return colors
Exemplo n.º 2
0
def get_colors(img, quiet):
    """Get the colorscheme."""
    # Cache the wallpaper name.
    util.save_file(img, CACHE_DIR / "wal")

    # Cache the sequences file.
    # _home_dylan_img_jpg.json
    cache_file = CACHE_DIR / "schemes" / \
        img.replace("/", "_").replace(".", "_")
    cache_file = cache_file.with_suffix(".json")

    if cache_file.is_file():
        colors = util.read_file_json(cache_file)
        print("colors: Found cached colorscheme.")

    else:
        print("colors: Generating a colorscheme...")
        if not quiet:
            util.disown("notify-send", "wal: Generating a colorscheme...")

        # Generate the colors.
        colors = gen_colors(img)
        colors = sort_colors(img, colors)

        # Cache the colorscheme.
        util.save_file_json(colors, cache_file)

        print("colors: Generated colorscheme")
        if not quiet:
            util.disown("notify-send", "wal: Generation complete.")

    return colors
Exemplo n.º 3
0
def send_sequences(colors, vte):
    """Send colors to all open terminals."""
    sequences = [set_color(num, color) for num, color in enumerate(colors)]
    sequences.append(set_special(10, colors[15]))
    sequences.append(set_special(11, colors[0]))
    sequences.append(set_special(12, colors[15]))
    sequences.append(set_special(13, colors[15]))
    sequences.append(set_special(14, colors[0]))

    # Set a blank color that isn"t affected by bold highlighting.
    sequences.append(set_color(66, colors[0]))

    # This escape sequence doesn"t work in VTE terminals.
    if not vte:
        sequences.append(set_special(708, colors[0]))

    # Get a list of terminals.
    terminals = [
        f"/dev/pts/{term}" for term in os.listdir("/dev/pts/") if len(term) < 4
    ]
    terminals.append(CACHE_DIR / "sequences")

    # Send the sequences to all open terminals.
    # pylint: disable=W0106
    [util.save_file("".join(sequences), term) for term in terminals]

    print("colors: Set terminal colors")
Exemplo n.º 4
0
def template(colors, input_file, output_dir):
    """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)

    # Get the template name.
    template_file = os.path.basename(input_file)

    # Export the template.
    output_file = output_dir / template_file
    util.save_file(template_data, output_file)

    print(f"export: Exported {template_file}.")
Exemplo n.º 5
0
def send_sequences(colors, vte):
    """Send colors to all open terminals."""
    # Colors 0-15.
    sequences = [
        set_color(num, color)
        for num, color in enumerate(colors["colors"].values())
    ]

    # Special colors.
    # http://pod.tst.eu/http://cvs.schmorp.de/rxvt-unicode/doc/rxvt.7.pod#XTerm_Operating_System_Commands
    # 10 = foreground, 11 = background, 12 = cursor foregound
    # 13 = mouse foreground
    sequences.append(set_special(10, colors["special"]["foreground"]))
    sequences.append(set_special(11, colors["special"]["background"]))
    sequences.append(set_special(12, colors["special"]["cursor"]))
    sequences.append(set_special(13, colors["special"]["cursor"]))

    # Set a blank color that isn"t affected by bold highlighting.
    # Used in wal.vim's airline theme.
    sequences.append(set_color(66, colors["special"]["background"]))

    # This escape sequence doesn"t work in VTE terminals.
    if not vte:
        sequences.append(set_special(708, colors["special"]["background"]))

    # Get the list of terminals.
    terminals = [
        f"/dev/pts/{term}" for term in os.listdir("/dev/pts/") if len(term) < 4
    ]
    terminals.append(CACHE_DIR / "sequences")

    # Send the sequences to all open terminals.
    # pylint: disable=W0106
    [util.save_file("".join(sequences), term) for term in terminals]

    print("colors: Set terminal colors")
Exemplo n.º 6
0
 def test_save_file(self):
     """> Save colors to a file."""
     tmp_file = pathlib.Path("/tmp/test_file")
     util.save_file("Hello, world", tmp_file)
     result = tmp_file.is_file()
     self.assertTrue(result)
Exemplo n.º 7
0
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}.")
Exemplo n.º 8
0
 def test_save_file(self):
     """> Save colors to a file."""
     tmp_file = "/tmp/test_file"
     util.save_file("Hello, world", tmp_file)
     result = os.path.isfile(tmp_file)
     self.assertTrue(result)