pub mod ansi;
pub mod ascii;
pub use ansi::{render_ansi, render_ansi_to};
pub use ascii::{render_ascii, render_ascii_to};
use crate::error::ImageError;
use crate::grid::Grid;
use std::fmt;
use std::io::Write;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum ColorDepth {
#[default]
TrueColor,
Ansi256,
Ansi16,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum RenderFormat {
#[default]
Ascii,
Ansi(ColorDepth),
}
pub fn render(grid: &Grid, format: RenderFormat) -> String {
match format {
RenderFormat::Ascii => ascii::render_ascii(grid),
RenderFormat::Ansi(depth) => ansi::render_ansi(grid, depth),
}
}
pub fn render_to<W: Write + ?Sized>(
grid: &Grid,
format: RenderFormat,
out: &mut W,
) -> Result<(), ImageError> {
match format {
RenderFormat::Ascii => ascii::render_ascii_to(grid, out),
RenderFormat::Ansi(depth) => ansi::render_ansi_to(grid, depth, out),
}
}
impl fmt::Display for Grid {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use fmt::Write as _;
for row in self.rows() {
for cell in row {
f.write_char(cell.ch)?;
}
f.write_char('\n')?;
}
Ok(())
}
}