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
spongebob/ui/theme.py
ADDED
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import random
|
|
4
|
+
|
|
5
|
+
from rich.style import Style
|
|
6
|
+
from rich.text import Text
|
|
7
|
+
from textual.widgets import Static
|
|
8
|
+
|
|
9
|
+
from spongebob import __version__
|
|
10
|
+
from spongebob.ui.canvas import detect_truecolor, rgb_to_ansi256
|
|
11
|
+
|
|
12
|
+
# Exact palette sampled from reference image 1
|
|
13
|
+
BG = "#000501"
|
|
14
|
+
BG_RGB = (0, 5, 1)
|
|
15
|
+
|
|
16
|
+
BANNER_BLUE = "#004fc5"
|
|
17
|
+
BANNER_BLUE_RGB = (0, 79, 197)
|
|
18
|
+
|
|
19
|
+
CREAM = "#cbf7bc"
|
|
20
|
+
CREAM_RGB = (203, 247, 188)
|
|
21
|
+
|
|
22
|
+
SIGNAL_GREEN = "#14e96d"
|
|
23
|
+
SIGNAL_GREEN_RGB = (20, 233, 109)
|
|
24
|
+
|
|
25
|
+
TEAL_LIGHT = "#d7fcff"
|
|
26
|
+
TEAL_LIGHT_RGB = (215, 252, 255)
|
|
27
|
+
|
|
28
|
+
TEAL_MID = "#208e9d"
|
|
29
|
+
TEAL_MID_RGB = (32, 142, 157)
|
|
30
|
+
|
|
31
|
+
TEAL_DARK = "#104c42"
|
|
32
|
+
TEAL_DARK_RGB = (16, 76, 66)
|
|
33
|
+
|
|
34
|
+
RED_RULE = "#d5574b"
|
|
35
|
+
RED_RULE_RGB = (213, 87, 75)
|
|
36
|
+
|
|
37
|
+
WARN_AMBER = "#facc15"
|
|
38
|
+
WARN_AMBER_RGB = (250, 204, 21)
|
|
39
|
+
|
|
40
|
+
CRIT_RED = "#f87171"
|
|
41
|
+
CRIT_RED_RGB = (248, 113, 113)
|
|
42
|
+
|
|
43
|
+
DIM_TEXT = "#649e8a"
|
|
44
|
+
DIM_TEXT_RGB = (100, 158, 138)
|
|
45
|
+
|
|
46
|
+
DEFAULT_PALETTE: dict[str, str] = {
|
|
47
|
+
"bg": BG,
|
|
48
|
+
"banner_blue": BANNER_BLUE,
|
|
49
|
+
"cream": CREAM,
|
|
50
|
+
"signal_green": SIGNAL_GREEN,
|
|
51
|
+
"teal_light": TEAL_LIGHT,
|
|
52
|
+
"teal_mid": TEAL_MID,
|
|
53
|
+
"teal_dark": TEAL_DARK,
|
|
54
|
+
"red_rule": RED_RULE,
|
|
55
|
+
"warn_amber": WARN_AMBER,
|
|
56
|
+
"crit_red": CRIT_RED,
|
|
57
|
+
"dim_text": DIM_TEXT,
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
THEME_ROLES: frozenset[str] = frozenset(DEFAULT_PALETTE.keys())
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def build_base_css(palette: dict[str, str] | None = None) -> str:
|
|
64
|
+
"""Build base Textual CSS from a palette dictionary."""
|
|
65
|
+
p = {**DEFAULT_PALETTE, **(palette or {})}
|
|
66
|
+
return f"""
|
|
67
|
+
Screen {{
|
|
68
|
+
background: {p['bg']};
|
|
69
|
+
color: {p['cream']};
|
|
70
|
+
}}
|
|
71
|
+
.top-title {{
|
|
72
|
+
height: 1;
|
|
73
|
+
padding: 0 1;
|
|
74
|
+
background: {p['bg']};
|
|
75
|
+
color: {p['cream']};
|
|
76
|
+
text-style: bold;
|
|
77
|
+
}}
|
|
78
|
+
.red-rule {{
|
|
79
|
+
height: 1;
|
|
80
|
+
background: {p['bg']};
|
|
81
|
+
color: {p['red_rule']};
|
|
82
|
+
}}
|
|
83
|
+
.screen-banner {{
|
|
84
|
+
height: auto;
|
|
85
|
+
padding: 0 1;
|
|
86
|
+
background: {p['banner_blue']};
|
|
87
|
+
color: {p['cream']};
|
|
88
|
+
text-style: bold;
|
|
89
|
+
border: solid {p['signal_green']};
|
|
90
|
+
}}
|
|
91
|
+
.outlined-box {{
|
|
92
|
+
border: solid {p['signal_green']};
|
|
93
|
+
background: {p['bg']};
|
|
94
|
+
color: {p['cream']};
|
|
95
|
+
padding: 0 1;
|
|
96
|
+
}}
|
|
97
|
+
.box-title {{
|
|
98
|
+
text-style: bold;
|
|
99
|
+
color: {p['signal_green']};
|
|
100
|
+
}}
|
|
101
|
+
.status-bar {{
|
|
102
|
+
height: 1;
|
|
103
|
+
padding: 0 1;
|
|
104
|
+
background: {p['bg']};
|
|
105
|
+
color: {p['signal_green']};
|
|
106
|
+
border-top: solid {p['signal_green']};
|
|
107
|
+
}}
|
|
108
|
+
Button {{
|
|
109
|
+
background: {p['bg']};
|
|
110
|
+
color: {p['cream']};
|
|
111
|
+
border: solid {p['signal_green']};
|
|
112
|
+
min-height: 1;
|
|
113
|
+
height: auto;
|
|
114
|
+
}}
|
|
115
|
+
Button:focus {{
|
|
116
|
+
background: {p['banner_blue']};
|
|
117
|
+
color: {p['cream']};
|
|
118
|
+
text-style: bold;
|
|
119
|
+
}}
|
|
120
|
+
Button.-primary {{
|
|
121
|
+
background: {p['bg']};
|
|
122
|
+
color: {p['signal_green']};
|
|
123
|
+
border: solid {p['signal_green']};
|
|
124
|
+
}}
|
|
125
|
+
Button.-primary:focus {{
|
|
126
|
+
background: {p['banner_blue']};
|
|
127
|
+
color: {p['cream']};
|
|
128
|
+
text-style: bold;
|
|
129
|
+
}}
|
|
130
|
+
Button.-error {{
|
|
131
|
+
background: {p['bg']};
|
|
132
|
+
color: {p['crit_red']};
|
|
133
|
+
border: solid {p['red_rule']};
|
|
134
|
+
}}
|
|
135
|
+
Button.-error:focus {{
|
|
136
|
+
background: {p['banner_blue']};
|
|
137
|
+
color: {p['cream']};
|
|
138
|
+
text-style: bold;
|
|
139
|
+
}}
|
|
140
|
+
Input {{
|
|
141
|
+
background: {p['bg']};
|
|
142
|
+
color: {p['cream']};
|
|
143
|
+
border: solid {p['signal_green']};
|
|
144
|
+
}}
|
|
145
|
+
Input:focus {{
|
|
146
|
+
border: solid {p['teal_light']};
|
|
147
|
+
}}
|
|
148
|
+
Checkbox {{
|
|
149
|
+
background: {p['bg']};
|
|
150
|
+
color: {p['cream']};
|
|
151
|
+
border: none;
|
|
152
|
+
}}
|
|
153
|
+
Select {{
|
|
154
|
+
background: {p['bg']};
|
|
155
|
+
color: {p['cream']};
|
|
156
|
+
}}
|
|
157
|
+
Footer {{
|
|
158
|
+
background: {p['bg']};
|
|
159
|
+
color: {p['dim_text']};
|
|
160
|
+
}}
|
|
161
|
+
"""
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
SUBTITLE = "NETWORK IMPAIRMENT SIMULATOR AND VISUALIZER"
|
|
165
|
+
|
|
166
|
+
WORDMARK_LINES: tuple[str, ...] = (
|
|
167
|
+
"▄▀▀▀ █▀▀▄ ▄▀▀▄ █▄ █ ▄▀▀▀ █▀▀▀ █▀▀▄ ▄▀▀▄ █▀▀▄",
|
|
168
|
+
" ▀▀▄ █▄▄▀ █ █ █ ▀█ █ ▀█ █▀▀ █▀▀▄ █ █ █▀▀▄",
|
|
169
|
+
"▀▀▀ █ ▀▄▄▀ █ █ ▀▄▄▀ █▄▄▄ █▄▄▀ ▀▄▄▀ █▄▄▀",
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
BASE_THEME_CSS = f"""
|
|
173
|
+
Screen {{
|
|
174
|
+
background: {BG};
|
|
175
|
+
color: {CREAM};
|
|
176
|
+
}}
|
|
177
|
+
.top-title {{
|
|
178
|
+
height: 1;
|
|
179
|
+
padding: 0 1;
|
|
180
|
+
background: {BG};
|
|
181
|
+
color: {CREAM};
|
|
182
|
+
text-style: bold;
|
|
183
|
+
}}
|
|
184
|
+
.red-rule {{
|
|
185
|
+
height: 1;
|
|
186
|
+
background: {BG};
|
|
187
|
+
color: {RED_RULE};
|
|
188
|
+
}}
|
|
189
|
+
.screen-banner {{
|
|
190
|
+
height: auto;
|
|
191
|
+
padding: 0 1;
|
|
192
|
+
background: {BANNER_BLUE};
|
|
193
|
+
color: {CREAM};
|
|
194
|
+
text-style: bold;
|
|
195
|
+
border: solid {SIGNAL_GREEN};
|
|
196
|
+
}}
|
|
197
|
+
.outlined-box {{
|
|
198
|
+
border: solid {SIGNAL_GREEN};
|
|
199
|
+
background: {BG};
|
|
200
|
+
color: {CREAM};
|
|
201
|
+
padding: 0 1;
|
|
202
|
+
}}
|
|
203
|
+
.box-title {{
|
|
204
|
+
text-style: bold;
|
|
205
|
+
color: {SIGNAL_GREEN};
|
|
206
|
+
}}
|
|
207
|
+
.status-bar {{
|
|
208
|
+
height: 1;
|
|
209
|
+
padding: 0 1;
|
|
210
|
+
background: {BG};
|
|
211
|
+
color: {SIGNAL_GREEN};
|
|
212
|
+
border-top: solid {SIGNAL_GREEN};
|
|
213
|
+
}}
|
|
214
|
+
Button {{
|
|
215
|
+
background: {BG};
|
|
216
|
+
color: {CREAM};
|
|
217
|
+
border: solid {SIGNAL_GREEN};
|
|
218
|
+
min-height: 1;
|
|
219
|
+
height: auto;
|
|
220
|
+
}}
|
|
221
|
+
Button:focus {{
|
|
222
|
+
background: {BANNER_BLUE};
|
|
223
|
+
color: {CREAM};
|
|
224
|
+
text-style: bold;
|
|
225
|
+
}}
|
|
226
|
+
Button.-primary {{
|
|
227
|
+
background: {BG};
|
|
228
|
+
color: {SIGNAL_GREEN};
|
|
229
|
+
border: solid {SIGNAL_GREEN};
|
|
230
|
+
}}
|
|
231
|
+
Button.-primary:focus {{
|
|
232
|
+
background: {BANNER_BLUE};
|
|
233
|
+
color: {CREAM};
|
|
234
|
+
text-style: bold;
|
|
235
|
+
}}
|
|
236
|
+
Button.-error {{
|
|
237
|
+
background: {BG};
|
|
238
|
+
color: {CRIT_RED};
|
|
239
|
+
border: solid {RED_RULE};
|
|
240
|
+
}}
|
|
241
|
+
Button.-error:focus {{
|
|
242
|
+
background: {BANNER_BLUE};
|
|
243
|
+
color: {CREAM};
|
|
244
|
+
text-style: bold;
|
|
245
|
+
}}
|
|
246
|
+
Input {{
|
|
247
|
+
background: {BG};
|
|
248
|
+
color: {CREAM};
|
|
249
|
+
border: solid {SIGNAL_GREEN};
|
|
250
|
+
}}
|
|
251
|
+
Input:focus {{
|
|
252
|
+
border: solid {TEAL_LIGHT};
|
|
253
|
+
}}
|
|
254
|
+
Checkbox {{
|
|
255
|
+
background: {BG};
|
|
256
|
+
color: {CREAM};
|
|
257
|
+
border: none;
|
|
258
|
+
}}
|
|
259
|
+
Select {{
|
|
260
|
+
background: {BG};
|
|
261
|
+
color: {CREAM};
|
|
262
|
+
}}
|
|
263
|
+
Footer {{
|
|
264
|
+
background: {BG};
|
|
265
|
+
color: {DIM_TEXT};
|
|
266
|
+
}}
|
|
267
|
+
"""
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
def color_style(
|
|
271
|
+
rgb: tuple[int, int, int],
|
|
272
|
+
truecolor: bool | None = None,
|
|
273
|
+
bg_rgb: tuple[int, int, int] | None = None,
|
|
274
|
+
) -> Style:
|
|
275
|
+
"""Build a Rich Style with 256-color fallback when truecolor is unavailable."""
|
|
276
|
+
use_tc = detect_truecolor() if truecolor is None else truecolor
|
|
277
|
+
if use_tc:
|
|
278
|
+
fg = f"rgb({rgb[0]},{rgb[1]},{rgb[2]})"
|
|
279
|
+
bg = f"rgb({bg_rgb[0]},{bg_rgb[1]},{bg_rgb[2]})" if bg_rgb is not None else None
|
|
280
|
+
return Style(color=fg, bgcolor=bg)
|
|
281
|
+
fg_idx = rgb_to_ansi256(*rgb)
|
|
282
|
+
bg_idx = rgb_to_ansi256(*bg_rgb) if bg_rgb is not None else None
|
|
283
|
+
return Style(color=f"color({fg_idx})", bgcolor=f"color({bg_idx})" if bg_idx is not None else None)
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
def generate_signal_bands(width: int, rows: int, seed: int = 42) -> list[list[tuple[str, tuple[int, int, int]]]]:
|
|
287
|
+
"""Generate deterministic jittering/lossy horizontal signal-band rows."""
|
|
288
|
+
rng = random.Random(seed)
|
|
289
|
+
tones = (TEAL_LIGHT_RGB, TEAL_MID_RGB, TEAL_DARK_RGB)
|
|
290
|
+
glyphs = ("▀", "▄", "─")
|
|
291
|
+
band_rows: list[list[tuple[str, tuple[int, int, int]]]] = []
|
|
292
|
+
|
|
293
|
+
for r in range(rows):
|
|
294
|
+
row_cells: list[tuple[str, tuple[int, int, int]]] = []
|
|
295
|
+
# Occasional missing band (loss motif)
|
|
296
|
+
if rng.random() < 0.18 and r > 0:
|
|
297
|
+
band_rows.append([(" ", BANNER_BLUE_RGB)] * width)
|
|
298
|
+
continue
|
|
299
|
+
|
|
300
|
+
x = 0
|
|
301
|
+
while x < width:
|
|
302
|
+
seg_len = rng.randint(3, 12)
|
|
303
|
+
# Jittered thickness/glyph and occasional gap
|
|
304
|
+
if rng.random() < 0.22:
|
|
305
|
+
ch = " "
|
|
306
|
+
rgb = BANNER_BLUE_RGB
|
|
307
|
+
else:
|
|
308
|
+
ch = glyphs[(r + rng.randint(0, 1)) % len(glyphs)]
|
|
309
|
+
rgb = tones[min(len(tones) - 1, (r + rng.randint(0, 1)) % len(tones))]
|
|
310
|
+
for _ in range(min(seg_len, width - x)):
|
|
311
|
+
row_cells.append((ch, rgb))
|
|
312
|
+
x += 1
|
|
313
|
+
band_rows.append(row_cells)
|
|
314
|
+
return band_rows
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def render_signal_band_text(
|
|
318
|
+
width: int,
|
|
319
|
+
rows: int,
|
|
320
|
+
seed: int = 42,
|
|
321
|
+
truecolor: bool | None = None,
|
|
322
|
+
) -> Text:
|
|
323
|
+
"""Render deterministic signal-band stripes as Rich Text on royal-blue background."""
|
|
324
|
+
use_tc = detect_truecolor() if truecolor is None else truecolor
|
|
325
|
+
bands = generate_signal_bands(width, rows, seed=seed)
|
|
326
|
+
text = Text()
|
|
327
|
+
for r_idx, row in enumerate(bands):
|
|
328
|
+
for ch, rgb in row:
|
|
329
|
+
text.append(ch, style=color_style(rgb, truecolor=use_tc, bg_rgb=BANNER_BLUE_RGB))
|
|
330
|
+
if r_idx < len(bands) - 1:
|
|
331
|
+
text.append("\n")
|
|
332
|
+
return text
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def segmented_bar(fraction: float, width: int = 12) -> str:
|
|
336
|
+
"""Return a segmented ASCII/block progress bar."""
|
|
337
|
+
clamped = max(0.0, min(1.0, fraction))
|
|
338
|
+
filled = int(round(clamped * width))
|
|
339
|
+
return f"[{'█' * filled}{'░' * (width - filled)}]"
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
def format_status_line(label: str, fraction: float = 1.0, bar_width: int = 12) -> str:
|
|
343
|
+
"""Format the bottom status line with a segmented progress bar."""
|
|
344
|
+
pct = int(round(max(0.0, min(1.0, fraction)) * 100))
|
|
345
|
+
return f"{label} {segmented_bar(fraction, width=bar_width)} {pct:>3}%"
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
class RedTopRule(Static):
|
|
349
|
+
"""Full-width red rule rendered across the top under the screen title."""
|
|
350
|
+
|
|
351
|
+
def on_mount(self) -> None:
|
|
352
|
+
self._refresh_rule()
|
|
353
|
+
|
|
354
|
+
def on_resize(self) -> None:
|
|
355
|
+
self._refresh_rule()
|
|
356
|
+
|
|
357
|
+
def _refresh_rule(self) -> None:
|
|
358
|
+
w = max(20, self.size.width or 80)
|
|
359
|
+
self.update("━" * w)
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
def make_top_title(screen_name: str) -> Static:
|
|
363
|
+
"""Create the consistent top title bar."""
|
|
364
|
+
return Static(f"SPONGEBOB v{__version__} // {screen_name.upper()}", classes="top-title")
|