1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
#![allow(unused_imports)]
#![warn(missing_docs)]
//! Parses a `Vec<u8>` as an byte sequence with ansi colors to
//! [`tui::text::Text`][Text].
//!
//! Invalid ansi colors / sequences will be ignored.
//!
//!
//! Supported features
//! - UTF-8 using `String::from_utf8` or [`simdutf8`][simdutf8].
//! - Most stuff like **Bold** / *Italic* / <u>Underline</u> / ~~Strikethrough~~.
//! - Supports 4-bit color palletes.
//! - Supports 8-bit color.
//! - Supports True color ( RGB / 24-bit color ).
//!
//!
//! ## Example
//! The argument to the function `ansi_to_text` implements `IntoIterator` so it will be consumed on
//! use.
//! ```rust
//! use ansi_to_tui_forked::IntoText;
//! let bytes = b"\x1b[38;2;225;192;203mAAAAA\x1b[0m".to_owned().to_vec();
//! let text = bytes.into_text().unwrap();
//! ```
//! Example parsing from a file.
//! ```rust
//! use ansi_to_tui_forked::IntoText;
//! let buffer = std::fs::read("ascii/text.ascii").unwrap();
//! let text = buffer.into_text().unwrap();
//! ```
//!
//! If you want to use [`simdutf8`][simdutf8] instead of `String::from_utf8()`
//! for parsing UTF-8 then enable optional feature `simd`
//!
//! [Text]: https://docs.rs/tui/0.15.0/tui/text/struct.Text.html
//! [ansi-to-tui]: https://github.com/uttarayan21/ansi-to-tui
//! [simdutf8]: https://github.com/rusticstuff/simdutf8
// mod ansi;
mod code;
mod error;
mod parser;
pub use error::Error;
use tui::text::Text;
/// IntoText will convert any type that has a AsRef<[u8]> to a Text.
pub trait IntoText {
/// Convert the type to a Text.
fn into_text(&self) -> Result<Text<'static>, Error>;
}
impl<T> IntoText for T
where
T: AsRef<[u8]>,
{
fn into_text(&self) -> Result<Text<'static>, Error> {
Ok(crate::parser::text(self.as_ref())?.1)
}
}