[+] Neofetch argument passthrough

This commit is contained in:
Azalea 2023-06-02 00:18:07 -07:00
parent 2a312d0a7b
commit 0693d6e316
2 changed files with 14 additions and 9 deletions

View file

@ -309,6 +309,7 @@ def create_parser() -> argparse.ArgumentParser:
parser.add_argument('-p', '--preset', help=f'Use preset', choices=list(PRESETS.keys())) parser.add_argument('-p', '--preset', help=f'Use preset', choices=list(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', 'fastfetch-old']) parser.add_argument('-b', '--backend', help=f'Choose a *fetch backend', choices=['neofetch', 'fastfetch', 'fastfetch-old'])
parser.add_argument('--args', help=f'Additional arguments pass-through to backend')
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('--c-overlay', action='store_true', dest='overlay', help=f'Use experimental overlay color adjusting instead of HSL lightness') parser.add_argument('--c-overlay', action='store_true', dest='overlay', help=f'Use experimental overlay color adjusting instead of HSL lightness')
@ -417,7 +418,7 @@ def run():
try: try:
asc = get_distro_ascii() if not args.ascii_file else Path(args.ascii_file).read_text("utf-8") asc = get_distro_ascii() if not args.ascii_file else Path(args.ascii_file).read_text("utf-8")
asc = config.color_align.recolor_ascii(asc, preset) asc = config.color_align.recolor_ascii(asc, preset)
neofetch_util.run(asc, config.backend) neofetch_util.run(asc, config.backend, args.args or '')
except Exception as e: except Exception as e:
print(f'Error: {e}') print(f'Error: {e}')
traceback.print_exc() traceback.print_exc()

View file

@ -338,20 +338,21 @@ def get_distro_name():
return run_neofetch_cmd('ascii_distro_name', True) return run_neofetch_cmd('ascii_distro_name', True)
def run(asc: str, backend: BackendLiteral): def run(asc: str, backend: BackendLiteral, args: str = ''):
if backend == "neofetch": if backend == "neofetch":
return run_neofetch(asc) return run_neofetch(asc, args)
if backend == "fastfetch": if backend == "fastfetch":
return run_fastfetch(asc) return run_fastfetch(asc, args)
if backend == "fastfetch-old": if backend == "fastfetch-old":
return run_fastfetch(asc, legacy=True) return run_fastfetch(asc, args, legacy=True)
def run_neofetch(asc: str): def run_neofetch(asc: str, args: str = ''):
""" """
Run neofetch with colors Run neofetch with colors
:param asc: Ascii art :param asc: Ascii art
:param args: Additional arguments to pass to neofetch
""" """
# Escape backslashes here because backslashes are escaped in neofetch for printf # Escape backslashes here because backslashes are escaped in neofetch for printf
asc = asc.replace('\\', '\\\\') asc = asc.replace('\\', '\\\\')
@ -363,14 +364,17 @@ def run_neofetch(asc: str):
path.write_text(asc) path.write_text(asc)
# Call neofetch with the temp file # Call neofetch with the temp file
run_neofetch_cmd(f'--ascii --source {path.absolute()} --ascii-colors') if args:
args = ' ' + args
run_neofetch_cmd(f'--ascii --source {path.absolute()} --ascii-colors' + args)
def run_fastfetch(asc: str, legacy: bool = False): def run_fastfetch(asc: str, args: str = '', legacy: bool = False):
""" """
Run neofetch with colors Run neofetch with colors
:param asc: Ascii art :param asc: Ascii art
:param args: Additional arguments to pass to fastfetch
:param legacy: Set true when using fastfetch < 1.8.0 :param legacy: Set true when using fastfetch < 1.8.0
""" """
# Write temp file # Write temp file
@ -380,7 +384,7 @@ def run_fastfetch(asc: str, legacy: bool = False):
path.write_text(asc) path.write_text(asc)
# Call fastfetch with the temp file # Call fastfetch with the temp file
proc = subprocess.run(['fastfetch', '--raw' if legacy else '--file-raw', path.absolute()]) proc = subprocess.run(['fastfetch', '--raw' if legacy else '--file-raw', path.absolute(), *shlex.split(args)])
if proc.returncode == 144: if proc.returncode == 144:
printc("&6Error code 144 detected: Please upgrade fastfetch to >=1.8.0 or use the 'fastfetch-old' backend") printc("&6Error code 144 detected: Please upgrade fastfetch to >=1.8.0 or use the 'fastfetch-old' backend")