pretty good

This commit is contained in:
2025-07-28 08:14:15 -04:00
parent 36a576dc2c
commit 4dd632012f
21 changed files with 2174 additions and 152 deletions

View File

@@ -8,6 +8,7 @@ from textual.containers import Container, Horizontal, Vertical, ScrollableContai
from textual.widgets import Header, Footer, Static, DataTable, Label
from textual.reactive import reactive
from textual.timer import Timer
from textual.events import MouseDown, MouseMove
from typing import TYPE_CHECKING
from rich.text import Text
from rich.console import Group
@@ -37,6 +38,8 @@ class StreamLensAppV2(App):
"""
CSS_PATH = "styles/streamlens_v2.tcss"
ENABLE_COMMAND_PALETTE = False
AUTO_FOCUS = None
BINDINGS = [
("q", "quit", "Quit"),
@@ -79,40 +82,13 @@ class StreamLensAppV2(App):
yield Header()
with Container(id="main-container"):
# Top metrics bar - compact like TipTop
# Ultra-compact metrics bar
with Horizontal(id="metrics-bar"):
yield MetricCard(
"Flows",
f"{self.total_flows}",
trend="stable",
id="flows-metric"
)
yield MetricCard(
"Packets/s",
f"{self.packets_per_sec:.1f}",
trend="up",
sparkline=True,
id="packets-metric"
)
yield MetricCard(
"Volume/s",
self._format_bytes_per_sec(self.bytes_per_sec),
trend="stable",
sparkline=True,
id="volume-metric"
)
yield MetricCard(
"Enhanced",
f"{self.enhanced_flows}",
color="success",
id="enhanced-metric"
)
yield MetricCard(
"Outliers",
f"{self.outlier_count}",
color="warning" if self.outlier_count > 0 else "normal",
id="outliers-metric"
)
yield MetricCard("Flows", f"{self.total_flows}", id="flows-metric")
yield MetricCard("Pkts/s", f"{self.packets_per_sec:.0f}", id="packets-metric")
yield MetricCard("Vol/s", self._format_bytes_per_sec(self.bytes_per_sec), id="volume-metric")
yield MetricCard("Enhanced", f"{self.enhanced_flows}", color="success", id="enhanced-metric")
yield MetricCard("Outliers", f"{self.outlier_count}", color="warning" if self.outlier_count > 0 else "normal", id="outliers-metric")
# Main content area with horizontal split
with Horizontal(id="content-area"):
@@ -132,7 +108,7 @@ class StreamLensAppV2(App):
yield Footer()
def on_mount(self) -> None:
"""Initialize the application with TipTop-style updates"""
"""Initialize the application with TipTop-style updates"""
self.update_metrics()
# Set up update intervals like TipTop
@@ -141,7 +117,20 @@ class StreamLensAppV2(App):
# Initialize sparkline history
self._initialize_history()
# Set initial focus to the flow table for immediate keyboard navigation
self.call_after_refresh(self._set_initial_focus)
def _set_initial_focus(self):
"""Set initial focus to the flow table after widgets are ready"""
try:
flow_table = self.query_one("#flow-table", EnhancedFlowTable)
data_table = flow_table.query_one("#flows-data-table", DataTable)
data_table.focus()
except Exception:
# If table isn't ready yet, try again after a short delay
self.set_timer(0.1, self._set_initial_focus)
def _initialize_history(self):
"""Initialize metrics history arrays"""
current_time = time.time()
@@ -281,4 +270,12 @@ class StreamLensAppV2(App):
def action_show_details(self) -> None:
"""Show detailed view for selected flow"""
# TODO: Implement detailed flow modal
pass
pass
def on_mouse_down(self, event: MouseDown) -> None:
"""Prevent default mouse down behavior to disable mouse interaction."""
event.prevent_default()
def on_mouse_move(self, event: MouseMove) -> None:
"""Prevent default mouse move behavior to disable mouse interaction."""
event.prevent_default()