Explorar o código

[O] Track selected options

Azalea (on HyDEV-Daisy) %!s(int64=3) %!d(string=hai) anos
pai
achega
fed771d930
Modificáronse 3 ficheiros con 25 adicións e 17 borrados
  1. 2 0
      hyfetch/color_util.py
  2. 8 0
      hyfetch/constants.py
  3. 15 17
      hyfetch/main.py

+ 2 - 0
hyfetch/color_util.py

@@ -58,7 +58,9 @@ def clear_screen(title: str = ''):
     print('\033[2J\033[H', end='')
     print('\033[2J\033[H', end='')
 
 
     if title:
     if title:
+        print()
         printc(title)
         printc(title)
+        print()
 
 
 
 
 def redistribute_rgb(r: int, g: int, b: int) -> tuple[int, int, int]:
 def redistribute_rgb(r: int, g: int, b: int) -> tuple[int, int, int]:

+ 8 - 0
hyfetch/constants.py

@@ -1,3 +1,4 @@
+import os
 from pathlib import Path
 from pathlib import Path
 
 
 CONFIG_PATH = Path.home() / '.config/hyfetch.json'
 CONFIG_PATH = Path.home() / '.config/hyfetch.json'
@@ -5,3 +6,10 @@ VERSION = '1.0.7'
 
 
 # Global color mode default to 8-bit for compatibility
 # Global color mode default to 8-bit for compatibility
 COLOR_MODE = '8bit'
 COLOR_MODE = '8bit'
+
+# Obtain terminal size
+try:
+    TERM_LEN = os.get_terminal_size().columns
+except Exception:
+    TERM_LEN = 40
+

+ 15 - 17
hyfetch/main.py

@@ -13,19 +13,12 @@ from typing_extensions import Literal
 
 
 from . import constants
 from . import constants
 from .color_util import AnsiMode, printc, color, clear_screen, RGB
 from .color_util import AnsiMode, printc, color, clear_screen, RGB
-from .constants import CONFIG_PATH, VERSION
+from .constants import CONFIG_PATH, VERSION, TERM_LEN, TEST_ASCII_WIDTH
 from .neofetch_util import run_neofetch, replace_colors, get_custom_distro_ascii
 from .neofetch_util import run_neofetch, replace_colors, get_custom_distro_ascii
 from .presets import PRESETS, ColorProfile
 from .presets import PRESETS, ColorProfile
 from .serializer import json_stringify
 from .serializer import json_stringify
 
 
 
 
-# Obtain terminal size
-try:
-    term_len = os.get_terminal_size().columns
-except Exception:
-    term_len = 40
-
-
 @dataclass
 @dataclass
 class Config:
 class Config:
     preset: str
     preset: str
@@ -86,7 +79,7 @@ def create_config() -> Config:
 
 
     :return: Config object (automatically stored)
     :return: Config object (automatically stored)
     """
     """
-    title = '\nWelcome to &b&lhy&f&lfetch&r! Let\'s set up some colors first.\n'
+    title = 'Welcome to &b&lhy&f&lfetch&r! Let\'s set up some colors first.'
     clear_screen(title)
     clear_screen(title)
 
 
     ##############################
     ##############################
@@ -96,14 +89,14 @@ def create_config() -> Config:
         from .color_scale import Scale
         from .color_scale import Scale
 
 
         scale2 = Scale(['#12c2e9', '#c471ed', '#f7797d'])
         scale2 = Scale(['#12c2e9', '#c471ed', '#f7797d'])
-        _8bit = [scale2(i / term_len).to_ansi_8bit(False) for i in range(term_len)]
-        _rgb = [scale2(i / term_len).to_ansi_rgb(False) for i in range(term_len)]
+        _8bit = [scale2(i / TERM_LEN).to_ansi_8bit(False) for i in range(TERM_LEN)]
+        _rgb = [scale2(i / TERM_LEN).to_ansi_rgb(False) for i in range(TERM_LEN)]
 
 
-        printc('&f' + ''.join(c + t for c, t in zip(_8bit, '8bit Color Testing'.center(term_len))))
-        printc('&f' + ''.join(c + t for c, t in zip(_rgb, 'RGB Color Testing'.center(term_len))))
+        printc('&f' + ''.join(c + t for c, t in zip(_8bit, '8bit Color Testing'.center(TERM_LEN))))
+        printc('&f' + ''.join(c + t for c, t in zip(_rgb, 'RGB Color Testing'.center(TERM_LEN))))
 
 
         print()
         print()
-        printc(f'1. Which &acolor &bsystem &rdo you want to use?')
+        printc(f'&a1. Which &bcolor system &ado you want to use?')
         printc(f'(If you can\'t see colors under "RGB Color Testing", please choose 8bit)')
         printc(f'(If you can\'t see colors under "RGB Color Testing", please choose 8bit)')
         print()
         print()
         color_system = literal_input('Your choice?', ['8bit', 'rgb'], 'rgb')
         color_system = literal_input('Your choice?', ['8bit', 'rgb'], 'rgb')
@@ -115,12 +108,14 @@ def create_config() -> Config:
 
 
     # Override global color mode
     # Override global color mode
     constants.COLOR_MODE = color_system
     constants.COLOR_MODE = color_system
+    title += f'\n&e1. Selected color mode: &r{color_system}'
 
 
     ##############################
     ##############################
     # 2. Choose preset
     # 2. Choose preset
     clear_screen(title)
     clear_screen(title)
-    print('2. Let\'s choose a flag!\n'
-          'Available flag presets:\n')
+    printc('&a2. Let\'s choose a flag!')
+    printc('Available flag presets:')
+    print()
 
 
     # Create flags = [[lines]]
     # Create flags = [[lines]]
     flags = []
     flags = []
@@ -130,7 +125,7 @@ def create_config() -> Config:
         flags.append([name.center(spacing), flag, flag, flag])
         flags.append([name.center(spacing), flag, flag, flag])
 
 
     # Calculate flags per row
     # Calculate flags per row
-    flags_per_row = term_len // (spacing + 2)
+    flags_per_row = TERM_LEN // (spacing + 2)
     while flags:
     while flags:
         current = flags[:flags_per_row]
         current = flags[:flags_per_row]
         flags = flags[flags_per_row:]
         flags = flags[flags_per_row:]
@@ -144,12 +139,15 @@ def create_config() -> Config:
     print()
     print()
     tmp = PRESETS['rainbow'].set_light(.7).color_text('preset')
     tmp = PRESETS['rainbow'].set_light(.7).color_text('preset')
     preset = literal_input(f'Which {tmp} do you want to use?', PRESETS.keys(), 'rainbow', show_ops=False)
     preset = literal_input(f'Which {tmp} do you want to use?', PRESETS.keys(), 'rainbow', show_ops=False)
+    title += f'\n&e2. Selected flag:       &r{PRESETS[preset].color_text(preset)}'
 
 
     ##############################
     ##############################
     # 3. Select light/dark mode
     # 3. Select light/dark mode
     clear_screen(title)
     clear_screen(title)
     light_dark = literal_input(f'3. Is your terminal in &gf(#85e7e9)light mode&r or &gf(#c471ed)dark mode&r?',
     light_dark = literal_input(f'3. Is your terminal in &gf(#85e7e9)light mode&r or &gf(#c471ed)dark mode&r?',
                                ['light', 'dark'], 'dark')
                                ['light', 'dark'], 'dark')
+    is_light = light_dark == 'light'
+    title += f'\n&e3. Light/Dark:          &r{light_dark}'
 
 
     # Create config
     # Create config
     c = Config(preset, color_system, light_dark)
     c = Config(preset, color_system, light_dark)