40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
"""Footer widget for oAI TUI."""
|
|
|
|
from textual.app import ComposeResult
|
|
from textual.widgets import Static
|
|
|
|
|
|
class Footer(Static):
|
|
"""Footer displaying session metrics."""
|
|
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.tokens_in = 0
|
|
self.tokens_out = 0
|
|
self.cost = 0.0
|
|
self.messages = 0
|
|
|
|
def compose(self) -> ComposeResult:
|
|
"""Compose the footer."""
|
|
yield Static(self._format_footer(), id="footer-content")
|
|
|
|
def _format_footer(self) -> str:
|
|
"""Format the footer text."""
|
|
return (
|
|
f"[dim]Messages: {self.messages} | "
|
|
f"Tokens: {self.tokens_in + self.tokens_out:,} "
|
|
f"({self.tokens_in:,} in, {self.tokens_out:,} out) | "
|
|
f"Cost: ${self.cost:.4f}[/]"
|
|
)
|
|
|
|
def update_stats(
|
|
self, tokens_in: int, tokens_out: int, cost: float, messages: int
|
|
) -> None:
|
|
"""Update the displayed statistics."""
|
|
self.tokens_in = tokens_in
|
|
self.tokens_out = tokens_out
|
|
self.cost = cost
|
|
self.messages = messages
|
|
content = self.query_one("#footer-content", Static)
|
|
content.update(self._format_footer())
|