[+] Support fastfetch as a *fetch backend

https://github.com/dylanaraps/neofetch/issues/2257
This commit is contained in:
Hykilpikonna 2022-12-10 21:04:38 -05:00
parent 389cd91346
commit 4447313769
No known key found for this signature in database
GPG key ID: 256CD01A41D7FA26
2 changed files with 33 additions and 2 deletions

View file

@ -9,7 +9,7 @@ from itertools import permutations
from math import ceil
from typing import Iterable
from . import termenv
from . import termenv, neofetch_util
from .color_scale import Scale
from .color_util import printc, clear_screen
from .constants import *
@ -356,6 +356,7 @@ def run():
parser.add_argument('-C', '--config-file', dest='config_file', default=CONFIG_PATH, help=f'Use another config file')
parser.add_argument('-p', '--preset', help=f'Use preset', choices=PRESETS.keys())
parser.add_argument('-m', '--mode', help=f'Color mode', choices=['8bit', 'rgb'])
parser.add_argument('-b', '--backend', help=f'Choose a *fetch backend', choices=['neofetch', 'fastfetch'])
parser.add_argument('--c-scale', dest='scale', help=f'Lighten colors by a multiplier', type=float)
parser.add_argument('--c-set-l', dest='light', help=f'Set lightness value of the colors', type=float)
parser.add_argument('-V', '--version', dest='version', action='store_true', help=f'Check version')
@ -405,6 +406,8 @@ def run():
config.preset = args.preset
if args.mode:
config.mode = args.mode
if args.backend:
config.backend = args.backend
# Override global color mode
GLOBAL_CFG.color_mode = config.mode
@ -423,7 +426,7 @@ def run():
# Run
try:
run_neofetch(preset, config.color_align)
neofetch_util.run(preset, config.color_align, config.backend)
except Exception as e:
print(f'Error: {e}')
traceback.print_exc()

View file

@ -248,6 +248,14 @@ def get_distro_name():
return run_neofetch_cmd('ascii_distro_name', True)
def run(preset: ColorProfile, alignment: ColorAlignment, backend: BackendLiteral):
print(backend)
if backend == "neofetch":
return run_neofetch(preset, alignment)
if backend == "fastfetch":
return run_fastfetch(preset, alignment)
def run_neofetch(preset: ColorProfile, alignment: ColorAlignment):
"""
Run neofetch with colors
@ -271,6 +279,26 @@ def run_neofetch(preset: ColorProfile, alignment: ColorAlignment):
run_neofetch_cmd(f'--ascii --source {path.absolute()} --ascii-colors')
def run_fastfetch(preset: ColorProfile, alignment: ColorAlignment):
"""
Run neofetch with colors
:param preset: Color palette
:param alignment: Color alignment settings
"""
asc = get_distro_ascii()
asc = alignment.recolor_ascii(asc, preset)
# Write temp file
with TemporaryDirectory() as tmp_dir:
tmp_dir = Path(tmp_dir)
path = tmp_dir / 'ascii.txt'
path.write_text(asc)
# Call fastfetch with the temp file
subprocess.run(['fastfetch', '--raw', path.absolute()])
def get_fore_back(distro: str | None = None) -> tuple[int, int] | None:
"""
Get recommended foreground-background configuration for distro, or None if the distro ascii is