Pour voir vos erreurs de compilation Rust dans un joli rataTUI (WIP)
| src | ||
| Cargo.toml | ||
| README.md | ||
lazycargo MVP - Complete Deliverables
📦 What You Have
A complete, working MVP scaffold for lazycargo - an interactive TUI for exploring Cargo build errors.
Files Provided
📁 lazycargo/
├── 📄 Cargo.toml # Dependencies configuration
├── 📄 src/main.rs # Entry point & TUI loop
├── 📄 src/model.rs # Data structures (BuildError, AppState)
├── 📄 src/parser.rs # JSON parsing from cargo output
├── 📄 src/error.rs # Custom error types
├── 📁 src/tui/
│ ├── 📄 mod.rs # Module declarations
│ ├── 📄 ui.rs # Rendering (error list + details)
│ └── 📄 handler.rs # Event handling (keybindings)
├── 📄 QUICKSTART.md # 5-minute setup guide
├── 📄 lazycargo-mvp.md # Detailed architecture guide
└── 🖼️ lazycargo-ui.png # UI mockup image
🎯 MVP Scope
✅ Implemented
- Data Model: Complete JSON parsing for rustc compiler messages
- TUI Rendering: Two-pane layout (error list | error details)
- Event Handling: Vi-style navigation (j/k, g/G, Page Up/Down)
- Error Display: Shows file, line, column, code, message, snippet
- Sample Data: Pre-populated with example error for testing
🔄 Next Phase (Not in MVP)
- Real
cargo buildintegration (subprocess spawning) - Stream JSON in real-time as compilation happens
- Re-run build from TUI (
rkey) - Open files in editor
- Filter/search errors
- Configuration file support
🚀 To Get Started
- Copy all provided files to your project
- Run:
cargo build(should compile with sample error) - Run:
cargo run(should show interactive TUI) - Test: Navigate with j/k, quit with q
That's it! You have a working TUI with a fake error to test the UI.
🔍 Architecture Overview
Data Flow
┌─────────────────────────────────────┐
│ cargo build --message-format=json │
└──────────────┬──────────────────────┘
│
▼
┌──────────────┐
│ parser.rs │ (JSON → BuildError)
└──────┬───────┘
│
▼
┌──────────────┐
│ AppState │ (Vec<BuildError>)
└──────┬───────┘
│
┌──────▼───────┐
│ Crossterm │ (Event handling)
│ Events │
└──────┬───────┘
│
┌──────▼───────┐
│ handler.rs │ (Update AppState)
└──────┬───────┘
│
┌──────▼───────┐
│ ui.rs │ (Render Frame)
└──────┬───────┘
│
▼
┌──────────────┐
│ Ratatui │ (Display in Terminal)
└──────────────┘
Module Responsibilities
| Module | Purpose |
|---|---|
main.rs |
Entry point, TUI loop, event polling |
model.rs |
Data structures (BuildError, AppState, JSON DTOs) |
parser.rs |
Parse JSON lines from cargo output |
error.rs |
Custom error types with thiserror |
tui/ui.rs |
Render widgets (List, Paragraph, Block) |
tui/handler.rs |
Handle keyboard input, update AppState |
📝 Keybindings
Navigation:
j / ↓ Next error
k / ↑ Previous error
g First error (go)
G Last error (Go)
Ctrl+D Page down
Ctrl+U Page up
Actions:
r Re-run build (TODO)
q Quit
Future:
/ Search (TODO)
: Command mode (TODO)
e Open in editor (TODO)
🔧 Technology Stack
| Dependency | Version | Purpose |
|---|---|---|
| ratatui | 0.30 | Terminal UI framework |
| crossterm | 0.28 | Terminal abstraction (events) |
| serde_json | 1.0 | Parse cargo JSON output |
| serde | 1.0 | Serialization framework |
| color_eyre | 0.6 | Better error messages |
| thiserror | 1.0 | Custom error types |
📖 How to Extend
Phase 2: Real Cargo Integration
// In build.rs (new file)
pub async fn run_cargo_build(project_path: &str) -> Result<Vec<BuildError>> {
let output = Command::new("cargo")
.arg("build")
.arg("--message-format=json")
.stdout(Stdio::piped())
.spawn()?;
let reader = BufReader::new(output.stdout.unwrap());
let errors: Vec<BuildError> = reader
.lines()
.filter_map(|line| parse_cargo_json_line(&line.ok()?))
.collect();
Ok(errors)
}
Phase 3: Open in Editor
// In handler.rs
KeyCode::Char('e') => {
let error = &app_state.errors[app_state.selected_index];
open::that(format!("{}:{}", error.file, error.line))?;
}
Phase 4: Search/Filter
// In model.rs - add to AppState
pub struct AppState {
pub errors: Vec<BuildError>,
pub selected_index: usize,
pub filter: String, // NEW
pub filtered_errors: Vec<usize>, // NEW - indices into errors
// ...
}
🐛 Debugging Tips
Build Fails?
- Check
Cargo.tomlhas all dependencies - Ensure
src/tui/mod.rsexists (module path) - Run
cargo checkto see compilation errors
UI Doesn't Display?
- Confirm
ratatui::init()is called before rendering - Check terminal size (need at least 60x20)
- Ensure event loop is running in main TUI loop
Parser Not Working?
- Print JSON to stdout:
eprintln!("{}", line); - Use
serde_json::from_str::<Value>(line)to debug - Check if
reason == "compiler-message"
Colors Not Showing?
- Terminal must support ANSI colors
- Try
CLICOLOR_FORCE=1 cargo run - Some terminals have color support disabled
📚 Reference Documentation
- Ratatui: https://docs.rs/ratatui/0.30/ratatui/
- Cargo JSON Format: https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages
- Crossterm: https://docs.rs/crossterm/0.28/crossterm/
- Serde: https://docs.rs/serde/latest/serde/
🎓 Learning Path
-
Understand the data model (model.rs)
- How errors are represented
- What fields are important
-
Learn the parser (parser.rs)
- How to extract errors from JSON
- Error filtering logic
-
Study the UI (tui/ui.rs)
- Ratatui widgets (List, Paragraph, Block)
- Layout and constraints
-
Explore event handling (tui/handler.rs)
- Keyboard input mapping
- State mutations
-
Put it together (main.rs)
- TUI loop pattern
- Terminal initialization/cleanup
🚢 Release Checklist
v0.1.0 (Current MVP)
- Parse rustc JSON output
- Display errors in interactive TUI
- Navigate with keybindings
- Show error details
v0.2.0 (Next)
- Real
cargo buildintegration - Stream errors in real-time
- Re-run build from UI
- Show build progress
v0.3.0 (Future)
- Open files in editor
- Filter/search errors
- Configuration file
- Error history/caching
v1.0.0 (Stable)
- Comprehensive documentation
- Multiple theme support
- Performance optimization
- Community feedback incorporated
💡 Ideas for Contributors
- Color themes: Implement dark/light mode toggle
- Themes: Add Nord, Dracula, Gruvbox color schemes
- Editor integration: Support VS Code, Vim, Emacs
- Performance: Profile and optimize for large projects
- Testing: Add unit tests for parser and UI
- Documentation: Write tutorials and guides
- Features: Add filtering, grouping, sorting options
🤝 License Recommendations
- MIT - Simple, permissive
- Apache 2.0 - Patent protection
- Dual MIT/Apache - Rust community standard (recommended)
📞 Next Steps
- Get it compiling: Follow QUICKSTART.md
- Test the UI: Navigate with keybindings, verify display
- Integrate real builds: Implement
run_cargo_build()in Phase 2 - Add features: Based on your needs
- Release: Share on crates.io when ready! 🎉
You now have everything needed to build the best Cargo error viewer in the Rust ecosystem! 🚀
Good luck! Questions? Check the docs, search GitHub, or ask the Rust community. The Rust community is incredibly helpful! 💖