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

pull/42/head
Vladimir Serov 2020-02-09 17:34:14 +03:00
parent 083d6304ba
commit f606807b08
No known key found for this signature in database
GPG Key ID: 6BA7C26C3FDF7BB3
1 changed files with 6 additions and 1 deletions

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()
)