diff --git a/hyfetch/main.py b/hyfetch/main.py index 0c8f4c4d..8d751ea7 100755 --- a/hyfetch/main.py +++ b/hyfetch/main.py @@ -3,6 +3,7 @@ from __future__ import annotations import argparse import datetime +import importlib.util import json import random import traceback @@ -286,9 +287,33 @@ def create_config() -> Config: update_title('Color alignment', color_alignment) + ############################## + # 6. Select *fetch backend + def select_backend(): + clear_screen(title) + print_title_prompt('Select a *fetch backend') + + # Check if fastfetch is installed + ff_path = fastfetch_path() + + # Check if qwqfetch is installed (if the qwqfetch module can be imported) + has_qwqfetch = importlib.util.find_spec('qwqfetch') is not None + + printc('- &bneofetch&r: Written in bash, &nbest compatibility&r on Unix systems') + printc('- &bfastfetch&r: Written in C, &nbest performance&r ' + + ('&c(Not installed)' if ff_path is None else f'&a(Installed at {ff_path})')) + printc('- &bqwqfetch&r: Pure python, &nminimal dependencies&r ' + + ('&c(Not installed)' if not has_qwqfetch else '')) + print() + + return literal_input('Your choice?', ['neofetch', 'fastfetch', 'qwqfetch'], 'neofetch') + + backend = select_backend() + update_title('Selected backend', backend) + # Create config clear_screen(title) - c = Config(preset, color_system, light_dark, lightness, color_alignment) + c = Config(preset, color_system, light_dark, lightness, color_alignment, backend) # Save config print() diff --git a/hyfetch/neofetch_util.py b/hyfetch/neofetch_util.py index a5d820db..4890ae86 100644 --- a/hyfetch/neofetch_util.py +++ b/hyfetch/neofetch_util.py @@ -352,6 +352,13 @@ def run_neofetch(asc: str, args: str = ''): run_neofetch_cmd(f'--ascii --source {path.absolute()} --ascii-colors' + args) +def fastfetch_path() -> Path | None: + return (shutil.which('fastfetch') + or if_file(SRC / 'fastfetch/usr/bin/fastfetch') + or if_file(SRC / 'fastfetch/fastfetch') + or if_file(SRC / 'fastfetch/fastfetch.exe')) + + def run_fastfetch(asc: str, args: str = '', legacy: bool = False): """ Run neofetch with colors @@ -361,10 +368,7 @@ def run_fastfetch(asc: str, args: str = '', legacy: bool = False): :param legacy: Set true when using fastfetch < 1.8.0 """ # Find fastfetch binary - ff_path = (shutil.which('fastfetch') - or if_file(SRC / 'fastfetch/usr/bin/fastfetch') - or if_file(SRC / 'fastfetch/fastfetch') - or if_file(SRC / 'fastfetch/fastfetch.exe')) + ff_path = fastfetch_path() if not ff_path: printc("&cError: fastfetch binary is not found. Please install fastfetch first.")