[+] Export distros
This commit is contained in:
parent
8f8ecb7b94
commit
b9773b989d
311 changed files with 7061 additions and 14 deletions
|
|
@ -5,29 +5,20 @@ List distributions supported by neofetch
|
|||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import string
|
||||
import sys
|
||||
import textwrap
|
||||
from dataclasses import dataclass
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import regex
|
||||
|
||||
sys.path.append(str(Path(__file__).parent.parent))
|
||||
|
||||
from hyfetch.distro import AsciiArt
|
||||
|
||||
RE_SPLIT = regex.compile('EOF[ \n]*?;;')
|
||||
RE_COLORS = regex.compile("""(?<=set_colors )[a-z\\d ]+(?=\n)""")
|
||||
|
||||
|
||||
@dataclass
|
||||
class AsciiArt:
|
||||
match: str
|
||||
color: str
|
||||
ascii: str
|
||||
|
||||
def get_friendly_name(self) -> str:
|
||||
return self.match.split("|")[0].strip(string.punctuation + '* ')\
|
||||
.replace('"', '').replace('*', '')
|
||||
|
||||
|
||||
def substr(s: str, start: str, end: str | None = None):
|
||||
"""
|
||||
Get substring between start and end
|
||||
|
|
@ -106,6 +97,28 @@ def generate_help(max_len: int, leading: str):
|
|||
return wrap(out, max_len, leading)
|
||||
|
||||
|
||||
def export_distro(d: AsciiArt):
|
||||
"""
|
||||
Export distro to a python script
|
||||
"""
|
||||
varname = d.name.replace(' ', '_').replace('/', '_')
|
||||
ascii = d.ascii.replace('"""', '\\"""')
|
||||
script = f"""
|
||||
from hyfetch.distro import AsciiArt
|
||||
|
||||
{varname} = AsciiArt(match=\"""{d.match}\""", color='{d.color}', ascii=\"""
|
||||
{ascii}
|
||||
\""")
|
||||
"""
|
||||
Path('distros').mkdir(parents=True, exist_ok=True)
|
||||
Path(f'distros/{varname}.py').write_text(script)
|
||||
|
||||
|
||||
def export_distros():
|
||||
distros = parse_ascii_distros()
|
||||
[export_distro(d) for d in distros]
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(generate_help(100, ' ' * 32))
|
||||
print(generate_help(100, '# '))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue