def change_colors(color_scheme: str) -> bool: if not color_scheme: return False from kittens.themes.collection import (NoCacheFound, load_themes, text_as_opts) from kittens.themes.main import colors_as_escape_codes if color_scheme.endswith('.conf'): conf_file = resolve_abs_or_config_path(color_scheme) try: with open(conf_file) as f: opts = text_as_opts(f.read()) except FileNotFoundError: raise SystemExit( f'Failed to find the color conf file: {expandvars(conf_file)}') else: try: themes = load_themes(-1) except NoCacheFound: themes = load_themes() cs = expandvars(color_scheme) try: theme = themes[cs] except KeyError: raise SystemExit(f'Failed to find the color theme: {cs}') opts = theme.kitty_opts raw = colors_as_escape_codes(opts) print(save_colors(), sep='', end=raw, flush=True) return True
def config_or_absolute_path(x: str, env: Optional[Dict[str, str]] = None) -> Optional[str]: if not x or x.lower() == 'none': return None return resolve_abs_or_config_path(x, env)
def path_to_custom_kitten(config_dir: str, kitten: str) -> str: path = resolve_abs_or_config_path(kitten, conf_dir=config_dir) return os.path.abspath(path)