Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add qwqfetch backend #148

Merged
merged 3 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hyfetch/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions hyfetch/neofetch_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_qwqfetch(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:
import qwqfetch
# distro_detector only return a bash variable
# so we use qwqfetch builtin distro detector
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
raise e

def run_neofetch(asc: str, args: str = ''):
"""
Run neofetch with colors
Expand Down
33 changes: 33 additions & 0 deletions tools/extract_color.py
Original file line number Diff line number Diff line change
@@ -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)