[+] Add a prompt to select backend

This commit is contained in:
Azalea 2024-05-16 20:37:55 +08:00
parent 38b8173be4
commit 4ed4f19196
2 changed files with 34 additions and 5 deletions

View file

@ -3,6 +3,7 @@ from __future__ import annotations
import argparse import argparse
import datetime import datetime
import importlib.util
import json import json
import random import random
import traceback import traceback
@ -286,9 +287,33 @@ def create_config() -> Config:
update_title('Color alignment', color_alignment) 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 # Create config
clear_screen(title) 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 # Save config
print() print()

View file

@ -352,6 +352,13 @@ def run_neofetch(asc: str, args: str = ''):
run_neofetch_cmd(f'--ascii --source {path.absolute()} --ascii-colors' + args) 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): def run_fastfetch(asc: str, args: str = '', legacy: bool = False):
""" """
Run neofetch with colors 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 :param legacy: Set true when using fastfetch < 1.8.0
""" """
# Find fastfetch binary # Find fastfetch binary
ff_path = (shutil.which('fastfetch') ff_path = fastfetch_path()
or if_file(SRC / 'fastfetch/usr/bin/fastfetch')
or if_file(SRC / 'fastfetch/fastfetch')
or if_file(SRC / 'fastfetch/fastfetch.exe'))
if not ff_path: if not ff_path:
printc("&cError: fastfetch binary is not found. Please install fastfetch first.") printc("&cError: fastfetch binary is not found. Please install fastfetch first.")