utf-8: moved codepage into a constant, and encoder into pixel impl

This commit is contained in:
Vladimir Serov 2020-02-09 17:34:14 +03:00
parent 4f2422ede6
commit 9eed3f6305

View file

@ -2,6 +2,7 @@
use crate::render::{Canvas as RenderCanvas, Pixel, Color};
const CODEPAGE: [&str; 4] = [" ","\u{2584}","\u{2580}","\u{2588}"];
#[derive(Copy, Clone, PartialEq)]
pub enum Unicode1x2 {
@ -22,6 +23,10 @@ impl Unicode1x2 {
Unicode1x2::Light => {0}
}
}
#[doc(hidden)]
fn parse_2_bits(sym: &u8) -> &'static str {
CODEPAGE[*sym as usize]
}
}
pub struct Canvas {
@ -66,7 +71,7 @@ impl RenderCanvas for Canvas {
}
}.iter()
// Mapping those 2-bit numbers to corresponding pixels.
.map(|sym| [" ","\u{2584}","\u{2580}","\u{2588}"][*sym as usize])
.map(Unicode1x2::parse_2_bits)
.collect::<Vec<&str>>()
.concat()
)