Pour voir vos erreurs de compilation Rust dans un joli rataTUI (WIP)
Find a file
Théo Codatte 31c2283a1f init tui
2026-02-10 01:55:31 +01:00
src init tui 2026-02-10 01:55:31 +01:00
Cargo.toml init tui 2026-02-10 01:55:31 +01:00
README.md init tui 2026-02-10 01:55:31 +01:00

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 build integration (subprocess spawning)
  • Stream JSON in real-time as compilation happens
  • Re-run build from TUI (r key)
  • Open files in editor
  • Filter/search errors
  • Configuration file support

🚀 To Get Started

  1. Copy all provided files to your project
  2. Run: cargo build (should compile with sample error)
  3. Run: cargo run (should show interactive TUI)
  4. 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.toml has all dependencies
  • Ensure src/tui/mod.rs exists (module path)
  • Run cargo check to 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


🎓 Learning Path

  1. Understand the data model (model.rs)

    • How errors are represented
    • What fields are important
  2. Learn the parser (parser.rs)

    • How to extract errors from JSON
    • Error filtering logic
  3. Study the UI (tui/ui.rs)

    • Ratatui widgets (List, Paragraph, Block)
    • Layout and constraints
  4. Explore event handling (tui/handler.rs)

    • Keyboard input mapping
    • State mutations
  5. 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 build integration
  • 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

  1. Get it compiling: Follow QUICKSTART.md
  2. Test the UI: Navigate with keybindings, verify display
  3. Integrate real builds: Implement run_cargo_build() in Phase 2
  4. Add features: Based on your needs
  5. 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! 💖