Files
mistral-vibe/vibe/cli/textual_ui/widgets/context_progress.py
Quentin Torroba fa15fc977b Initial commit
Co-Authored-By: Quentin Torroba <quentin.torroba@mistral.ai>
Co-Authored-By: Laure Hugo <laure.hugo@mistral.ai>
Co-Authored-By: Benjamin Trom <benjamin.trom@mistral.ai>
Co-Authored-By: Mathias Gesbert <mathias.gesbert@ext.mistral.ai>
Co-Authored-By: Michel Thomazo <michel.thomazo@mistral.ai>
Co-Authored-By: Clément Drouin <clement.drouin@mistral.ai>
Co-Authored-By: Vincent Guilloux <vincent.guilloux@mistral.ai>
Co-Authored-By: Valentin Berard <val@mistral.ai>
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2025-12-09 13:13:22 +01:00

32 lines
762 B
Python

from __future__ import annotations
from dataclasses import dataclass
from typing import Any
from textual.reactive import reactive
from textual.widgets import Static
@dataclass
class TokenState:
max_tokens: int = 0
current_tokens: int = 0
class ContextProgress(Static):
tokens = reactive(TokenState())
def __init__(self, **kwargs: Any) -> None:
super().__init__(**kwargs)
def watch_tokens(self, new_state: TokenState) -> None:
if new_state.max_tokens == 0:
self.update("")
return
percentage = min(
100, int((new_state.current_tokens / new_state.max_tokens) * 100)
)
text = f"{percentage}% of {new_state.max_tokens // 1000}k tokens"
self.update(text)