def __init__(self): self.base_path = Path().home() / '.config' / 'alacritty' if not self.base_path.exists(): raise ConfigError(f'Config directory not found: {self.base_path}') self.config_file = self.base_path / 'alacritty.yml' if not self.config_file.is_file(): log.warn('Config file not found') self.config_file.touch() print('Created config file =>', end=' ') log.color_print(self.config_file, log.Color.BLUE) self.config = self._load(self.config_file) if self.config is None: self.config = {} log.warn('Alacritty config file was empty') self.resources = { 'themes': { 'type': 'Themes directory', 'path': self.base_path / 'themes', 'exists': lambda: self.resources['themes']['path'].is_dir(), 'create': lambda: self.resources['themes']['path'].mkdir() }, 'fonts': { 'type': 'Fonts file', 'path': self.base_path / 'fonts.yaml', 'exists': lambda: self.resources['fonts']['path'].is_file(), 'create': lambda: self.resources['fonts']['path'].touch() } }
def list_fonts(): fonts = self._load(self._resource_path('fonts')) if fonts is None or 'fonts' not in fonts: log.warn('Cannot list fonts, no fonts found') else: log.color_print('Fonts:', log.Color.BOLD) for font in fonts['fonts']: log.color_print(f' {font}', log.Color.PURPLE)
def print_theme(theme: str): themes_dir = self._resource_path('themes') theme_file = themes_dir / f'{theme}.yaml' if not theme_file.is_file(): raise ConfigError( f'Failed printing "{theme}" theme, "{theme_file}" not found' ) log.color_print(theme_file, log.Color.BOLD) print(yaml.dump(self._load(theme_file)))
def list_themes(): themes_dir = self._resource_path('themes') themes = [file.name.split('.')[0] for file in themes_dir.iterdir()] if len(themes) < 1: log.warn('Cannot list themes, themes directory is empty') else: log.color_print('Themes:', log.Color.BOLD) for theme in themes: log.color_print(f' {theme}', log.Color.BLUE)
def _resource_path(self, resource: str) -> Path: if resource not in self.resources: raise ConfigError(f'Path for resource "{resource}" not set') resource = self.resources[resource] if not resource['exists'](): log.warn(f'{resource["type"]} not found') resource['create']() print('Created resource =>', end=' ') log.color_print(resource['path'].absolute(), log.Color.BLUE) return resource['path']
def print_fonts(): fonts_file = self._resource_path('fonts') log.color_print(fonts_file, log.Color.BOLD) print(yaml.dump(self._load(fonts_file)))
def print_config(): log.color_print(self.config_file, log.Color.BOLD) print(yaml.dump(self.config))