https://github.com/ratatui/ansi-to-tui
Convert ansi colored text to tui::text::Text
https://github.com/ratatui/ansi-to-tui
ansi ascii rust terminal tui-rs
Last synced: 6 months ago
JSON representation
Convert ansi colored text to tui::text::Text
- Host: GitHub
- URL: https://github.com/ratatui/ansi-to-tui
- Owner: ratatui
- License: mit
- Created: 2021-04-25T08:36:11.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2026-01-10T05:25:37.000Z (6 months ago)
- Last Synced: 2026-01-11T01:36:06.681Z (6 months ago)
- Topics: ansi, ascii, rust, terminal, tui-rs
- Language: Rust
- Homepage: https://crates.io/crates/ansi-to-tui
- Size: 203 KB
- Stars: 86
- Watchers: 6
- Forks: 29
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# ansi-to-tui
[![Crate Badge]][Crate] [![Repo Badge]][Repo] \
[![Docs Badge]][Docs] [![License Badge]][License] \
[![CI Badge]][CI] [![Codecov Badge]][Codecov]
Convert ANSI color and style codes into Ratatui [`Text`][Text].
This crate parses bytes containing ANSI SGR escape sequences (like `\x1b[31m`).
It produces a Ratatui [`Text`][Text] with equivalent foreground/background [`Color`][Color] and
[`Modifier`][Modifier] settings via [`Style`][Style].
Unknown or malformed escape sequences are ignored so you can feed it real terminal output without
having to pre-clean it.
| Color Mode | Supported | SGR Example | Ratatui `Color` Example |
| --------------------------- | :-------: | ------------------------ | ----------------------- |
| Named (3/4-bit, 8/16-color) | ✓ | `\x1b[30..37;40..47m` | `Color::Blue` |
| Indexed (8-bit, 256-color) | ✓ | `\x1b[38;5;m` | `Color::Indexed(1)` |
| Truecolor (24-bit RGB) | ✓ | `\x1b[38;2;;;m` | `Color::Rgb(255, 0, 0)` |
## Example
```rust
use ansi_to_tui::IntoText as _;
let buffer = std::fs::read("ascii/text.ascii")?;
let output = buffer.into_text()?;
```
Contributing and CI details are in [`CONTRIBUTING.md`][Contributing].
[Text]: https://docs.rs/ratatui-core/latest/ratatui_core/text/struct.Text.html
[Color]: https://docs.rs/ratatui-core/latest/ratatui_core/style/enum.Color.html
[Style]: https://docs.rs/ratatui-core/latest/ratatui_core/style/struct.Style.html
[Modifier]: https://docs.rs/ratatui-core/latest/ratatui_core/style/struct.Modifier.html
[Crate Badge]: https://img.shields.io/crates/v/ansi-to-tui?logo=rust
[Crate]: https://crates.io/crates/ansi-to-tui
[Repo Badge]: https://img.shields.io/badge/repo-ansi--to--tui-blue?logo=github
[Repo]: https://github.com/ratatui/ansi-to-tui
[Docs Badge]: https://img.shields.io/badge/docs-ansi--to--tui-blue?logo=rust
[Docs]: https://docs.rs/ansi-to-tui
[Contributing]: CONTRIBUTING.md
[License Badge]: https://img.shields.io/crates/l/ansi-to-tui
[License]: LICENSE
[CI Badge]: https://github.com/ratatui/ansi-to-tui/actions/workflows/build.yml/badge.svg
[CI]: https://github.com/ratatui/ansi-to-tui/actions/workflows/build.yml
[Codecov Badge]: https://codecov.io/gh/ratatui/ansi-to-tui/branch/main/graph/badge.svg
[Codecov]: https://codecov.io/gh/ratatui/ansi-to-tui