From 0693d6e3169b8487f7463bb417c0ff9719b1c392 Mon Sep 17 00:00:00 2001 From: Azalea Date: Fri, 2 Jun 2023 00:18:07 -0700 Subject: [PATCH] [+] Neofetch argument passthrough --- hyfetch/main.py | 3 ++- hyfetch/neofetch_util.py | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/hyfetch/main.py b/hyfetch/main.py index 3bb6f46d..3fe144fb 100755 --- a/hyfetch/main.py +++ b/hyfetch/main.py @@ -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('-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('--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-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') @@ -417,7 +418,7 @@ def run(): try: 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) - neofetch_util.run(asc, config.backend) + neofetch_util.run(asc, config.backend, args.args or '') except Exception as e: print(f'Error: {e}') traceback.print_exc() diff --git a/hyfetch/neofetch_util.py b/hyfetch/neofetch_util.py index 49a2d971..5a579491 100644 --- a/hyfetch/neofetch_util.py +++ b/hyfetch/neofetch_util.py @@ -338,20 +338,21 @@ def get_distro_name(): 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": - return run_neofetch(asc) + return run_neofetch(asc, args) if backend == "fastfetch": - return run_fastfetch(asc) + return run_fastfetch(asc, args) 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 :param asc: Ascii art + :param args: Additional arguments to pass to neofetch """ # Escape backslashes here because backslashes are escaped in neofetch for printf asc = asc.replace('\\', '\\\\') @@ -363,14 +364,17 @@ def run_neofetch(asc: str): path.write_text(asc) # 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 :param asc: Ascii art + :param args: Additional arguments to pass to fastfetch :param legacy: Set true when using fastfetch < 1.8.0 """ # Write temp file @@ -380,7 +384,7 @@ def run_fastfetch(asc: str, legacy: bool = False): path.write_text(asc) # 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: printc("&6Error code 144 detected: Please upgrade fastfetch to >=1.8.0 or use the 'fastfetch-old' backend")