Skip to content

Commit

Permalink
[+] Add custom ascii file option, closes #104
Browse files Browse the repository at this point in the history
  • Loading branch information
hykilpikonna committed Mar 21, 2023
1 parent 365ed5a commit 8c5905c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
6 changes: 5 additions & 1 deletion hyfetch/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,9 @@ def run():
parser.add_argument('--c-set-l', dest='light', help=f'Set lightness value of the colors', type=float)
parser.add_argument('-V', '--version', dest='version', action='store_true', help=f'Check version')
parser.add_argument('--debug', action='store_true', help=f'Debug mode')

parser.add_argument('--distro', '--test-distro', dest='distro', help=f'Test for a specific distro')
parser.add_argument('--ascii-file', help='Use a specific file for the ascii art')

# Hidden debug arguments
# --test-print: Print the ascii distro and exit
Expand Down Expand Up @@ -384,7 +386,9 @@ def run():

# Run
try:
neofetch_util.run(preset, config.color_align, config.backend)
asc = get_distro_ascii() if not args.ascii_file else Path(args.ascii_file).read_text("utf-8")
asc = config.color_align.recolor_ascii(asc, preset)
neofetch_util.run(asc, config.backend)
except Exception as e:
print(f'Error: {e}')
traceback.print_exc()
Expand Down
24 changes: 8 additions & 16 deletions hyfetch/neofetch_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,25 +336,21 @@ def get_distro_name():
return run_neofetch_cmd('ascii_distro_name', True)


def run(preset: ColorProfile, alignment: ColorAlignment, backend: BackendLiteral):
def run(asc: str, backend: BackendLiteral):
if backend == "neofetch":
return run_neofetch(preset, alignment)
return run_neofetch(asc)
if backend == "fastfetch":
return run_fastfetch(preset, alignment)
return run_fastfetch(asc)
if backend == "fastfetch-old":
return run_fastfetch(preset, alignment, legacy=True)
return run_fastfetch(asc, legacy=True)


def run_neofetch(preset: ColorProfile, alignment: ColorAlignment):
def run_neofetch(asc: str):
"""
Run neofetch with colors
:param preset: Color palette
:param alignment: Color alignment settings
:param asc: Ascii art
"""
asc = get_distro_ascii()
asc = alignment.recolor_ascii(asc, preset)

# Escape backslashes here because backslashes are escaped in neofetch for printf
asc = asc.replace('\\', '\\\\')

Expand All @@ -368,17 +364,13 @@ def run_neofetch(preset: ColorProfile, alignment: ColorAlignment):
run_neofetch_cmd(f'--ascii --source {path.absolute()} --ascii-colors')


def run_fastfetch(preset: ColorProfile, alignment: ColorAlignment, legacy: bool = False):
def run_fastfetch(asc: str, legacy: bool = False):
"""
Run neofetch with colors
:param preset: Color palette
:param alignment: Color alignment settings
:param asc: Ascii art
:param legacy: Set true when using fastfetch < 1.8.0
"""
asc = get_distro_ascii()
asc = alignment.recolor_ascii(asc, preset)

# Write temp file
with TemporaryDirectory() as tmp_dir:
tmp_dir = Path(tmp_dir)
Expand Down

0 comments on commit 8c5905c

Please sign in to comment.