netrunner_cli 0.7.1

A feature-rich Rust-based CLI to test and analyze your internet connection
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
# NetRunner CLI - Examples & Demos

This directory contains examples and demo recordings for NetRunner CLI.

## ๐Ÿ“น VHS Tapes (Terminal Recordings)

We use [VHS](https://github.com/charmbracelet/vhs) to create automated terminal recordings. These demonstrate various features and can be used to generate GIF/video demos. Generated GIFs are stored in `vhs/target/` and tracked via **Git LFS**.

### Previews

#### ๐Ÿš€ Speed Test
![speed-test](vhs/target/speed-test.gif)

#### ๐Ÿ“Š Statistics Dashboard
![statistics-dashboard](vhs/target/statistics-dashboard.gif)

#### ๐Ÿ—‚ Test History
![history](vhs/target/history.gif)

### Available Demos

#### 1. **speed-test.tape** - Basic Speed Test
Demonstrates the core speed test functionality:
- Automatic IP-based geolocation
- Server discovery and selection
- Download and upload speed testing
- Real-time animated graphs
- Results display

**Run:** `vhs examples/vhs/speed-test.tape` (outputs to `vhs/target/speed-test.gif`)

#### 2. **speed-test-history.tape** - Test History
Shows historical test tracking:
- Building test history
- Viewing recent tests
- Displaying statistics
- 30-day retention

**Run:** `vhs examples/vhs/speed-test-history.tape` (outputs to `vhs/target/history.gif`)

#### 3. **statistics-dashboard.tape** - Statistics Dashboard โ† new
Showcases the full-screen interactive statistics TUI powered by [tui-piechart](https://crates.io/crates/tui-piechart):
- Seeds 20 realistic speed-test results spanning 30 days
- Four pie charts: Download speed ยท Upload speed ยท Ping latency ยท Connection quality
- Summary panel with avg / max / min for all metrics
- Scrollable results table
- Keyboard navigation (Tab, arrow keys, q)

**Run:** `vhs examples/vhs/statistics-dashboard.tape` (outputs to `vhs/target/statistics-dashboard.gif`)

## ๐ŸŽฌ Generating Recordings

### Prerequisites

Install VHS:
```bash
# macOS
brew install vhs

# Linux (with Go installed)
go install github.com/charmbracelet/vhs@latest

# Or download from: https://github.com/charmbracelet/vhs/releases
```

### Generate All Recordings

```bash
# From project root โ€” build the release binary first
cargo build --release
cargo build --release --example statistics_dashboard

# Then generate each tape
vhs examples/vhs/speed-test.tape
vhs examples/vhs/speed-test-history.tape
vhs examples/vhs/statistics-dashboard.tape

# Or generate all at once
for tape in examples/vhs/*.tape; do
    echo "Recording $tape..."
    vhs "$tape"
done
```

### Output Files

Generated GIFs are saved in `vhs/target/` and tracked via **Git LFS**:
- `vhs/target/speed-test.gif` โ€” Basic speed test demo
- `vhs/target/history.gif` โ€” History management
- `vhs/target/statistics-dashboard.gif` โ€” Statistics dashboard (tui-piechart)

**Git LFS:** The `.gitattributes` file at the project root tracks
`examples/vhs/target/*.gif` as LFS objects so large binaries never bloat
the Git history. Clone with `git lfs pull` to fetch the GIFs locally.

## ๐ŸŽจ Customizing Recordings

### VHS Configuration

Each `.tape` file can be customized:

```vhs
# Appearance
Set Theme "Dracula"          # Color scheme
Set FontSize 14              # Terminal font size
Set Width 1200               # Terminal width
Set Height 800               # Terminal height

# Behavior
Set PlaybackSpeed 0.5        # Slower = 0.5, Faster = 2.0
Set TypingSpeed 100ms        # Speed of typing animation

# Output
Output target/demo.gif           # Output file path (gitignored)
```

### Available Themes

- Dracula (default in examples)
- Monokai
- Nord
- Solarized Dark/Light
- And many more...

See: https://github.com/charmbracelet/vhs#themes

## ๐Ÿš€ Code Examples

### Rust Examples

NetRunner CLI provides several comprehensive Rust examples demonstrating different features:

#### 1. **logo_demo.rs** - Logo Widget Demo
Simple example showing the NetRunner logo with cyberpunk aesthetics.

```bash
cargo run --example logo_demo
cargo run --example logo_demo small
cargo run --example logo_demo tiny
```

#### 2. **basic_speed_test.rs** - Basic Speed Test
Complete example of running a speed test programmatically.

```bash
cargo run --example basic_speed_test
```

Features:
- Running a speed test
- Accessing test results
- Displaying metrics
- Performance analysis
- Error handling

#### 3. **history_management.rs** - History Storage
Working with NetRunner's embedded database for test history.

```bash
cargo run --example history_management
```

Features:
- Storing test results
- Retrieving historical data
- Calculating statistics
- Analyzing trends
- Comparing current vs historical performance
- Database maintenance
- Exporting to JSON

#### 4. **statistics_dashboard.rs** - Interactive Statistics Dashboard โ† new
Seeds 20 realistic speed-test results into the history database and launches
the full-screen interactive statistics TUI powered by
[tui-piechart](https://crates.io/crates/tui-piechart).

```bash
cargo run --example statistics_dashboard
```

Features:
- Seeding `HistoryStorage` with varied `SpeedTestResult` data (no network needed)
- Mixed `ConnectionQuality` ratings across all tiers (Excellent โ†’ Failed)
- Four European server locations: Frankfurt ยท Amsterdam ยท London ยท Paris
- Full-screen TUI with four live pie charts and a scrollable results table
- Keyboard navigation (Tab / arrow keys / q)

**Controls inside the TUI:**

| Key | Action |
|-----|--------|
| `Tab` / `โ†’` | Cycle to the next chart |
| `โ†` | Cycle to the previous chart |
| `โ†‘` / `k` | Scroll results table up |
| `โ†“` / `j` | Scroll results table down |
| `q` / `Esc` | Quit |

![statistics-dashboard](vhs/target/statistics-dashboard.gif)

#### 5. **custom_configuration.rs** - Custom Configurations
Different configuration profiles for various use cases.

```bash
cargo run --example custom_configuration
```

Configurations demonstrated:
- Quick Test (fast checks)
- Accurate Test (detailed analysis)
- CI/CD Pipeline (automation)
- Slow Connection (mobile/DSL)
- Gigabit Test (fiber/high-speed)

#### 6. **continuous_monitoring.rs** - Network Monitoring
Continuous network monitoring with alerts and logging.

```bash
cargo run --example continuous_monitoring
```

Features:
- Periodic speed testing
- Real-time monitoring
- Performance alerts
- Data logging to CSV
- Uptime tracking
- Statistics display
- Alert system

### Example Output Comparison

**basic_speed_test.rs:**
```
โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘          NetRunner CLI - Basic Speed Test Example        โ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

๐Ÿ“Š Speed Metrics:
   โ†“ Download: 487.30 Mbps
   โ†‘ Upload:   125.80 Mbps
   ๐Ÿ“ก Ping:    8.20 ms
   โšก Quality:  Excellent
```

**json_output.rs:**
```json
{
  "timestamp": "2024-01-15T10:30:00Z",
  "download_mbps": 487.3,
  "upload_mbps": 125.8,
  "ping_ms": 8.2,
  "quality": "Excellent"
}
```

**continuous_monitoring.rs:**
```
๐Ÿ“Š Test #1 - 2024-01-15 10:30:00
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
   โ†“ Download: 487.30 Mbps
   โ†‘ Upload:   125.80 Mbps
   ๐Ÿ“ก Ping:    8.20 ms
   โšก Quality:  Excellent
   โœ“ Test completed successfully
```

## ๐Ÿ“ Usage Examples

### Basic Speed Test

```bash
# Simple speed test
netrunner speed

# With JSON output
netrunner speed --json

# Without animations (faster)
netrunner speed --no-animation
```

### Debug Mode

```bash
# Show trace logs for failed geolocation services
NETRUNNER_DEBUG=1 netrunner speed

# Useful for troubleshooting:
# - API rate limits (429 errors)
# - Network timeouts
# - Service outages
```

### History Management

```bash
# View recent tests
netrunner history

# Show detailed statistics
netrunner history --stats

# View specific time range
netrunner history --days 7
```

### JSON Integration

```bash
# Save to file
netrunner speed --json > results.json

# Parse with jq
netrunner speed --json | jq '.download_mbps'

# Monitor continuously
watch -n 300 'netrunner speed --json | jq -r ".download_mbps"'

# CI/CD integration
netrunner speed --json | jq -e '.download_mbps > 100'
```

### Network Diagnostics

```bash
# Full diagnostics
netrunner diagnose

# Combined analysis
netrunner analyze
```

## ๐Ÿ”ง Advanced Examples

### Custom Server Testing

```bash
# Test against specific server
netrunner speed --server https://custom-server.example.com

# Useful for:
# - Internal network testing
# - CDN endpoint validation
# - Custom speed test servers
```

### Automated Monitoring

```bash
#!/bin/bash
# monitor.sh - Check speed every 5 minutes

while true; do
    RESULT=$(netrunner speed --json)
    DOWNLOAD=$(echo "$RESULT" | jq -r '.download_mbps')
    QUALITY=$(echo "$RESULT" | jq -r '.quality')
    
    echo "$(date): $DOWNLOAD Mbps - $QUALITY" >> speed_log.txt
    
    # Alert if speed drops below threshold
    if (( $(echo "$DOWNLOAD < 100" | bc -l) )); then
        echo "Warning: Speed below 100 Mbps!"
    fi
    
    sleep 300
done
```

### Integration with Prometheus

```bash
#!/bin/bash
# Export metrics for Prometheus

RESULT=$(netrunner speed --json)

echo "# HELP netrunner_download_mbps Download speed in Mbps"
echo "# TYPE netrunner_download_mbps gauge"
echo "netrunner_download_mbps $(echo "$RESULT" | jq -r '.download_mbps')"

echo "# HELP netrunner_upload_mbps Upload speed in Mbps"
echo "# TYPE netrunner_upload_mbps gauge"
echo "netrunner_upload_mbps $(echo "$RESULT" | jq -r '.upload_mbps')"

echo "# HELP netrunner_ping_ms Ping latency in milliseconds"
echo "# TYPE netrunner_ping_ms gauge"
echo "netrunner_ping_ms $(echo "$RESULT" | jq -r '.ping_ms')"
```

## ๐Ÿ“š Documentation

For more information, see:
- [Main README]../README.md - Project overview
- [QUICK_REFERENCE.md]../QUICK_REFERENCE.md - Quick reference guide
- [GEOLOCATION_SERVER_FIX.md]../GEOLOCATION_SERVER_FIX.md - Technical details

## ๐ŸŽฏ Contributing Examples

Want to add a new example? Great!

1. Create a `.tape` file following the existing format
2. Test it with `vhs your-example.tape`
3. Add documentation to this README
4. Submit a pull request

## ๐ŸŽ“ Learning Path

Recommended order for exploring the examples:

1. **Start here:** `basic_speed_test.rs` โ€” Learn the fundamentals
2. **Then:** `custom_configuration.rs` โ€” Customize for your needs
3. **After:** `history_management.rs` โ€” Track results over time
4. **Next:** `statistics_dashboard.rs` โ€” Visualise history with pie charts โ† new
5. **Finally:** `continuous_monitoring.rs` โ€” Build production monitors

## ๐Ÿ”ง Development Tips

### Using Examples as Templates

All examples are well-documented and can be used as templates:

```rust
// Copy an example
cp examples/basic_speed_test.rs examples/my_custom_test.rs

// Modify for your needs
// Add to Cargo.toml if needed

// Run your custom example
cargo run --example my_custom_test
```

### Integration Patterns

**As a Library:**
```rust
use netrunner_cli::modules::{
    speed_test::SpeedTest,
    types::TestConfig,
};

// Use in your own application
let config = TestConfig::default();
let test = SpeedTest::new(config)?;
let result = test.run_full_test().await?;
```

**In Scripts:**
```bash
#!/bin/bash
# Run speed test and check threshold
RESULT=$(netrunner speed --json)
SPEED=$(echo "$RESULT" | jq -r '.download_mbps')

if (( $(echo "$SPEED < 100" | bc -l) )); then
    echo "Speed below threshold!"
    exit 1
fi
```

## ๐Ÿ“„ License

All examples are licensed under MIT, same as the main project.