constants.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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.3.0'
  8. # Obtain terminal size
  9. try:
  10. TERM_LEN = os.get_terminal_size().columns
  11. except Exception:
  12. TERM_LEN = 40
  13. TEST_ASCII = r"""
  14. ### |\___/| ###
  15. ### ) ( ###
  16. ## =\ /= ##
  17. #### )===( ####
  18. ### / \ ###
  19. ### | | ###
  20. ## / {txt} \ ##
  21. ## \ / ##
  22. _/\_\_ _/_/\_
  23. |##| ( ( |##|
  24. |##| ) ) |##|
  25. |##| (_( |##|""".strip('\n')
  26. TEST_ASCII_WIDTH = max(len(line) for line in TEST_ASCII.split('\n'))
  27. DEFAULT_DARK_L = 0.
  28. @dataclass
  29. class GlobalConfig:
  30. # Global color mode default to 8-bit for compatibility
  31. color_mode: str
  32. override_distro: str | None
  33. debug: bool
  34. is_light: bool
  35. def light_dark(self) -> Literal['light', 'dark']:
  36. return 'light' if self.is_light else 'dark'
  37. def default_lightness(self, term: Literal['light', 'dark'] | None = None) -> float:
  38. if term is None:
  39. term = self.light_dark()
  40. return 0.65 if term.lower() == 'dark' else 0.4
  41. GLOBAL_CFG = GlobalConfig(color_mode='8bit', override_distro=None, debug=False, is_light=False)