Skip to content

Commit ab5649d

Browse files
committed
update docs
1 parent 53795fa commit ab5649d

File tree

3 files changed

+77
-72
lines changed

3 files changed

+77
-72
lines changed

CLAUDE.md

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ SVT (Simple Viewer in Terminal) - A terminal-based image viewer with sxiv-like k
1111
- Terminal Backend: crossterm
1212
- Image Processing: image crate
1313
- CLI: clap (derive)
14+
- Config: serde + toml + dirs
1415

1516
## Project Structure
1617

@@ -22,6 +23,7 @@ svt/
2223
├── src/
2324
│ ├── main.rs # Entry point, CLI parsing, event loop
2425
│ ├── app.rs # App state, navigation, cache orchestration
26+
│ ├── config.rs # Config loading (file + env, priority: env > file > default)
2527
│ ├── fit.rs # Fit mode (Normal/Fit)
2628
│ ├── kgp.rs # Kitty Graphics Protocol helpers (encode/place/erase)
2729
│ ├── sender.rs # TerminalWriter (single stdout writer, status priority, cancel)
@@ -40,27 +42,15 @@ cargo clippy # Lint
4042

4143
## Keybindings
4244

43-
- `q` - Quit
44-
- `j` / `Space` / `l` - Next image
45-
- `k` / `Backspace` / `h` - Previous image
46-
- `g` - First image
47-
- `G` - Last image
48-
- `f` - Toggle fit
49-
- `r` - Reload (clear cache)
50-
- Counts supported (e.g. `5j`, `10G`)
51-
52-
## Environment Variables
53-
54-
- `SVT_NAV_LATCH_MS` - Navigation latch (ms) before drawing images (default: 150)
55-
- `SVT_RENDER_CACHE_SIZE` - Client-side render cache size (encoded images in memory, default: 100)
56-
- `SVT_TMUX_KITTY_MAX_PIXELS` - Max pixels for tmux+kitty in `Normal` mode (default: 2000000)
57-
- `SVT_FORCE_ALT_SCREEN` - Force alternate screen mode
58-
- `SVT_NO_ALT_SCREEN` - Disable alternate screen mode
59-
- `SVT_DEBUG` - Enable debug info in status bar
60-
- `SVT_TRACE_WORKER` - Write worker timing logs to `/tmp/svt_worker.log`
61-
- `SVT_KGP_NO_COMPRESS` - Disable zlib compression for KGP transmission
62-
- `SVT_COMPRESS_LEVEL` - Zlib compression level 0-9 (default: 6, higher = smaller but slower)
63-
- `SVT_PREFETCH_COUNT` - Number of images to prefetch ahead/behind (default: 5)
45+
See [README.md](README.md#keybindings).
46+
47+
## Configuration
48+
49+
Settings: `~/.config/svt/config.toml` or environment variables (`SVT_*`).
50+
51+
**Priority:** Environment variables > Config file > Defaults
52+
53+
See [README.md](README.md#configuration) for all options.
6454

6555
## Coding Conventions
6656

@@ -69,29 +59,13 @@ cargo clippy # Lint
6959
- Keep functions small and focused
7060
- Write tests for public functions
7161

72-
### Critical Invariants
73-
74-
- **stdout is written by `TerminalWriter` only** (`src/sender.rs`)
75-
- **Image output must be chunked at safe boundaries**
76-
- KGP chunk boundaries for transmit (`encode_chunks`)
77-
- per-row boundaries for placement/erase (`place_rows` / `erase_rows`)
78-
- **Navigation must stay responsive**
79-
- cancel in-flight image output on navigation (only when not transmitting)
80-
- avoid blocking the main loop on decode/encode or stdout I/O
81-
- **Single KGP ID per process**
82-
- `delete_by_id` before each transmit to clear terminal-side cache
83-
- prevents "wrong image" and "blank screen" issues
84-
- **Transmit must complete once started**
85-
- skip cancellation during active transmission (`is_transmitting()`)
86-
- ensures terminal receives complete image data
87-
88-
## Architecture Notes
62+
## Architecture & Invariants
8963

90-
- See `docs/architecture.md`.
64+
See [docs/architecture.md](docs/architecture.md).
9165

9266
## Contributing
9367

94-
See `CONTRIBUTING.md`.
68+
See [CONTRIBUTING.md](CONTRIBUTING.md).
9569

9670
## References
9771

CONTRIBUTING.md

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,50 @@
22

33
Thanks for contributing to `svt`.
44

5-
## Quick start
5+
## Quick Start
66

77
```bash
88
cargo build
99
cargo test
10-
cargo clippy --all-targets --all-features
10+
cargo clippy
11+
cargo fmt --check
1112
```
1213

13-
## Project layout
14+
## Project Layout
1415

15-
- `src/main.rs`: CLI + event loop
16-
- `src/app.rs`: app state, cache orchestration
17-
- `src/worker.rs`: image decode/resize/encode (thread)
18-
- `src/sender.rs`: `TerminalWriter` (single stdout writer, status priority, cancel)
19-
- `src/kgp.rs`: Kitty Graphics Protocol helpers
20-
- `docs/architecture.md`: system overview
16+
See [CLAUDE.md](CLAUDE.md#project-structure).
2117

22-
## Invariants (please keep)
18+
## Architecture & Invariants
2319

24-
- stdout must be written by **`TerminalWriter` only** (`src/sender.rs`)
25-
- image output must be chunked at safe boundaries
26-
- KGP chunk boundaries for transmit (`encode_chunks`)
27-
- per-row boundaries for placement/erase (`place_rows` / `erase_rows`)
28-
- navigation must stay responsive
29-
- cancel in-flight image output on navigation
30-
- avoid blocking the main loop on decode/encode or stdout I/O
20+
See [docs/architecture.md](docs/architecture.md).
3121

32-
## Environment variables (developer)
22+
## Configuration
3323

34-
| Env | Description |
35-
|-----|-------------|
36-
| `SVT_TRACE_WORKER=1` | Write worker timing logs to `/tmp/svt_worker.log` |
37-
| `SVT_DEBUG=1` | Add debug info to status bar |
24+
See [README.md](README.md#configuration).
3825

39-
## Tips
26+
For debugging:
4027

41-
- If you change terminal escape handling, test with a large image and rapid navigation to verify cancellation.
42-
- If tests print escape sequences, ensure the writer treats stdout as non-TTY during tests.
28+
| Config | Env | Description |
29+
|--------|-----|-------------|
30+
| `debug` | `SVT_DEBUG` | Show debug info in status bar |
31+
| `trace_worker` | `SVT_TRACE_WORKER` | Write timing logs to `/tmp/svt_worker.log` |
32+
33+
## Testing Tips
34+
35+
- Test with large images and rapid navigation to verify cancellation behavior.
36+
- Tests should not write escape sequences to stdout.
4337

4438
## Release
4539

46-
Push a tag like `v0.1.0` to build and attach binaries to a GitHub Release:
40+
Push a tag to trigger GitHub Actions release:
4741

4842
```bash
49-
git tag v0.1.0
50-
git push origin v0.1.0
43+
git tag v25.12.3
44+
git push origin v25.12.3
5145
```
5246

53-
Current workflow targets:
47+
**Versioning:** `YY.MM.PATCH` (e.g., `25.12.2` = December 2025, patch 2)
5448

49+
**Targets:**
5550
- macOS (Apple Silicon): `aarch64-apple-darwin`
56-
- Linux: `x86_64-unknown-linux-gnu`
51+
- Linux (x86_64): `x86_64-unknown-linux-gnu`

docs/architecture.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ The core goal is: keep navigation/status updates responsive even when image rend
55

66
## High-level pipeline
77

8-
There are three concurrent lanes:
8+
There are three concurrent "lanes":
99

1010
1. **Main thread** (`src/main.rs`)
11+
- Loads configuration (`src/config.rs`).
1112
- Reads key events.
1213
- Updates application state.
1314
- Decides when to request rendering.
@@ -78,7 +79,42 @@ This approach:
7879
`svt` uses a **client-side render cache** only:
7980

8081
- **Render cache** (`render_cache` in `App`): Stores decoded/resized/encoded image data.
81-
- Size controlled by `SVT_RENDER_CACHE_SIZE` (default: 15).
82+
- Size controlled by `render_cache_size` config (default: 100).
8283
- LRU eviction when cache is full.
8384

8485
The terminal-side cache is **not** relied upon. Each transmit starts with `delete_by_id` to ensure a clean slate. This trades some bandwidth for simplicity and correctness.
86+
87+
## Configuration
88+
89+
Settings are loaded at startup by `Config::load()` (`src/config.rs`):
90+
91+
1. Load from `~/.config/svt/config.toml` (if exists).
92+
2. Override with environment variables (`SVT_*`).
93+
3. Apply defaults for missing values.
94+
95+
**Priority:** Environment variables > Config file > Defaults
96+
97+
The `Config` struct is passed to `App` and propagated to worker requests as needed.
98+
99+
## Invariants
100+
101+
These invariants must be preserved when modifying the codebase:
102+
103+
1. **stdout via `TerminalWriter` only** (`src/sender.rs`)
104+
- No other component may write to stdout directly.
105+
106+
2. **Image output chunked at safe boundaries**
107+
- KGP chunk boundaries for transmit (`encode_chunks`)
108+
- Per-row boundaries for placement/erase (`place_rows` / `erase_rows`)
109+
110+
3. **Navigation stays responsive**
111+
- Cancel in-flight image output on navigation (except during transmit)
112+
- Avoid blocking the main loop on decode/encode or stdout I/O
113+
114+
4. **Single KGP ID per process**
115+
- `delete_by_id` before each transmit to clear terminal-side cache
116+
- Prevents "wrong image" and "blank screen" issues
117+
118+
5. **Transmit must complete once started**
119+
- Skip cancellation during active transmission (`is_transmitting()`)
120+
- Ensures terminal receives complete image data

0 commit comments

Comments
 (0)