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 complete_themes_args(ans: Completions, opt: Optional[OptionDict], prefix: str, unknown_args: Delegate) -> None: if opt is None: from kittens.themes.collection import load_themes themes = load_themes(cache_age=-1, ignore_no_cache=True) names = tuple(t.name for t in themes if t.name.startswith(prefix)) ans.add_match_group('Themes', names) else: complete_basic_option_args(ans, opt, prefix)