diff --git a/hyfetch/color_util.py b/hyfetch/color_util.py index c018db4b..97ca043f 100644 --- a/hyfetch/color_util.py +++ b/hyfetch/color_util.py @@ -4,6 +4,8 @@ import colorsys from typing import NamedTuple from typing_extensions import Literal +from hyfetch.constants import COLOR_MODE + AnsiMode = Literal['default', 'ansi', '8bit', 'rgb'] @@ -36,7 +38,7 @@ def color(msg: str) -> str: code = code.replace(',', ' ').replace(';', ' ').replace(' ', ' ') rgb = tuple(int(c) for c in code.split(' ')) - msg = msg[:i] + RGB(*rgb).to_ansi_rgb(foreground=fore) + msg[end + 1:] + msg = msg[:i] + RGB(*rgb).to_ansi(mode=COLOR_MODE, foreground=fore) + msg[end + 1:] return msg @@ -151,7 +153,7 @@ class RGB(NamedTuple): """ raise NotImplementedError() - def to_ansi(self, mode: AnsiMode, foreground: bool = True): + def to_ansi(self, mode: AnsiMode = COLOR_MODE, foreground: bool = True): if mode == 'rgb': return self.to_ansi_rgb(foreground) if mode == '8bit': diff --git a/hyfetch/constants.py b/hyfetch/constants.py new file mode 100644 index 00000000..b77a3fd7 --- /dev/null +++ b/hyfetch/constants.py @@ -0,0 +1,7 @@ +from pathlib import Path + +CONFIG_PATH = Path.home() / '.config/hyfetch.json' +VERSION = '1.0.7' + +# Global color mode default to 8-bit for compatibility +COLOR_MODE = '8bit' diff --git a/hyfetch/main.py b/hyfetch/main.py index aed9a3ff..ef741234 100755 --- a/hyfetch/main.py +++ b/hyfetch/main.py @@ -9,14 +9,13 @@ from dataclasses import dataclass from pathlib import Path from typing import Iterable +from . import constants from .color_util import AnsiMode, printc, color, clear_screen, RGB +from .constants import CONFIG_PATH, VERSION from .neofetch_util import run_neofetch, replace_colors, get_custom_distro_ascii from .presets import PRESETS, ColorProfile from .serializer import json_stringify -CONFIG_PATH = Path.home() / '.config/hyfetch.json' -VERSION = '1.0.7' - # Obtain terminal size try: @@ -50,20 +49,25 @@ def check_config() -> Config: return create_config() -def literal_input(prompt: str, options: Iterable[str], default: str) -> str: +def literal_input(prompt: str, options: Iterable[str], default: str, show_ops: bool = True) -> str: """ Ask the user to provide an input among a list of options :param prompt: Input prompt :param options: Options :param default: Default option + :param show_ops: Show options :return: Selection """ options = list(options) lows = [o.lower() for o in options] - op_text = '|'.join([f'&l&n{o}&r' if o == default else o for o in options]) - printc(f'{prompt} ({op_text})') + if show_ops: + op_text = '|'.join([f'&l&n{o}&r' if o == default else o for o in options]) + printc(f'{prompt} ({op_text})') + else: + printc(f'{prompt} (default: {default})') + selection = input('> ') or default while not selection.lower() in lows: print(f'Invalid selection! {selection} is not one of {"|".join(options)}') @@ -105,8 +109,9 @@ def create_config() -> Config: # Numpy not found, skip gradient test, use fallback color_system = literal_input('Which &acolor &bsystem &rdo you want to use?', ['8bit', 'rgb'], 'rgb') - color_system = AnsiMode(color_system) + # Override global color mode + constants.COLOR_MODE = color_system ############################## # 3. Choose preset @@ -180,6 +185,10 @@ def run(): if args.mode: config.mode = args.mode + # Override global color mode + constants.COLOR_MODE = config.mode + + # Get preset preset = PRESETS.get(config.preset) # Lighten @@ -193,7 +202,7 @@ def run(): asc = get_custom_distro_ascii(args.test_distro) print(asc) print(replace_colors(asc, preset, config.mode)[0]) - exit(0) + return # Run run_neofetch(preset, config.mode)