Function ansi_to_tui::ansi_to_text[][src]

pub fn ansi_to_text<'t, B: IntoIterator<Item = u8>>(
    bytes: B
) -> Result<Text<'t>, Error>

This functions converts the ascii byte sequence with ansi colors to tui::text::Text type
This functions’s argument implements into_iter so the buffer will be consumed on use.

Example

use ansi_to_tui::ansi_to_text;
let bytes : Vec<u8> = vec![b'\x1b', b'[', b'3', b'1', b'm', b'A', b'A', b'A', b'\x1b', b'[', b'0'];
let text = ansi_to_text(bytes);

Example parsing from a file.

use ansi_to_tui::ansi_to_text;
use std::io::Read;

let mut file = std::fs::File::open("ascii/text.ascii").unwrap();
let mut buffer: Vec<u8> = Vec::new();
file.read_to_end(&mut buffer);
let text = ansi_to_text(buffer);