| Crates.io | ratatui-code-editor |
| lib.rs | ratatui-code-editor |
| version | 0.0.1 |
| created_at | 2025-10-16 12:14:17.685022+00 |
| updated_at | 2025-10-16 12:14:17.685022+00 |
| description | ratatui-code-editor is A code editor widget for ratatui, built with syntax highlighting powered by Tree-sitter. |
| homepage | https://github.com/vipmax/ratatui-code-editor |
| repository | https://github.com/vipmax/ratatui-code-editor.git |
| max_upload_size | |
| id | 1885882 |
| size | 282,655 |
A code editor widget for Ratatui, built with syntax highlighting powered by Tree-sitter.

The Ratatui Code Editor features blazing fast syntax highlighting powered by Tree-sitter. Tree-sitter incrementally parses your code in real time, enabling blazing fast, accurate and context-aware highlighting for all supported languages.
Performance Features:
This approach means you get instant, editor-quality highlighting in your terminal, with no lagβeven for big files or wide code blocks.
Add this to your Cargo.toml:
anyhow = "1.0"
crossterm = "0.29"
ratatui = "0.29"
ratatui-code-editor = { git = "https://github.com/vipmax/ratatui-code-editor" }
use crossterm::{
event::{self, Event, KeyCode},
execute,
terminal::{
enable_raw_mode, disable_raw_mode,
EnterAlternateScreen, LeaveAlternateScreen
},
};
use ratatui::{Terminal, backend::CrosstermBackend, layout::Position};
use ratatui_code_editor::editor::Editor;
use ratatui_code_editor::theme::vesper;
use std::io::stdout;
fn main() -> anyhow::Result<()> {
enable_raw_mode()?;
execute!(stdout(), EnterAlternateScreen)?;
let backend = CrosstermBackend::new(stdout());
let mut terminal = Terminal::new(backend)?;
let content = "fn main() {\n println!(\"Hello, world!\");\n}";
let mut editor = Editor::new("rust", content, vesper());
let mut editor_area = ratatui::layout::Rect::default();
loop {
terminal.draw(|f| {
let area = f.area();
editor_area = area;
f.render_widget(&editor, editor_area);
let cursor = editor.get_visible_cursor(&area);
if let Some((x,y)) = cursor {
f.set_cursor_position(Position::new(x, y));
}
})?;
if let Event::Key(key) = event::read()? {
if key.code == KeyCode::Esc {
break;
}
editor.input(key, &editor_area)?;
}
}
disable_raw_mode()?;
execute!(stdout(), LeaveAlternateScreen)?;
Ok(())
}
Run the included examples to see the editor in action:
# Minimal editor example
cargo run --release --example minimal
# Half-screen editor
cargo run --release --example half
# Split-screen editor
cargo run --release --example split
# Editor
cargo run --release --example editor <filename>
Any printable character - Insert character
Delete - Delete characters
Enter - Insert new line
Tab - Insert tab or spaces
Ctrl+D - Duplicate
Ctrl+X - Cut
Alt+Enter - go to next line
Alt+/ - comment/uncomment
The editor comes with built-in themes:
vesper - Dark theme defaultlet custom_theme = vec![
("keyword", "#ff6b6b"),
("string", "#4ecdc4"),
("comment", "#95a5a6"),
("function", "#f39c12"),
];
let editor = Editor::new("rust", content, custom_theme);
The editor is built with several key components:
ratatui - Terminal UI frameworktree-sitter - Syntax highlighting parserropey - Efficient text buffercrossterm - Cross-platform terminal manipulationarboard - Clipboard accessunicode-width, unicode-segmentation - Unicode text width calculationContributions are welcome! Please feel free to submit issues, feature requests, or pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.