Replace illwill with custom canvas — zero dependencies

- Custom terminal canvas: one buffer, one write() per frame
- Threaded audio via Nim channels (20fps → 60fps)
- 6 phosphor palettes (green, amber, cyan, blue, white, red)
- All tuning constants at top of osc.nim
- No illwill dependency, binary 352KB → 200KB
- CRT effects use same palette as trace

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
rolandnsharp
2026-04-07 17:33:45 +10:00
parent cdd3523550
commit 5dbd3ebfb6
7 changed files with 451 additions and 271 deletions

View File

@@ -1,6 +1,6 @@
# terminal-oscilloscope
A terminal-based oscilloscope with CRT phosphor physics, written in Nim using [illwill](https://github.com/johnnovak/illwill).
A terminal-based oscilloscope with CRT phosphor physics, written in Nim. Zero dependencies — 200KB binary, just libc.
![demo](demo.gif)
@@ -10,7 +10,9 @@ A terminal-based oscilloscope with CRT phosphor physics, written in Nim using [i
- **Y-T and X-Y modes** — time-domain waveform or Lissajous figures
- **Phosphor persistence** — beam bloom, decay trails, intensity-based shading
- **Half-block rendering** — 2x vertical resolution using Unicode `▀▄█` characters
- **Live audio capture** — direct libav bindings via dlopen, zero dependencies
- **Live audio capture** — direct libav bindings via dlopen, zero install
- **Threaded audio** — 60fps rendering, audio capture on separate thread
- **6 CRT phosphor palettes** — green, amber, cyan, blue, white, red
## Install
@@ -19,7 +21,7 @@ Requires [Nim](https://nim-lang.org/) 2.x.
```bash
git clone https://github.com/rolandnsharp/terminal-oscilloscope.git
cd terminal-oscilloscope
nimble build
nim c -d:release --threads:on -o:osc src/osc.nim
./osc
```
@@ -32,6 +34,37 @@ nimble build
| `]` / `[` | Zoom in / out time axis |
| `q` | Quit (with CRT shutdown effect) |
## Configuration
Edit the constants at the top of `src/osc.nim`:
```nim
const
# Phosphor physics
Decay = 0.85 # persistence per frame (0.01.0)
Beam = 0.4 # intensity at beam impact
Bloom = 0.08 # horizontal glow spread
# Phosphor glow thresholds
HotGlow = 0.7 # white-hot beam core
WarmGlow = 0.4 # bright phosphor
CoolGlow = 0.15 # dim persistence trail
# Palette: green, amber, cyan, blue, white, red
Palette = "green"
```
### Palettes
| Name | Phosphor | Look |
|------|----------|------|
| `green` | P31 | classic oscilloscope |
| `amber` | P12 | warm retro terminal |
| `cyan` | P7 | Tektronix blue-green |
| `blue` | P11 | cool/modern |
| `white` | P4 | TV phosphor |
| `red` | P22-R | radar display |
## Audio
Captures system audio by opening the PulseAudio/PipeWire monitor of your default output sink directly via libavformat and libavdevice. Libraries are loaded at runtime with `dlopen` — no dev packages, no subprocess, no extra dependencies.