[+] Run neofetch with a preset

This commit is contained in:
Azalea (on HyDEV-Daisy) 2022-04-10 05:11:45 -04:00
parent 3f0331a307
commit 1389a5b2ce

View file

@ -1,8 +1,13 @@
import os
import re
from pathlib import Path
from subprocess import check_output
from tempfile import TemporaryDirectory
import pkg_resources
from .presets import ColorProfile
def get_command_path() -> str:
"""
@ -13,11 +18,34 @@ def get_command_path() -> str:
return pkg_resources.resource_filename(__name__, 'scripts/neofetch_mod.sh')
def get_distro_ascii_lines() -> int:
def get_distro_ascii() -> str:
"""
Get how many lines are in the distro ascii
Get the distro ascii
:return: Number of lines
:return: Distro ascii
"""
out = check_output([get_command_path(), "print_ascii"])
return len(out.decode().strip().split('\n'))
return check_output([get_command_path(), "print_ascii"]).decode().strip()
def run(preset: ColorProfile):
# Get existing ascii
asc = get_distro_ascii()
# Remove existing colors
asc = re.sub('\\${.*?}', '', asc)
# Add new colors
lines = asc.split('\n')
colors = preset.with_length(len(lines))
asc = '\n'.join([colors[i].to_ansi_rgb() + l for i, l in enumerate(lines)])
# Write temp file
with TemporaryDirectory() as tmp_dir:
tmp_dir = Path(tmp_dir)
path = tmp_dir / 'ascii.txt'
path.write_text(asc)
# Call neofetch with the temp file
os.environ['ascii_len'] = str(max(len(l) for l in lines))
os.environ['ascii_lines'] = str(len(lines))
os.system(get_command_path() + f' --ascii --source {path.absolute()} --ascii-colors')