Files
rag-manager/ingest_pipeline/cli/tui/widgets/indicators.py
2025-09-21 01:38:47 +00:00

94 lines
3.2 KiB
Python

"""Status indicators and progress bars with enhanced visual feedback."""
from typing import Any
from textual.app import ComposeResult
from textual.widgets import ProgressBar, Static
from typing_extensions import override
class StatusIndicator(Static):
"""Modern status indicator with color coding and animations."""
status: str
def __init__(self, status: str, **kwargs: Any) -> None:
super().__init__(**kwargs)
self.status = status
self.update_status(status)
def update_status(self, status: str) -> None:
"""Update the status display with enhanced visual feedback."""
self.status = status
# Remove previous status classes
self.remove_class("status-active", "status-error", "status-warning", "pulse", "glow")
status_lower = status.lower()
if (
status_lower in {"active", "online", "connected", "✓ active"}
or status_lower.endswith("active")
or "" in status_lower
and "active" in status_lower
):
self.add_class("status-active")
self.add_class("glow")
self.update(f"🟢 {status}")
elif status_lower in {"error", "failed", "offline", "disconnected"}:
self.add_class("status-error")
self.add_class("pulse")
self.update(f"🔴 {status}")
elif status_lower in {"warning", "pending", "in_progress"}:
self.add_class("status-warning")
self.add_class("pulse")
self.update(f"🟡 {status}")
elif status_lower in {"loading", "connecting"}:
self.add_class("shimmer")
self.update(f"🔄 {status}")
else:
self.update(f"{status}")
class EnhancedProgressBar(Static):
"""Enhanced progress bar with better visual feedback."""
total: int
progress: int
status_text: str
def __init__(self, total: int = 100, **kwargs: Any) -> None:
super().__init__(**kwargs)
self.total = total
self.progress = 0
self.status_text = "Ready"
@override
def compose(self) -> ComposeResult:
yield Static("", id="progress_status", classes="progress-label")
yield ProgressBar(total=self.total, id="progress_bar", show_eta=True, classes="shimmer")
def update_progress(self, progress: int, status: str = "") -> None:
"""Update progress with enhanced feedback."""
self.progress = progress
if status:
self.status_text = status
# Update the progress bar
progress_bar = self.query_one("#progress_bar", ProgressBar)
progress_bar.update(progress=progress)
# Update status text with icons
status_display = self.query_one("#progress_status", Static)
if progress >= 100:
status_display.update(f"{self.status_text}")
progress_bar.add_class("glow")
elif progress >= 75:
status_display.update(f"🔥 {self.status_text}")
elif progress >= 50:
status_display.update(f"{self.status_text}")
elif progress >= 25:
status_display.update(f"🔄 {self.status_text}")
else:
status_display.update(f"🚀 {self.status_text}")