print-break
A simple Rust debugging macro that pretty-prints variables and pauses execution. No debugger needed.
Features
- Pretty-prints any
Debugtype with syntax highlighting - Auto-detects JSON, TOML, YAML strings and formats them with colors
- Pauses execution until you press Enter
- Compiles to nothing in release builds - zero overhead in production
- Disable at runtime with
PRINT_BREAK=0 - Interactive controls: continue, quit, skip, more, help
- Stack traces - press
tto see how you got there - Clipboard support - press
cto copy values - Elapsed time - see time between breakpoints
- Conditional breakpoints with
print_break_if! - Non-TTY safe - won't hang in CI/piped output
- Customizable borders - rounded, sharp, double, or ASCII
Installation
[]
= "0.1"
Usage
use ;
Output
┌─ BREAK #1 ─────────────────────────────────────
│ src/main.rs:8 │
├────────────────────────────────────────────────
│ user_id = 42
│ name = "ferris"
│ items = [1, 2, 3]
└────────────────────────────────────────────────
[Enter=continue, m=more, s=skip all, q=quit]
Interactive Controls
When paused at a breakpoint:
| Key | Action |
|---|---|
| Enter | Continue to next breakpoint |
| m | Show full output (if truncated) |
| t | Show stack trace |
| c | Copy value to clipboard |
| s | Skip all remaining breakpoints |
| q | Quit the program |
| h / ? | Show help |
Environment Variables
# Disable all breakpoints
PRINT_BREAK=0
# Re-enable (default)
PRINT_BREAK=1
# Set max nesting depth for structs (default: 4)
PRINT_BREAK_DEPTH=6
# Show all nesting (no collapse)
PRINT_BREAK_DEPTH=999
# Border styles: rounded (default), sharp, double, ascii
PRINT_BREAK_STYLE=double
PRINT_BREAK_STYLE=ascii
CI / Non-Interactive Mode
When stderr is not a TTY (piped to file, running in CI), print-break automatically:
- Disables colors
- Skips the pause (won't hang your CI)
- Still prints the debug output for logging
Conditional Breakpoints
Perfect for debugging loops:
use print_break_if;
for i in 0..1000
Release Builds
In release builds (cargo build --release), all print_break! and print_break_if! calls compile to nothing - zero runtime overhead.
Format Detection
Strings are automatically detected and pretty-printed:
- JSON - Objects and arrays
- TOML - Configuration files
- YAML - Configuration files
- Plain text - Word-wrapped at 80 characters
Long output is truncated at 50 lines. Press m to see the full output.
Editor Integration
Neovim
Copy editors/nvim/print-break.lua to your Neovim config:
Keybindings (Rust files only):
| Key | Mode | Action |
|---|---|---|
<leader>pb |
Normal | Insert print_break!() with word under cursor |
<leader>pb |
Visual | Wrap selection in print_break!() |
<leader>pB |
Normal | Insert print_break_if!(condition, vars) |
<leader>pc |
Normal | Remove all print_break! from current buffer |
<leader>pC |
Normal | Remove all print_break! from all Rust files |
Smart features:
- Automatically captures the variable under cursor
- Appends to existing
print_break!if one exists on the next line - Finds end of multi-line statements before inserting
License
MIT