spongebob-cli 0.3.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- spongebob/__init__.py +1 -0
- spongebob/__main__.py +375 -0
- spongebob/analyzer/__init__.py +9 -0
- spongebob/analyzer/__main__.py +39 -0
- spongebob/analyzer/analyzer.py +234 -0
- spongebob/bus/__init__.py +6 -0
- spongebob/bus/bus.py +38 -0
- spongebob/diagnose/__init__.py +29 -0
- spongebob/diagnose/__main__.py +111 -0
- spongebob/diagnose/adapter.py +82 -0
- spongebob/diagnose/models.py +79 -0
- spongebob/diagnose/probes.py +129 -0
- spongebob/engine/__init__.py +26 -0
- spongebob/engine/__main__.py +25 -0
- spongebob/engine/models.py +161 -0
- spongebob/engine/simulator.py +196 -0
- spongebob/export/__init__.py +25 -0
- spongebob/export/exporter.py +354 -0
- spongebob/meter/__init__.py +7 -0
- spongebob/meter/__main__.py +50 -0
- spongebob/meter/meter.py +140 -0
- spongebob/narrator/__init__.py +25 -0
- spongebob/narrator/narrator.py +352 -0
- spongebob/plugins/__init__.py +28 -0
- spongebob/plugins/loader.py +308 -0
- spongebob/plugins/models.py +47 -0
- spongebob/scenarios/__init__.py +25 -0
- spongebob/scenarios/builtin/__init__.py +1 -0
- spongebob/scenarios/builtin/control-line.toml +33 -0
- spongebob/scenarios/builtin/crowded-wifi.toml +33 -0
- spongebob/scenarios/builtin/flaky-last-mile.toml +33 -0
- spongebob/scenarios/builtin/long-haul-orbit.toml +33 -0
- spongebob/scenarios/builtin/overloaded-uplink.toml +35 -0
- spongebob/scenarios/builtin/tunnel-burst.toml +38 -0
- spongebob/scenarios/loader.py +205 -0
- spongebob/scenarios/models.py +55 -0
- spongebob/scenarios/runner.py +24 -0
- spongebob/ui/__init__.py +23 -0
- spongebob/ui/__main__.py +11 -0
- spongebob/ui/app.py +88 -0
- spongebob/ui/canvas.py +147 -0
- spongebob/ui/diagnose_screen.py +525 -0
- spongebob/ui/export_modal.py +158 -0
- spongebob/ui/menu_screen.py +159 -0
- spongebob/ui/replay.py +209 -0
- spongebob/ui/settings_screen.py +101 -0
- spongebob/ui/simulate_screen.py +566 -0
- spongebob/ui/theme.py +364 -0
- spongebob/ui/visualize_screen.py +411 -0
- spongebob_cli-0.3.2.dist-info/METADATA +78 -0
- spongebob_cli-0.3.2.dist-info/RECORD +54 -0
- spongebob_cli-0.3.2.dist-info/WHEEL +5 -0
- spongebob_cli-0.3.2.dist-info/entry_points.txt +2 -0
- spongebob_cli-0.3.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from rich.text import Text
|
|
4
|
+
from textual.app import ComposeResult
|
|
5
|
+
from textual.binding import Binding
|
|
6
|
+
from textual.containers import Center, Vertical
|
|
7
|
+
from textual.screen import Screen
|
|
8
|
+
from textual.widgets import Button, Footer, Static
|
|
9
|
+
|
|
10
|
+
from spongebob.ui import theme
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class MenuScreen(Screen[None]):
|
|
14
|
+
"""Keyboard-first main menu screen."""
|
|
15
|
+
|
|
16
|
+
BINDINGS = [
|
|
17
|
+
Binding("s", "open_simulate", "Simulate"),
|
|
18
|
+
Binding("v", "open_visualize", "Visualize"),
|
|
19
|
+
Binding("d", "open_diagnose", "Diagnose"),
|
|
20
|
+
Binding("p", "open_settings", "Plugins/Settings"),
|
|
21
|
+
Binding("n", "toggle_narrator", "Narrator On/Off"),
|
|
22
|
+
Binding("q", "quit_app", "Quit"),
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
CSS = f"""
|
|
26
|
+
MenuScreen {{
|
|
27
|
+
layout: vertical;
|
|
28
|
+
background: {theme.BG};
|
|
29
|
+
color: {theme.CREAM};
|
|
30
|
+
}}
|
|
31
|
+
#menu-center {{
|
|
32
|
+
height: 1fr;
|
|
33
|
+
align: center middle;
|
|
34
|
+
}}
|
|
35
|
+
#menu-box {{
|
|
36
|
+
width: 56;
|
|
37
|
+
height: auto;
|
|
38
|
+
padding: 0 1;
|
|
39
|
+
background: {theme.BG};
|
|
40
|
+
}}
|
|
41
|
+
#menu-banner {{
|
|
42
|
+
background: {theme.BANNER_BLUE};
|
|
43
|
+
color: {theme.CREAM};
|
|
44
|
+
border: solid {theme.SIGNAL_GREEN};
|
|
45
|
+
padding: 1 2;
|
|
46
|
+
margin-bottom: 1;
|
|
47
|
+
text-align: center;
|
|
48
|
+
}}
|
|
49
|
+
#menu-mode-box {{
|
|
50
|
+
border: solid {theme.SIGNAL_GREEN};
|
|
51
|
+
padding: 0 1;
|
|
52
|
+
background: {theme.BG};
|
|
53
|
+
height: auto;
|
|
54
|
+
}}
|
|
55
|
+
#menu-mode-label {{
|
|
56
|
+
color: {theme.SIGNAL_GREEN};
|
|
57
|
+
text-style: bold;
|
|
58
|
+
margin-bottom: 1;
|
|
59
|
+
}}
|
|
60
|
+
#menu-mode-box Button {{
|
|
61
|
+
width: 100%;
|
|
62
|
+
margin-bottom: 0;
|
|
63
|
+
content-align: left middle;
|
|
64
|
+
padding: 0 1;
|
|
65
|
+
}}
|
|
66
|
+
#too-small {{
|
|
67
|
+
width: 100%;
|
|
68
|
+
height: 1fr;
|
|
69
|
+
content-align: center middle;
|
|
70
|
+
color: {theme.WARN_AMBER};
|
|
71
|
+
text-style: bold;
|
|
72
|
+
display: none;
|
|
73
|
+
}}
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
def compose(self) -> ComposeResult:
|
|
77
|
+
yield theme.make_top_title("MAIN MENU")
|
|
78
|
+
yield theme.RedTopRule(classes="red-rule")
|
|
79
|
+
yield Static("Enlarge terminal (minimum 50x16 required).", id="too-small")
|
|
80
|
+
with Center(id="menu-center"):
|
|
81
|
+
with Vertical(id="menu-box"):
|
|
82
|
+
yield Static("", id="menu-banner")
|
|
83
|
+
with Vertical(id="menu-mode-box"):
|
|
84
|
+
yield Static("SELECT MODE", id="menu-mode-label")
|
|
85
|
+
yield Button("[S] Simulate (Delay, Jitter, Loss)", id="btn-simulate", variant="primary")
|
|
86
|
+
yield Button("[V] Visualize (Live Pipe Replay)", id="btn-visualize")
|
|
87
|
+
yield Button("[D] Diagnose (Live Target Probe)", id="btn-diagnose")
|
|
88
|
+
yield Button("[P] Plugins & Settings", id="btn-settings")
|
|
89
|
+
yield Button("[N] Settings: Narrator ON", id="btn-narrator-toggle")
|
|
90
|
+
yield Button("[Q] Quit", id="btn-quit", variant="error")
|
|
91
|
+
yield Static(theme.format_status_line("SYSTEM READY", 1.0), id="menu-status", classes="status-bar")
|
|
92
|
+
yield Footer()
|
|
93
|
+
|
|
94
|
+
def on_mount(self) -> None:
|
|
95
|
+
self._render_banner()
|
|
96
|
+
self._sync_narrator_label()
|
|
97
|
+
self._check_size()
|
|
98
|
+
|
|
99
|
+
def on_resize(self) -> None:
|
|
100
|
+
self._check_size()
|
|
101
|
+
|
|
102
|
+
def _check_size(self) -> None:
|
|
103
|
+
too_small = self.query_one("#too-small", Static)
|
|
104
|
+
center = self.query_one("#menu-center", Center)
|
|
105
|
+
if self.size.width < 50 or self.size.height < 16:
|
|
106
|
+
too_small.styles.display = "block"
|
|
107
|
+
center.styles.display = "none"
|
|
108
|
+
else:
|
|
109
|
+
too_small.styles.display = "none"
|
|
110
|
+
center.styles.display = "block"
|
|
111
|
+
|
|
112
|
+
def _render_banner(self) -> None:
|
|
113
|
+
banner = Text()
|
|
114
|
+
word_style = theme.color_style(theme.CREAM_RGB, bg_rgb=theme.BANNER_BLUE_RGB)
|
|
115
|
+
sub_style = theme.color_style(theme.TEAL_LIGHT_RGB, bg_rgb=theme.BANNER_BLUE_RGB)
|
|
116
|
+
for line in theme.WORDMARK_LINES:
|
|
117
|
+
banner.append(line + "\n", style=word_style)
|
|
118
|
+
banner.append(theme.SUBTITLE + "\n", style=sub_style)
|
|
119
|
+
banner.append(theme.render_signal_band_text(48, 3, seed=42))
|
|
120
|
+
self.query_one("#menu-banner", Static).update(banner)
|
|
121
|
+
|
|
122
|
+
def _sync_narrator_label(self) -> None:
|
|
123
|
+
enabled = getattr(self.app, "narrator_enabled", True)
|
|
124
|
+
state = "ON" if enabled else "OFF"
|
|
125
|
+
self.query_one("#btn-narrator-toggle", Button).label = f"[N] Settings: Narrator {state}"
|
|
126
|
+
|
|
127
|
+
def on_button_pressed(self, event: Button.Pressed) -> None:
|
|
128
|
+
btn_id = event.button.id
|
|
129
|
+
if btn_id == "btn-simulate":
|
|
130
|
+
self.action_open_simulate()
|
|
131
|
+
elif btn_id == "btn-visualize":
|
|
132
|
+
self.action_open_visualize()
|
|
133
|
+
elif btn_id == "btn-diagnose":
|
|
134
|
+
self.action_open_diagnose()
|
|
135
|
+
elif btn_id == "btn-settings":
|
|
136
|
+
self.action_open_settings()
|
|
137
|
+
elif btn_id == "btn-narrator-toggle":
|
|
138
|
+
self.action_toggle_narrator()
|
|
139
|
+
elif btn_id == "btn-quit":
|
|
140
|
+
self.action_quit_app()
|
|
141
|
+
|
|
142
|
+
def action_toggle_narrator(self) -> None:
|
|
143
|
+
self.app.toggle_narrator() # type: ignore[attr-defined]
|
|
144
|
+
self._sync_narrator_label()
|
|
145
|
+
|
|
146
|
+
def action_open_simulate(self) -> None:
|
|
147
|
+
self.app.open_simulate() # type: ignore[attr-defined]
|
|
148
|
+
|
|
149
|
+
def action_open_visualize(self) -> None:
|
|
150
|
+
self.app.open_visualize() # type: ignore[attr-defined]
|
|
151
|
+
|
|
152
|
+
def action_open_diagnose(self) -> None:
|
|
153
|
+
self.app.open_diagnose() # type: ignore[attr-defined]
|
|
154
|
+
|
|
155
|
+
def action_open_settings(self) -> None:
|
|
156
|
+
self.app.open_settings() # type: ignore[attr-defined]
|
|
157
|
+
|
|
158
|
+
def action_quit_app(self) -> None:
|
|
159
|
+
self.app.exit()
|
spongebob/ui/replay.py
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Sequence
|
|
5
|
+
|
|
6
|
+
from spongebob.analyzer import Finding
|
|
7
|
+
from spongebob.engine.models import DropReason, Event
|
|
8
|
+
from spongebob.meter import measure
|
|
9
|
+
|
|
10
|
+
_SEVERITY_RANK: dict[str, int] = {"critical": 0, "warn": 1, "info": 2}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass(frozen=True)
|
|
14
|
+
class ParticleState:
|
|
15
|
+
"""Visual state of an in-flight packet at virtual time t_ms."""
|
|
16
|
+
|
|
17
|
+
seq: int
|
|
18
|
+
x_norm: float
|
|
19
|
+
hop_index: int
|
|
20
|
+
jitter_offset: float
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass(frozen=True)
|
|
24
|
+
class DropEffect:
|
|
25
|
+
"""Visual state of a recently dropped packet at virtual time t_ms."""
|
|
26
|
+
|
|
27
|
+
seq: int
|
|
28
|
+
hop_index: int
|
|
29
|
+
reason: DropReason | None
|
|
30
|
+
age_ms: float
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@dataclass(frozen=True)
|
|
34
|
+
class PulseTarget:
|
|
35
|
+
"""Target hop and finding for the diagnostic scan pulse."""
|
|
36
|
+
|
|
37
|
+
hop_name: str | None
|
|
38
|
+
hop_index: int | None
|
|
39
|
+
finding: Finding | None
|
|
40
|
+
all_clear: bool
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@dataclass(frozen=True)
|
|
44
|
+
class ReplayState:
|
|
45
|
+
"""Pure snapshot of the visualizer state at virtual time t_ms."""
|
|
46
|
+
|
|
47
|
+
time_ms: float
|
|
48
|
+
max_time_ms: float
|
|
49
|
+
particles: tuple[ParticleState, ...]
|
|
50
|
+
drops: tuple[DropEffect, ...]
|
|
51
|
+
queue_depths: dict[str, int]
|
|
52
|
+
sent: int
|
|
53
|
+
delivered: int
|
|
54
|
+
lost: int
|
|
55
|
+
loss_pct: float
|
|
56
|
+
latency_avg_ms: float | None
|
|
57
|
+
jitter_ms: float | None
|
|
58
|
+
reordered: int
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def select_pulse_target(
|
|
62
|
+
findings: Sequence[Finding], hop_names: Sequence[str]
|
|
63
|
+
) -> PulseTarget:
|
|
64
|
+
"""Pick the highest-severity finding's hop, or return all-clear when none."""
|
|
65
|
+
if not findings:
|
|
66
|
+
return PulseTarget(hop_name=None, hop_index=None, finding=None, all_clear=True)
|
|
67
|
+
|
|
68
|
+
ordered = sorted(findings, key=lambda f: _SEVERITY_RANK.get(f.severity, 99))
|
|
69
|
+
top = ordered[0]
|
|
70
|
+
if top.hop is not None and top.hop in hop_names:
|
|
71
|
+
return PulseTarget(
|
|
72
|
+
hop_name=top.hop,
|
|
73
|
+
hop_index=list(hop_names).index(top.hop),
|
|
74
|
+
finding=top,
|
|
75
|
+
all_clear=False,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
# Path-level finding: stall at the end of the pipe if hops exist
|
|
79
|
+
fallback_idx = len(hop_names) - 1 if hop_names else None
|
|
80
|
+
return PulseTarget(
|
|
81
|
+
hop_name=top.hop,
|
|
82
|
+
hop_index=fallback_idx,
|
|
83
|
+
finding=top,
|
|
84
|
+
all_clear=False,
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def compute_replay_state(
|
|
89
|
+
events: Sequence[Event],
|
|
90
|
+
hop_names: Sequence[str],
|
|
91
|
+
t_ms: float,
|
|
92
|
+
drop_ttl_ms: float = 220.0,
|
|
93
|
+
) -> ReplayState:
|
|
94
|
+
"""Compute pure replay state at virtual time t_ms from a list of engine events."""
|
|
95
|
+
if not events:
|
|
96
|
+
return ReplayState(
|
|
97
|
+
time_ms=t_ms,
|
|
98
|
+
max_time_ms=0.0,
|
|
99
|
+
particles=(),
|
|
100
|
+
drops=(),
|
|
101
|
+
queue_depths={name: 0 for name in hop_names},
|
|
102
|
+
sent=0,
|
|
103
|
+
delivered=0,
|
|
104
|
+
lost=0,
|
|
105
|
+
loss_pct=0.0,
|
|
106
|
+
latency_avg_ms=None,
|
|
107
|
+
jitter_ms=None,
|
|
108
|
+
reordered=0,
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
max_time_ms = max(e.time_ms for e in events)
|
|
112
|
+
num_hops = max(1, len(hop_names))
|
|
113
|
+
hop_to_idx = {name: i for i, name in enumerate(hop_names)}
|
|
114
|
+
|
|
115
|
+
# Group events per packet sequence number
|
|
116
|
+
per_seq: dict[int, list[Event]] = {}
|
|
117
|
+
for event in events:
|
|
118
|
+
per_seq.setdefault(event.seq, []).append(event)
|
|
119
|
+
|
|
120
|
+
particles: list[ParticleState] = []
|
|
121
|
+
drops: list[DropEffect] = []
|
|
122
|
+
queue_depths: dict[str, int] = {name: 0 for name in hop_names}
|
|
123
|
+
|
|
124
|
+
for seq, seq_events in per_seq.items():
|
|
125
|
+
seq_events.sort(key=lambda e: e.time_ms)
|
|
126
|
+
send_ev = next((e for e in seq_events if e.type == "packet_sent"), None)
|
|
127
|
+
if send_ev is None or t_ms < send_ev.time_ms:
|
|
128
|
+
continue
|
|
129
|
+
|
|
130
|
+
# Build hop traversal intervals: (hop_idx, start_t, end_t, event)
|
|
131
|
+
last_t = send_ev.time_ms
|
|
132
|
+
dropped_ev: Event | None = None
|
|
133
|
+
delivered_ev: Event | None = None
|
|
134
|
+
active_particle: ParticleState | None = None
|
|
135
|
+
|
|
136
|
+
for ev in seq_events:
|
|
137
|
+
if ev.type == "packet_sent":
|
|
138
|
+
continue
|
|
139
|
+
if ev.type == "packet_dropped":
|
|
140
|
+
if ev.time_ms <= t_ms:
|
|
141
|
+
dropped_ev = ev
|
|
142
|
+
break
|
|
143
|
+
if ev.type in ("packet_delayed", "packet_delivered"):
|
|
144
|
+
h_idx = hop_to_idx.get(ev.hop or "", 0)
|
|
145
|
+
seg_start_t = last_t
|
|
146
|
+
seg_end_t = ev.time_ms
|
|
147
|
+
if seg_start_t <= t_ms < seg_end_t and seg_end_t > seg_start_t:
|
|
148
|
+
frac = (t_ms - seg_start_t) / (seg_end_t - seg_start_t)
|
|
149
|
+
x_norm = (h_idx + frac) / num_hops
|
|
150
|
+
wobble = ((seq % 5) - 2) * 0.15
|
|
151
|
+
active_particle = ParticleState(
|
|
152
|
+
seq=seq,
|
|
153
|
+
x_norm=max(0.0, min(1.0, x_norm)),
|
|
154
|
+
hop_index=h_idx,
|
|
155
|
+
jitter_offset=wobble,
|
|
156
|
+
)
|
|
157
|
+
if ev.hop in queue_depths and ev.queue_depth is not None:
|
|
158
|
+
queue_depths[ev.hop] = max(queue_depths[ev.hop], ev.queue_depth)
|
|
159
|
+
break
|
|
160
|
+
last_t = seg_end_t
|
|
161
|
+
if ev.type == "packet_delivered" and ev.time_ms <= t_ms:
|
|
162
|
+
delivered_ev = ev
|
|
163
|
+
if ev.hop in queue_depths and ev.queue_depth is not None:
|
|
164
|
+
queue_depths[ev.hop] = ev.queue_depth
|
|
165
|
+
|
|
166
|
+
if dropped_ev is not None:
|
|
167
|
+
age = t_ms - dropped_ev.time_ms
|
|
168
|
+
if 0.0 <= age <= drop_ttl_ms:
|
|
169
|
+
h_idx = hop_to_idx.get(dropped_ev.hop or "", 0)
|
|
170
|
+
drops.append(
|
|
171
|
+
DropEffect(
|
|
172
|
+
seq=seq,
|
|
173
|
+
hop_index=h_idx,
|
|
174
|
+
reason=dropped_ev.reason,
|
|
175
|
+
age_ms=age,
|
|
176
|
+
)
|
|
177
|
+
)
|
|
178
|
+
elif active_particle is not None:
|
|
179
|
+
particles.append(active_particle)
|
|
180
|
+
elif delivered_ev is not None and t_ms - delivered_ev.time_ms <= 40.0:
|
|
181
|
+
# Brief arrival flash at the end of the pipe
|
|
182
|
+
particles.append(
|
|
183
|
+
ParticleState(
|
|
184
|
+
seq=seq,
|
|
185
|
+
x_norm=1.0,
|
|
186
|
+
hop_index=num_hops - 1,
|
|
187
|
+
jitter_offset=0.0,
|
|
188
|
+
)
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
events_up_to_t = [e for e in events if e.time_ms <= t_ms]
|
|
192
|
+
live_metrics = measure(events_up_to_t)
|
|
193
|
+
|
|
194
|
+
return ReplayState(
|
|
195
|
+
time_ms=t_ms,
|
|
196
|
+
max_time_ms=max_time_ms,
|
|
197
|
+
particles=tuple(particles),
|
|
198
|
+
drops=tuple(drops),
|
|
199
|
+
queue_depths=queue_depths,
|
|
200
|
+
sent=live_metrics.sent,
|
|
201
|
+
delivered=live_metrics.delivered,
|
|
202
|
+
lost=live_metrics.lost,
|
|
203
|
+
loss_pct=live_metrics.loss_pct,
|
|
204
|
+
latency_avg_ms=(
|
|
205
|
+
live_metrics.latency_ms.avg if live_metrics.latency_ms is not None else None
|
|
206
|
+
),
|
|
207
|
+
jitter_ms=live_metrics.jitter_ms,
|
|
208
|
+
reordered=live_metrics.reordered,
|
|
209
|
+
)
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from textual.app import ComposeResult
|
|
4
|
+
from textual.binding import Binding
|
|
5
|
+
from textual.containers import Horizontal, Vertical
|
|
6
|
+
from textual.screen import Screen
|
|
7
|
+
from textual.widgets import Button, Footer, Input, Label, Static
|
|
8
|
+
|
|
9
|
+
from spongebob.ui import theme
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class SettingsScreen(Screen[None]):
|
|
13
|
+
"""Session settings and explicit data-only plugin folder loader."""
|
|
14
|
+
|
|
15
|
+
BINDINGS = [
|
|
16
|
+
Binding("escape", "go_back", "Back"),
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
CSS = f"""
|
|
20
|
+
SettingsScreen {{
|
|
21
|
+
layout: vertical;
|
|
22
|
+
background: {theme.BG};
|
|
23
|
+
color: {theme.CREAM};
|
|
24
|
+
}}
|
|
25
|
+
#settings-body {{
|
|
26
|
+
height: 1fr;
|
|
27
|
+
padding: 1;
|
|
28
|
+
}}
|
|
29
|
+
#plugin-box {{
|
|
30
|
+
border: solid {theme.SIGNAL_GREEN};
|
|
31
|
+
padding: 1;
|
|
32
|
+
height: auto;
|
|
33
|
+
margin-bottom: 1;
|
|
34
|
+
}}
|
|
35
|
+
.section-title {{
|
|
36
|
+
text-style: bold;
|
|
37
|
+
color: {theme.SIGNAL_GREEN};
|
|
38
|
+
margin-bottom: 1;
|
|
39
|
+
}}
|
|
40
|
+
#plugin-row {{
|
|
41
|
+
height: auto;
|
|
42
|
+
margin-bottom: 1;
|
|
43
|
+
}}
|
|
44
|
+
#plugin-dir-input {{
|
|
45
|
+
width: 1fr;
|
|
46
|
+
margin-right: 1;
|
|
47
|
+
}}
|
|
48
|
+
#plugin-status {{
|
|
49
|
+
color: {theme.CREAM};
|
|
50
|
+
}}
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
def compose(self) -> ComposeResult:
|
|
54
|
+
yield theme.make_top_title("SETTINGS & PLUGINS")
|
|
55
|
+
yield theme.RedTopRule(classes="red-rule")
|
|
56
|
+
yield Static("SETTINGS — EXPLICIT PLUGIN FOLDER (DATA-ONLY)", classes="screen-banner")
|
|
57
|
+
with Vertical(id="settings-body"):
|
|
58
|
+
with Vertical(id="plugin-box"):
|
|
59
|
+
yield Static("PLUGIN FOLDER", classes="section-title")
|
|
60
|
+
yield Label("Type a folder path containing plugin.toml (or subfolders):")
|
|
61
|
+
with Horizontal(id="plugin-row"):
|
|
62
|
+
yield Input("", placeholder="e.g. ./my-plugins", id="plugin-dir-input")
|
|
63
|
+
yield Button("Load Plugins", id="btn-load-plugins", variant="primary")
|
|
64
|
+
yield Static("No plugins loaded.", id="plugin-status")
|
|
65
|
+
yield Static(theme.format_status_line("SETTINGS READY", 1.0), classes="status-bar")
|
|
66
|
+
yield Footer()
|
|
67
|
+
|
|
68
|
+
def on_mount(self) -> None:
|
|
69
|
+
self._render_registry()
|
|
70
|
+
|
|
71
|
+
def on_button_pressed(self, event: Button.Pressed) -> None:
|
|
72
|
+
if event.button.id == "btn-load-plugins":
|
|
73
|
+
path = self.query_one("#plugin-dir-input", Input).value.strip()
|
|
74
|
+
if not path:
|
|
75
|
+
self.query_one("#plugin-status", Static).update("Enter a plugin folder path.")
|
|
76
|
+
return
|
|
77
|
+
self.app.load_plugins_folder(path) # type: ignore[attr-defined]
|
|
78
|
+
self._render_registry()
|
|
79
|
+
|
|
80
|
+
def _render_registry(self) -> None:
|
|
81
|
+
reg = getattr(self.app, "plugin_registry", None)
|
|
82
|
+
status = self.query_one("#plugin-status", Static)
|
|
83
|
+
if reg is None or (not reg.plugins and not reg.errors):
|
|
84
|
+
status.update("No plugins loaded.")
|
|
85
|
+
return
|
|
86
|
+
lines: list[str] = []
|
|
87
|
+
for p in reg.plugins:
|
|
88
|
+
m = p.manifest
|
|
89
|
+
if m.kind == "scenarios":
|
|
90
|
+
cnt = f"{len(p.scenarios)} scenarios"
|
|
91
|
+
elif m.kind == "jokes":
|
|
92
|
+
cnt = f"{sum(len(v) for v in p.finding_jokes.values()) + sum(len(v) for v in p.drop_jokes.values())} jokes"
|
|
93
|
+
else:
|
|
94
|
+
cnt = f"{len(p.theme_colors)} colors"
|
|
95
|
+
lines.append(f"Loaded {m.name} ({m.version}) [{m.kind}]: {cnt}")
|
|
96
|
+
for pname, err in reg.errors:
|
|
97
|
+
lines.append(f"Skipped {pname}: {err}")
|
|
98
|
+
status.update("\n".join(lines))
|
|
99
|
+
|
|
100
|
+
def action_go_back(self) -> None:
|
|
101
|
+
self.app.pop_screen()
|