From 58c80b2b1df4b9979133fc741378e9a6e3b39722 Mon Sep 17 00:00:00 2001 From: Fabian Ising Date: Sun, 3 Sep 2023 12:55:32 +0200 Subject: [PATCH] [alacritty] Screenshot mode --- .config/alacritty/color_switcher.py | 18 ++++++------- .config/alacritty/screenshot_mode.py | 40 ++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 .config/alacritty/screenshot_mode.py diff --git a/.config/alacritty/color_switcher.py b/.config/alacritty/color_switcher.py index 557a5df..568032b 100755 --- a/.config/alacritty/color_switcher.py +++ b/.config/alacritty/color_switcher.py @@ -3,10 +3,9 @@ import os import re - -CONFIG_FILE_NAME = "schemes.yml" +SCHEME_FILE_NAME = "schemes.yml" CONFIG_FILE_DIR = os.path.expanduser("~/.config/alacritty/") -CONFIG_FILE_PATH = os.path.join(CONFIG_FILE_DIR, CONFIG_FILE_NAME) +SCHEME_FILE_PATH = os.path.join(CONFIG_FILE_DIR, SCHEME_FILE_NAME) COLOR_SCHEME_LINE_SEARCH = "colors: \*(\S+)" COLOR_SCHEME_LINE_TEMPLATE = "colors: *{}\n" @@ -19,9 +18,9 @@ NVIM_COLOR_SCHEME_LINE_SEARCH = "set background=(\S+)\ncolorscheme (\S+)" NVIM_COLOR_SCHEME_LINE_TEMPLATE = "set background={}\ncolorscheme {}" def change_alacritty_theme(): - with open(CONFIG_FILE_PATH, "r") as config_file: - config_file.seek(0) - lines = config_file.readlines() + with open(SCHEME_FILE_PATH, "r") as scheme_file: + scheme_file.seek(0) + lines = scheme_file.readlines() colors_line_index = -1 for i, line in enumerate(lines): @@ -30,7 +29,6 @@ def change_alacritty_theme(): current_color_scheme = match.group(1) colors_line_index = i - if current_color_scheme == "dark_mode": new_scheme = "solarized_light" else: @@ -38,10 +36,10 @@ def change_alacritty_theme(): lines[colors_line_index] = COLOR_SCHEME_LINE_TEMPLATE.format( new_scheme) - - with open(CONFIG_FILE_PATH, "w") as config_file: + with open(SCHEME_FILE_PATH, "w") as scheme_file: for line in lines: - config_file.write(line) + scheme_file.write(line) + return new_scheme def change_vim_theme(light_mode=False): diff --git a/.config/alacritty/screenshot_mode.py b/.config/alacritty/screenshot_mode.py new file mode 100644 index 0000000..b94123f --- /dev/null +++ b/.config/alacritty/screenshot_mode.py @@ -0,0 +1,40 @@ +#! /usr/bin/env python3 +# vim:fenc=utf-8 +# +# Copyright © 2023 ising +# +# Distributed under terms of the MIT license. + +""" + +""" +import os +import sys + +CONFIG_FILE_NAME = "alacritty.yml" +CONFIG_FILE_DIR = os.path.expanduser("~/.config/alacritty/") +CONFIG_FILE_PATH = os.path.join(CONFIG_FILE_DIR, CONFIG_FILE_NAME) + +def main(turn_on=False): + padding_line = None + with open(CONFIG_FILE_PATH, "r") as config_file: + config_file.seek(0) + config_lines = config_file.readlines() + for i, line in enumerate(config_lines): + if "padding:" in line and "x:" in config_lines[i+1]: + padding_line = i + if padding_line is None: + return + if turn_on: + config_lines[padding_line+1] = " x: 10\n" + config_lines[padding_line+2] = " y: 10\n" + else: + config_lines[padding_line+1] = " x: 0\n" + config_lines[padding_line+2] = " y: 0\n" + with open(CONFIG_FILE_PATH, "w") as config_file: + for line in config_lines: + config_file.write(line) + +if __name__=="__main__": + main(len(sys.argv) == 2 and sys.argv[1] == "on") +