# Ratatui (/integrations/ratatui)

[Full example on GitHub](https://github.com/leandrocp/lumis/tree/main/crates/lumis/examples/ratatui)

Ratatui already has a good bridge for ANSI-colored text: [`ansi-to-tui`](https://github.com/ratatui/ansi-to-tui). Lumis already emits ANSI. So the clean integration path is:

1. highlight with Lumis terminal output
2. convert ANSI to `ratatui::text::Text`
3. render that text in a widget

That gives you syntax highlighting in terminal UIs without a custom Lumis formatter just for Ratatui.

## Add dependencies

```toml
[dependencies]
lumis = "0.16"
ratatui = "0.30"
ansi-to-tui = "8"
```

## Highlight and render

```rust
use ansi_to_tui::IntoText;
use lumis::{highlight, languages::Language, themes, TerminalBuilder};
use ratatui::widgets::{Block, Paragraph};

fn code_paragraph(
    source: &str,
    language: Language,
) -> Paragraph<'static> {
    let theme = themes::get("catppuccin_frappe").unwrap();
    let formatter = TerminalBuilder::new()
        .language(language)
        .theme(Some(theme))
        .build()
        .unwrap();

    let ansi = highlight(source, formatter);
    let text = ansi.into_text().unwrap();

    Paragraph::new(text)
        .block(Block::bordered().title("main.rs"))
}
```

Use a dark theme (like `catppuccin_frappe`) for terminal UIs since they render on a dark background.