code_mesh_tui/lib.rs
1/*!
2# Code Mesh TUI
3
4Terminal User Interface for Code Mesh - A modern, responsive terminal interface
5that enhances the user experience with interactive chat, file viewing, diff
6comparison, and more.
7
8## Architecture
9
10The TUI is built using ratatui and crossterm for cross-platform terminal handling,
11with a component-based architecture similar to React components.
12
13### Core Components
14
15- **App**: Main application state and event handling
16- **Chat**: Interactive chat interface with message history and markdown rendering
17- **FileViewer**: File browser and viewer with syntax highlighting
18- **DiffViewer**: Side-by-side and unified diff comparison
19- **StatusBar**: System information and mode indicators
20- **CommandPalette**: Quick action interface
21- **Dialog**: Modal dialogs for forms and confirmations
22
23### Features
24
25- Responsive layout system with panels and windows
26- Keyboard navigation and shortcuts
27- Mouse support where appropriate
28- Theme system with customizable colors
29- Syntax highlighting for code blocks
30- Real-time log streaming
31- Progress indicators for long operations
32- Accessibility features (high contrast, etc.)
33
34## Usage
35
36```rust
37use code_mesh_tui::{App, Config};
38
39#[tokio::main]
40async fn main() -> anyhow::Result<()> {
41 let config = Config::default();
42 let mut app = App::new(config).await?;
43 app.run().await
44}
45```
46*/
47
48pub mod app;
49pub mod chat;
50pub mod components;
51pub mod config;
52pub mod diff;
53pub mod events;
54pub mod file_viewer;
55pub mod layout;
56pub mod renderer;
57pub mod status;
58pub mod theme;
59pub mod utils;
60
61pub use app::App;
62pub use config::Config;
63
64use anyhow::Result;
65use crossterm::{
66 event::{DisableMouseCapture, EnableMouseCapture},
67 execute,
68 terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
69};
70use ratatui::{backend::CrosstermBackend, Terminal};
71use std::io;
72
73/// Initialize the terminal for TUI mode
74pub fn init_terminal() -> Result<Terminal<CrosstermBackend<io::Stdout>>> {
75 enable_raw_mode()?;
76 let mut stdout = io::stdout();
77 execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?;
78 let backend = CrosstermBackend::new(stdout);
79 let terminal = Terminal::new(backend)?;
80 Ok(terminal)
81}
82
83/// Restore the terminal to normal mode
84pub fn restore_terminal(terminal: &mut Terminal<CrosstermBackend<io::Stdout>>) -> Result<()> {
85 disable_raw_mode()?;
86 execute!(
87 terminal.backend_mut(),
88 LeaveAlternateScreen,
89 DisableMouseCapture
90 )?;
91 terminal.show_cursor()?;
92 Ok(())
93}