[PR] #148 from nexplorer-3e: add qwqfetch backend
This commit is contained in:
commit
db54e8990d
3 changed files with 56 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
33
tools/extract_color.py
Normal file
33
tools/extract_color.py
Normal file
|
@ -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)
|
Loading…
Reference in a new issue