From a97d2805b1765e500c738dd1b5f16b96f066f2e6 Mon Sep 17 00:00:00 2001 From: eval Nya <60149113+nexplorer-3e@users.noreply.github.com> Date: Mon, 3 Jul 2023 23:51:29 +0800 Subject: [PATCH 1/3] tools: chore: add extract_color.py dump ansi code number from neofetch script --- tools/extract_color.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tools/extract_color.py diff --git a/tools/extract_color.py b/tools/extract_color.py new file mode 100644 index 000000000..bab3b1fee --- /dev/null +++ b/tools/extract_color.py @@ -0,0 +1,33 @@ +import re, json + +distro_color = {} + + +def color(colornum): # see neofetch color() + reset = "\e[0m" + ascii_bold = "\e[1m" + if colornum == "fg" or colornum == "7": + return f"\e[37m{reset}" + if colornum == "#": + pass # TODO + if int(colornum) >= 0 and int(colornum) < 7: + return f"{reset}\e[3{colornum}m" + return f"\e38;5;{colornum}m" + + +with open("neofetch") as f: + s = f.read() +l = iter(s.split("\n")) +for i in l: + p = re.search(r'"\D+"\*\)', i) + if p is None: + continue + distros = re.sub(r"\"|\)|\*", "", i.strip(" ")).split("|") + c = next(l).strip(" ") + if "set_colors" not in c: + continue + colors = c.split(" ")[1:] + for dist in distros: + distro_color[dist.strip(" ").rstrip(" ")] = colors +with open("distcolor.json", "w") as f: + json.dump(distro_color, f) From ed377261a2d7c3c5e09abc081935a230d2536b8a Mon Sep 17 00:00:00 2001 From: eval Nya <60149113+nexplorer-3e@users.noreply.github.com> Date: Mon, 3 Jul 2023 23:54:46 +0800 Subject: [PATCH 2/3] feat: add qwqfetch backend --- hyfetch/main.py | 2 +- hyfetch/neofetch_util.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/hyfetch/main.py b/hyfetch/main.py index 14f71aed3..3462e06dc 100755 --- a/hyfetch/main.py +++ b/hyfetch/main.py @@ -308,7 +308,7 @@ def create_parser() -> argparse.ArgumentParser: 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=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('-b', '--backend', help=f'Choose a *fetch backend', choices=['qwqfetch', '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) diff --git a/hyfetch/neofetch_util.py b/hyfetch/neofetch_util.py index 5a5794913..0dd4e26f4 100644 --- a/hyfetch/neofetch_util.py +++ b/hyfetch/neofetch_util.py @@ -345,8 +345,30 @@ def run(asc: str, backend: BackendLiteral, args: str = ''): return run_fastfetch(asc, args) if backend == "fastfetch-old": return run_fastfetch(asc, args, legacy=True) + if backend == "qwqfetch": + return run_qwqfetch(asc, args) +def run_neofetch(asc: str, args: str = ''): + """ + Run neofetch with colors + + :param preset: Color palette + :param alignment: Color alignment settings + """ + asc = asc.replace('\\', '\\\\') + + # call qwqfetch to print string + try: + from qwqfetch import src + # distro_detector only return a bash variable + # so we use qwqfetch builtin distro detector + print(src.get_result(asc)) + except ImportError as e: # module not found etc + print("qwqfetch is not installed. Install it by executing:") # use print to output hint directly + print("pip install git+https://github.com/nexplorer-3e/qwqfetch") # TODO: public repo + raise e + def run_neofetch(asc: str, args: str = ''): """ Run neofetch with colors From 673de9bb5337f5dd676f730537f1c19deed36697 Mon Sep 17 00:00:00 2001 From: eval Nya <60149113+nexplorer-3e@users.noreply.github.com> Date: Tue, 11 Jul 2023 14:21:36 +0800 Subject: [PATCH 3/3] run_qwqfetch: rename & change entry point --- hyfetch/neofetch_util.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hyfetch/neofetch_util.py b/hyfetch/neofetch_util.py index 0dd4e26f4..98fc6c4d6 100644 --- a/hyfetch/neofetch_util.py +++ b/hyfetch/neofetch_util.py @@ -349,7 +349,7 @@ def run(asc: str, backend: BackendLiteral, args: str = ''): return run_qwqfetch(asc, args) -def run_neofetch(asc: str, args: str = ''): +def run_qwqfetch(asc: str, args: str = ''): """ Run neofetch with colors @@ -360,10 +360,10 @@ def run_neofetch(asc: str, args: str = ''): # call qwqfetch to print string try: - from qwqfetch import src + import qwqfetch # distro_detector only return a bash variable # so we use qwqfetch builtin distro detector - print(src.get_result(asc)) + print(qwqfetch.get_ascres(asc)) except ImportError as e: # module not found etc print("qwqfetch is not installed. Install it by executing:") # use print to output hint directly print("pip install git+https://github.com/nexplorer-3e/qwqfetch") # TODO: public repo