diff --git a/hyfetch/main.py b/hyfetch/main.py index 7f1fcae9..e5352548 100755 --- a/hyfetch/main.py +++ b/hyfetch/main.py @@ -13,7 +13,8 @@ from hyfetch import presets 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 .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 @@ -181,14 +182,12 @@ def create_config() -> Config: color_alignment = None while True: 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_width = ascii_size(asc)[0] + fore_back = get_fore_back() 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)], ] ascii_per_row = TERM_LEN // (asc_width + 2) @@ -216,7 +215,9 @@ def create_config() -> Config: [printc(' '.join(line)) for line in zip(*current)] 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() 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 if args.debug_list: distro = args.debug_list - ca = color_alignments[distro] + ca = fore_back[distro] print(distro) GLOBAL_CFG.override_distro = distro diff --git a/hyfetch/neofetch_util.py b/hyfetch/neofetch_util.py index 51d87bfe..4b095647 100644 --- a/hyfetch/neofetch_util.py +++ b/hyfetch/neofetch_util.py @@ -150,6 +150,10 @@ def get_distro_ascii(distro: str | None = None) -> str: 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): asc = get_distro_ascii() w, h = ascii_size(asc) @@ -179,12 +183,26 @@ def run_neofetch(preset: ColorProfile, alignment: ColorAlignment): subprocess.run(full_cmd) -# Color alignment recommendations -color_alignments = { - 'fedora': ColorAlignment('horizontal', fore_back=(2, 1)), - 'ubuntu': ColorAlignment('horizontal', fore_back=(2, 1)), - 'NixOS.*': ColorAlignment('custom', {1: 1, 2: 0}), - # 'arch': ColorAlignment('horizontal'), - # 'centos': ColorAlignment('horizontal'), +def get_fore_back(distro: str | None = None) -> tuple[int, int] | None: + """ + Get recommended foreground-background configuration for distro, or None if the distro ascii is + not suitable for fore-back configuration. + + :return: + """ + 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), }