File size: 1,290 Bytes
a7d7463
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""Animation Configuration"""

from dataclasses import dataclass
from enum import Enum


class ColorMode(Enum):
    """Color mode options"""

    AUTO = "auto"
    ALWAYS = "always"
    NEVER = "never"


@dataclass
class AnimationConfig:
    """Configuration for terminal animations"""

    speed: float = 0.05
    color_enabled: bool = True
    color_mode: ColorMode = ColorMode.AUTO
    default_frames: int = 30
    particle_count: int = 50

    SPINNER_FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]

    PROGRESS_CHARS = "█▓▒░"

    @classmethod
    def from_env(cls) -> "AnimationConfig":
        """Create config from environment variables"""
        import os

        return cls(
            speed=float(os.getenv("ANIMATION_SPEED", "0.05")),
            color_enabled=os.getenv("ANIMATION_COLOR", "true").lower() == "true",
        )

    def should_use_color(self) -> bool:
        """Check if color should be used"""
        if not self.color_enabled:
            return False

        if self.color_mode == ColorMode.ALWAYS:
            return True
        elif self.color_mode == ColorMode.NEVER:
            return False
        else:
            import sys

            return sys.stdout.isatty()


DEFAULT_CONFIG = AnimationConfig()