constants.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from __future__ import annotations
  2. import os
  3. from dataclasses import dataclass
  4. from pathlib import Path
  5. from typing_extensions import Literal
  6. CONFIG_PATH = Path.home() / '.config/hyfetch.json'
  7. VERSION = '1.4.0'
  8. # Obtain terminal size
  9. try:
  10. TERM_LEN = os.get_terminal_size().columns
  11. TERM_LINES = os.get_terminal_size().lines
  12. except Exception:
  13. TERM_LEN = 40
  14. TERM_LINES = 10
  15. TEST_ASCII = r"""
  16. ### |\___/| ###
  17. ### ) ( ###
  18. ## =\ /= ##
  19. #### )===( ####
  20. ### / \ ###
  21. ### | | ###
  22. ## / {txt} \ ##
  23. ## \ / ##
  24. _/\_\_ _/_/\_
  25. |##| ( ( |##|
  26. |##| ) ) |##|
  27. |##| (_( |##|""".strip('\n')
  28. TEST_ASCII_WIDTH = max(len(line) for line in TEST_ASCII.split('\n'))
  29. DEFAULT_DARK_L = 0.
  30. @dataclass
  31. class GlobalConfig:
  32. # Global color mode default to 8-bit for compatibility
  33. color_mode: str
  34. override_distro: str | None
  35. debug: bool
  36. is_light: bool
  37. def light_dark(self) -> Literal['light', 'dark']:
  38. return 'light' if self.is_light else 'dark'
  39. def default_lightness(self, term: Literal['light', 'dark'] | None = None) -> float:
  40. if term is None:
  41. term = self.light_dark()
  42. return 0.65 if term.lower() == 'dark' else 0.4
  43. GLOBAL_CFG = GlobalConfig(color_mode='8bit', override_distro=None, debug=False, is_light=False)