ratatui-image

GitHub CI
Status

Showcase:

Recording

Image widgets for [Ratatui]

⚠️ THIS CRATE IS EXPERIMENTAL

⚠️ THE TERMWIZ RATATUI BACKEND IS BROKEN WITH THIS CRATE

Render images with graphics protocols in the terminal with [Ratatui].

Quick start

```rust use ratatui::{backend::{Backend, TestBackend}, Terminal, terminal::Frame, layout::Rect}; use ratatui_image::{ picker::{Picker, BackendType}, ImageSource, Resize, ResizeImage, protocol::ResizeProtocol, };

struct App { // We need to hold the render state. image: Box, }

fn main() -> Result<(), Box> { // It is highly recommended to use Picker::from_termios() instead! let mut picker = Picker::new((7, 16), BackendType::Sixel, None)?;

let dyn_img = image::io::Reader::open("./assets/Ada.png")?.decode()?;
let image = picker.new_state(dyn_img);
let mut app = App { image };

let backend = TestBackend::new(80, 30);
let mut terminal = Terminal::new(backend)?;

// loop:
terminal.draw(|f| ui(f, &mut app))?;

Ok(())

}

fn ui(f: &mut Frame, app: &mut App) { let image = ResizeImage::new(None); f.renderstatefulwidget(image, f.size(), &mut app.image); } ```

Example

See the [crate::picker::Picker] helper and examples/demo.

Current version: 0.2.0

Sixel compatibility and QA:

Terminal | Fixed | Resize | Notes -----------|-------|--------|------- Xterm | ✔️ | ✔️ | Foot | ✔️ | ✔️ | kitty | ✔️ | ✔️ | Alacritty | ✔️ | ❌ | with sixel patch, never clears graphics. iTerm2 | ❌ | ❌ | Unimplemented, has a protocolo similar to sixel konsole | ❌ | ❌ | Does not clear graphics unless cells have a background style Contour | ❌ | ❌ | Text over graphics Wezterm | ❌ | ❌ | Buggy ctx | ❌ | ❌ | Buggy Blackbox | ❔ | ❔ | Untested

Latest Xterm testing screenshot:
Testing screenshot

Halfblocks should work in all terminals.

Comparison:

License: MIT