From 8c5905c8586a0c7e1505e874da32ad2b9659f5e8 Mon Sep 17 00:00:00 2001 From: Azalea Gui Date: Mon, 20 Mar 2023 23:31:14 -0400 Subject: [PATCH] [+] Add custom ascii file option, closes #104 --- hyfetch/main.py | 6 +++++- hyfetch/neofetch_util.py | 24 ++++++++---------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/hyfetch/main.py b/hyfetch/main.py index c4e4d34f..3dc3dd1a 100755 --- a/hyfetch/main.py +++ b/hyfetch/main.py @@ -320,7 +320,9 @@ def run(): 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('--debug', action='store_true', help=f'Debug mode') + parser.add_argument('--distro', '--test-distro', dest='distro', help=f'Test for a specific distro') + parser.add_argument('--ascii-file', help='Use a specific file for the ascii art') # Hidden debug arguments # --test-print: Print the ascii distro and exit @@ -384,7 +386,9 @@ def run(): # Run try: - neofetch_util.run(preset, config.color_align, config.backend) + 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) except Exception as e: print(f'Error: {e}') traceback.print_exc() diff --git a/hyfetch/neofetch_util.py b/hyfetch/neofetch_util.py index 48538bae..b135c946 100644 --- a/hyfetch/neofetch_util.py +++ b/hyfetch/neofetch_util.py @@ -336,25 +336,21 @@ def get_distro_name(): return run_neofetch_cmd('ascii_distro_name', True) -def run(preset: ColorProfile, alignment: ColorAlignment, backend: BackendLiteral): +def run(asc: str, backend: BackendLiteral): if backend == "neofetch": - return run_neofetch(preset, alignment) + return run_neofetch(asc) if backend == "fastfetch": - return run_fastfetch(preset, alignment) + return run_fastfetch(asc) if backend == "fastfetch-old": - return run_fastfetch(preset, alignment, legacy=True) + return run_fastfetch(asc, legacy=True) -def run_neofetch(preset: ColorProfile, alignment: ColorAlignment): +def run_neofetch(asc: str): """ Run neofetch with colors - :param preset: Color palette - :param alignment: Color alignment settings + :param asc: Ascii art """ - asc = get_distro_ascii() - asc = alignment.recolor_ascii(asc, preset) - # Escape backslashes here because backslashes are escaped in neofetch for printf asc = asc.replace('\\', '\\\\') @@ -368,17 +364,13 @@ def run_neofetch(preset: ColorProfile, alignment: ColorAlignment): run_neofetch_cmd(f'--ascii --source {path.absolute()} --ascii-colors') -def run_fastfetch(preset: ColorProfile, alignment: ColorAlignment, legacy: bool = False): +def run_fastfetch(asc: str, legacy: bool = False): """ Run neofetch with colors - :param preset: Color palette - :param alignment: Color alignment settings + :param asc: Ascii art :param legacy: Set true when using fastfetch < 1.8.0 """ - asc = get_distro_ascii() - asc = alignment.recolor_ascii(asc, preset) - # Write temp file with TemporaryDirectory() as tmp_dir: tmp_dir = Path(tmp_dir)