[O] Adapt fore-back configuration

This commit is contained in:
Azalea (on HyDEV-Daisy) 2022-07-29 10:37:46 -04:00
parent e35db2b838
commit 4835bbba40
2 changed files with 33 additions and 14 deletions

View file

@ -13,7 +13,8 @@ from hyfetch import presets
from .color_util import printc, color, clear_screen, LightDark from .color_util import printc, color, clear_screen, LightDark
from .constants import CONFIG_PATH, VERSION, TERM_LEN, TEST_ASCII_WIDTH, TEST_ASCII, GLOBAL_CFG from .constants import CONFIG_PATH, VERSION, TERM_LEN, TEST_ASCII_WIDTH, TEST_ASCII, GLOBAL_CFG
from .models import Config from .models import Config
from .neofetch_util import run_neofetch, get_distro_ascii, ColorAlignment, ascii_size, color_alignments from .neofetch_util import run_neofetch, get_distro_ascii, ColorAlignment, ascii_size, fore_back, \
get_fore_back
from .presets import PRESETS from .presets import PRESETS
@ -181,14 +182,12 @@ def create_config() -> Config:
color_alignment = None color_alignment = None
while True: while True:
clear_screen(title) clear_screen(title)
printc(f'&a5. Let\'s choose a color arrangement!')
printc(f'You can choose standard horizontal or vertical alignment, or use one of the random color schemes, or assign colors yourself (TODO).')
print()
asc = get_distro_ascii() asc = get_distro_ascii()
asc_width = ascii_size(asc)[0] asc_width = ascii_size(asc)[0]
fore_back = get_fore_back()
asciis = [ asciis = [
[*ColorAlignment('horizontal').recolor_ascii(asc, _prs).split('\n'), 'Horizontal'.center(asc_width)], [*ColorAlignment('horizontal', fore_back=fore_back).recolor_ascii(asc, _prs).split('\n'), 'Horizontal'.center(asc_width)],
[*ColorAlignment('vertical').recolor_ascii(asc, _prs).split('\n'), 'Vertical'.center(asc_width)], [*ColorAlignment('vertical').recolor_ascii(asc, _prs).split('\n'), 'Vertical'.center(asc_width)],
] ]
ascii_per_row = TERM_LEN // (asc_width + 2) ascii_per_row = TERM_LEN // (asc_width + 2)
@ -216,7 +215,9 @@ def create_config() -> Config:
[printc(' '.join(line)) for line in zip(*current)] [printc(' '.join(line)) for line in zip(*current)]
print() print()
print('Choose a color arrangement. You can type "roll" to randomize again.') printc(f'&a5. Let\'s choose a color arrangement!')
printc(f'You can choose standard horizontal or vertical alignment, or use one of the random color schemes.')
print('You can type "roll" to randomize again.')
print() print()
choice = literal_input(f'Your choice?', ['horizontal', 'vertical', 'roll'] + [f'random{i}' for i in range(random_count)], 'horizontal') choice = literal_input(f'Your choice?', ['horizontal', 'vertical', 'roll'] + [f'random{i}' for i in range(random_count)], 'horizontal')
@ -312,7 +313,7 @@ def run():
# Debug recommendations # Debug recommendations
if args.debug_list: if args.debug_list:
distro = args.debug_list distro = args.debug_list
ca = color_alignments[distro] ca = fore_back[distro]
print(distro) print(distro)
GLOBAL_CFG.override_distro = distro GLOBAL_CFG.override_distro = distro

View file

@ -150,6 +150,10 @@ def get_distro_ascii(distro: str | None = None) -> str:
return normalize_ascii(check_output([get_command_path(), cmd]).decode().strip()) return normalize_ascii(check_output([get_command_path(), cmd]).decode().strip())
def get_distro_name():
return check_output([get_command_path(), 'ascii_distro_name']).decode().strip()
def run_neofetch(preset: ColorProfile, alignment: ColorAlignment): def run_neofetch(preset: ColorProfile, alignment: ColorAlignment):
asc = get_distro_ascii() asc = get_distro_ascii()
w, h = ascii_size(asc) w, h = ascii_size(asc)
@ -179,12 +183,26 @@ def run_neofetch(preset: ColorProfile, alignment: ColorAlignment):
subprocess.run(full_cmd) subprocess.run(full_cmd)
# Color alignment recommendations def get_fore_back(distro: str | None = None) -> tuple[int, int] | None:
color_alignments = { """
'fedora': ColorAlignment('horizontal', fore_back=(2, 1)), Get recommended foreground-background configuration for distro, or None if the distro ascii is
'ubuntu': ColorAlignment('horizontal', fore_back=(2, 1)), not suitable for fore-back configuration.
'NixOS.*': ColorAlignment('custom', {1: 1, 2: 0}),
# 'arch': ColorAlignment('horizontal'), :return:
# 'centos': ColorAlignment('horizontal'), """
if not distro and GLOBAL_CFG.override_distro:
distro = GLOBAL_CFG.override_distro
if not distro:
distro = get_distro_name().lower()
for k, v in fore_back.items():
if distro.startswith(k.lower()):
return v
return None
# Foreground-background recommendation
fore_back = {
'fedora': (2, 1),
'ubuntu': (2, 1),
} }