Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ use tui::widgets::{Block, Widget};
pub enum ColorMode {
Luma,
Rgb,
Rgba,
}

const BLOCK_LIGHT: char = '\u{2591}';
const BLOCK_MEDIUM: char = '\u{2592}';
const BLOCK_DARK: char = '\u{2593}';
const BLOCK_FULL: char = '\u{2588}';
const EMPTY: char = ' ';

/// A tui-rs Widget which displays an image.
pub struct Image<'a> {
Expand Down Expand Up @@ -151,6 +153,17 @@ impl<'a> Image<'a> {
(255.0 * b) as u8,
));
}
ColorMode::Rgba => {
if a == 0. {
cell.set_char(EMPTY);
} else {
cell.set_char(BLOCK_FULL).set_fg(Color::Rgb(
(255.0 * r) as u8,
(255.0 * g) as u8,
(255.0 * b) as u8,
));
}
}
}
}
}
Expand Down