icon_manager.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. """Icon management for consistent CLI display."""
  2. from __future__ import annotations
  3. from pathlib import Path
  4. class IconManager:
  5. """Centralized icon management system for consistent CLI display.
  6. This class provides standardized icons for file types, status indicators,
  7. and UI elements. Icons use Nerd Font glyphs for consistent display.
  8. Categories:
  9. - File types: .yaml, .j2, .json, .md, etc.
  10. - Status: success, warning, error, info, skipped
  11. - UI elements: folders, config, locks, etc.
  12. """
  13. # File Type Icons
  14. FILE_FOLDER = "\uf07b" #
  15. FILE_DEFAULT = "\uf15b" #
  16. FILE_YAML = "\uf15c" #
  17. FILE_JSON = "\ue60b" #
  18. FILE_MARKDOWN = "\uf48a" #
  19. FILE_JINJA2 = "\ue235" #
  20. FILE_DOCKER = "\uf308" #
  21. FILE_COMPOSE = "\uf308" #
  22. FILE_SHELL = "\uf489" #
  23. FILE_PYTHON = "\ue73c" #
  24. FILE_TEXT = "\uf15c" #
  25. # Status Indicators
  26. STATUS_SUCCESS = "\uf00c" # (check)
  27. STATUS_ERROR = "\uf00d" # (times/x)
  28. STATUS_WARNING = "\uf071" # (exclamation-triangle)
  29. STATUS_INFO = "\uf05a" # (info-circle)
  30. STATUS_SKIPPED = "\uf05e" # (ban/circle-slash)
  31. # UI Elements
  32. UI_CONFIG = "\ue5fc" #
  33. UI_LOCK = "\uf084" #
  34. UI_SETTINGS = "\uf013" #
  35. UI_ARROW_RIGHT = "\uf061" # (arrow-right)
  36. UI_BULLET = "\uf111" # (circle)
  37. UI_LIBRARY_GIT = "\uf418" # (git icon)
  38. UI_LIBRARY_STATIC = "\uf07c" # (folder icon)
  39. @classmethod
  40. def get_file_icon(cls, file_path: str | Path) -> str:
  41. """Get the appropriate icon for a file based on its extension or name.
  42. Args:
  43. file_path: Path to the file (can be string or Path object)
  44. Returns:
  45. Unicode icon character for the file type
  46. Examples:
  47. >>> IconManager.get_file_icon("config.yaml")
  48. '\uf15c'
  49. >>> IconManager.get_file_icon("template.j2")
  50. '\ue235'
  51. """
  52. if isinstance(file_path, str):
  53. file_path = Path(file_path)
  54. file_name = file_path.name.lower()
  55. suffix = file_path.suffix.lower()
  56. # Check for Docker Compose files
  57. compose_names = {
  58. "docker-compose.yml",
  59. "docker-compose.yaml",
  60. "compose.yml",
  61. "compose.yaml",
  62. }
  63. if file_name in compose_names or file_name.startswith("docker-compose"):
  64. return cls.FILE_DOCKER
  65. # Check by extension
  66. extension_map = {
  67. ".yaml": cls.FILE_YAML,
  68. ".yml": cls.FILE_YAML,
  69. ".json": cls.FILE_JSON,
  70. ".md": cls.FILE_MARKDOWN,
  71. ".j2": cls.FILE_JINJA2,
  72. ".sh": cls.FILE_SHELL,
  73. ".py": cls.FILE_PYTHON,
  74. ".txt": cls.FILE_TEXT,
  75. }
  76. return extension_map.get(suffix, cls.FILE_DEFAULT)
  77. @classmethod
  78. def get_status_icon(cls, status: str) -> str:
  79. """Get the appropriate icon for a status indicator.
  80. Args:
  81. status: Status type (success, error, warning, info, skipped)
  82. Returns:
  83. Unicode icon character for the status
  84. Examples:
  85. >>> IconManager.get_status_icon("success")
  86. '✓'
  87. >>> IconManager.get_status_icon("warning")
  88. '⚠'
  89. """
  90. status_map = {
  91. "success": cls.STATUS_SUCCESS,
  92. "error": cls.STATUS_ERROR,
  93. "warning": cls.STATUS_WARNING,
  94. "info": cls.STATUS_INFO,
  95. "skipped": cls.STATUS_SKIPPED,
  96. }
  97. return status_map.get(status.lower(), cls.STATUS_INFO)
  98. @classmethod
  99. def folder(cls) -> str:
  100. """Get the folder icon."""
  101. return cls.FILE_FOLDER
  102. @classmethod
  103. def config(cls) -> str:
  104. """Get the config icon."""
  105. return cls.UI_CONFIG
  106. @classmethod
  107. def lock(cls) -> str:
  108. """Get the lock icon (for sensitive variables)."""
  109. return cls.UI_LOCK
  110. @classmethod
  111. def arrow_right(cls) -> str:
  112. """Get the right arrow icon (for showing transitions/changes)."""
  113. return cls.UI_ARROW_RIGHT