Skip to content

Commit

Permalink
[+] Add a prompt to select backend
Browse files Browse the repository at this point in the history
  • Loading branch information
hykilpikonna committed May 16, 2024
1 parent 38b8173 commit 4ed4f19
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
27 changes: 26 additions & 1 deletion hyfetch/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import argparse
import datetime
import importlib.util
import json
import random
import traceback
Expand Down Expand Up @@ -286,9 +287,33 @@ def select_lightness():

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()
Expand Down
12 changes: 8 additions & 4 deletions hyfetch/neofetch_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.")
Expand Down

0 comments on commit 4ed4f19

Please sign in to comment.