Ratatui
Ratatui already has a good bridge for ANSI-colored text: ansi-to-tui. Lumis already emits ANSI. So the clean integration path is:
- highlight with Lumis terminal output
- convert ANSI to
ratatui::text::Text - render that text in a widget
That gives you syntax highlighting in terminal UIs without a custom Lumis formatter just for Ratatui.
Add dependencies
[dependencies]
lumis = "0.7"
ratatui = "0.29"
ansi-to-tui = "8"
Highlight and render
use ansi_to_tui::IntoText;
use lumis::{formatters::Formatter, languages::Language, themes, TerminalBuilder};
use ratatui::widgets::{Block, Paragraph};
fn code_paragraph(source: &str, language: Language) -> Paragraph<'static> {
let theme = themes::get("dracula").unwrap();
let formatter = TerminalBuilder::new()
.language(language)
.theme(Some(theme))
.build()
.unwrap();
let mut output = Vec::new();
formatter.format(source, &mut output).unwrap();
let ansi = String::from_utf8(output).unwrap();
let text = ansi.into_text().unwrap();
Paragraph::new(text).block(Block::bordered().title("main.rs"))
}
Use a dark theme (like dracula) for terminal UIs since they render on a dark background.