[+] Compatibility with fastfetch < 1.8.0

#62
This commit is contained in:
Azalea Gui 2023-01-14 16:36:37 -05:00
parent 4fe39b405b
commit 7960624185
No known key found for this signature in database
GPG key ID: E289FAC0DA92DD2B
2 changed files with 8 additions and 3 deletions

View file

@ -356,7 +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('-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('-p', '--preset', help=f'Use preset', choices=PRESETS.keys())
parser.add_argument('-m', '--mode', help=f'Color mode', choices=['8bit', 'rgb']) 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('-b', '--backend', help=f'Choose a *fetch backend', choices=['neofetch', 'fastfetch', 'fastfetch-old'])
parser.add_argument('--c-scale', dest='scale', help=f'Lighten colors by a multiplier', type=float) 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('--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') parser.add_argument('-V', '--version', dest='version', action='store_true', help=f'Check version')

View file

@ -265,6 +265,8 @@ def run(preset: ColorProfile, alignment: ColorAlignment, backend: BackendLiteral
return run_neofetch(preset, alignment) return run_neofetch(preset, alignment)
if backend == "fastfetch": if backend == "fastfetch":
return run_fastfetch(preset, alignment) return run_fastfetch(preset, alignment)
if backend == "fastfetch-old":
return run_fastfetch(preset, alignment, legacy=True)
def run_neofetch(preset: ColorProfile, alignment: ColorAlignment): def run_neofetch(preset: ColorProfile, alignment: ColorAlignment):
@ -290,12 +292,13 @@ def run_neofetch(preset: ColorProfile, alignment: ColorAlignment):
run_neofetch_cmd(f'--ascii --source {path.absolute()} --ascii-colors') run_neofetch_cmd(f'--ascii --source {path.absolute()} --ascii-colors')
def run_fastfetch(preset: ColorProfile, alignment: ColorAlignment): def run_fastfetch(preset: ColorProfile, alignment: ColorAlignment, legacy: bool = False):
""" """
Run neofetch with colors Run neofetch with colors
:param preset: Color palette :param preset: Color palette
:param alignment: Color alignment settings :param alignment: Color alignment settings
:param legacy: Set true when using fastfetch < 1.8.0
""" """
asc = get_distro_ascii() asc = get_distro_ascii()
asc = alignment.recolor_ascii(asc, preset) asc = alignment.recolor_ascii(asc, preset)
@ -307,7 +310,9 @@ def run_fastfetch(preset: ColorProfile, alignment: ColorAlignment):
path.write_text(asc) path.write_text(asc)
# Call fastfetch with the temp file # Call fastfetch with the temp file
subprocess.run(['fastfetch', '--file-raw', path.absolute()]) proc = subprocess.run(['fastfetch', '--raw' if legacy else '--file-raw', path.absolute()])
if proc.returncode == 144:
printc("&6Error code 144 detected: Please upgrade fastfetch to >=1.8.0 or use the 'fastfetch-old' backend")
def get_fore_back(distro: str | None = None) -> tuple[int, int] | None: def get_fore_back(distro: str | None = None) -> tuple[int, int] | None: